Video Zoom Controls with Upscaling and Pan

Allows zooming in and out on any video playing within the browser with keys z (zoom in) and x (zoom out), with upscaling for better picture quality, and panning with Shift + A, W, S, D. Press Shift + R to reset zoom and pan.

  1. // ==UserScript==
  2. // @name Video Zoom Controls with Upscaling and Pan
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Allows zooming in and out on any video playing within the browser with keys z (zoom in) and x (zoom out), with upscaling for better picture quality, and panning with Shift + A, W, S, D. Press Shift + R to reset zoom and pan.
  6. // @author Your Name
  7. // @match *://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to zoom the video
  16. function zoomVideo(video, scaleFactor) {
  17. const currentScale = parseFloat(video.dataset.scale) || 1;
  18. const newScale = currentScale * scaleFactor;
  19. video.style.transform = `scale(${newScale}) translate(${video.dataset.panX}px, ${video.dataset.panY}px)`;
  20. video.dataset.scale = newScale;
  21. }
  22.  
  23. // Function to pan the video
  24. function panVideo(video, deltaX, deltaY) {
  25. const panX = parseFloat(video.dataset.panX) || 0;
  26. const panY = parseFloat(video.dataset.panY) || 0;
  27. video.dataset.panX = panX + deltaX;
  28. video.dataset.panY = panY + deltaY;
  29. zoomVideo(video, 1); // Reset zoom to apply pan
  30. }
  31.  
  32. // Function to reset zoom and pan
  33. function resetZoomAndPan(video) {
  34. video.dataset.scale = 1;
  35. video.dataset.panX = 0;
  36. video.dataset.panY = 0;
  37. zoomVideo(video, 1); // Reset zoom and pan
  38. }
  39.  
  40. // Apply image-rendering property for better quality
  41. const style = document.createElement('style');
  42. style.innerHTML = `
  43. video {
  44. image-rendering: optimizeQuality; /* You can change this to 'crisp-edges' or other values for different interpolation */
  45. }
  46. `;
  47. document.head.appendChild(style, {nonce: 'Trusted Type Policy'});
  48.  
  49. // Event listener for keypress
  50. document.addEventListener('keypress', function(event) {
  51. if (event.shiftKey && event.key === 'Z') {
  52. // Zoom in when Shift + Z keys are pressed
  53. const videos = document.querySelectorAll('video');
  54. videos.forEach(video => zoomVideo(video, 1.02)); // You can adjust the zoom factor here
  55. } else if (event.shiftKey && event.key === 'X') {
  56. // Zoom out when Shift + X keys are pressed
  57. const videos = document.querySelectorAll('video');
  58. videos.forEach(video => zoomVideo(video, 0.98)); // You can adjust the zoom factor here
  59. }
  60. });
  61.  
  62. // Event listener for Shift + A, W, S, D keys for panning
  63. document.addEventListener('keydown', function(event) {
  64. const deltaX = event.key === 'A' ? -10 : event.key === 'D' ? 10 : 0;
  65. const deltaY = event.key === 'W' ? -10 : event.key === 'S' ? 10 : 0;
  66.  
  67. if (deltaX !== 0 || deltaY !== 0) {
  68. // Pan when Shift + A, W, S, or D keys are pressed
  69. const videos = document.querySelectorAll('video');
  70. videos.forEach(video => panVideo(video, deltaX, deltaY)); // You can adjust the pan speed here
  71. } else if (event.shiftKey && event.key === 'R') {
  72. // Reset zoom and pan when Shift + R keys are pressed
  73. const videos = document.querySelectorAll('video');
  74. videos.forEach(video => resetZoomAndPan(video));
  75. }
  76. });
  77.  
  78. // Store original zoom level when video is first loaded
  79. document.addEventListener('DOMContentLoaded', function() {
  80. const videos = document.querySelectorAll('video');
  81. videos.forEach(video => {
  82. video.dataset.scale = 1;
  83. video.dataset.panX = 0;
  84. video.dataset.panY = 0;
  85. });
  86. });
  87. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址