Video zooming buttons

Allows you to zoom in on YouTube videos. Useful to get rid of black borders at the top/bottom of a video if you have an ultrawide display.

当前为 2020-02-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Video zooming buttons
  3. // @description Allows you to zoom in on YouTube videos. Useful to get rid of black borders at the top/bottom of a video if you have an ultrawide display.
  4. // @version 1
  5. // @grant none
  6. // @match https://www.youtube.com/*
  7. // @namespace https://greasyfork.org/users/442760
  8. // ==/UserScript==
  9.  
  10. function prepareButton(b)
  11. {
  12. b.style.float = "right";
  13. }
  14.  
  15. function getVideo()
  16. {
  17. return document.querySelector(".html5-main-video");
  18. }
  19.  
  20. console.log("Start waiting");
  21.  
  22. var waitInterval = setInterval(function() {
  23. var elemTitle = document.querySelector("yt-formatted-string.ytd-video-primary-info-renderer:nth-child(1)");
  24.  
  25. if (!elemTitle || !getVideo()) {
  26. return;
  27. }
  28.  
  29. clearInterval(waitInterval);
  30. console.log("Clear interval");
  31. var zoomSpeed = 0.0;
  32. var zoom = 1.0;
  33.  
  34. setInterval(function() {
  35. var video = getVideo();
  36. if (video) {
  37. zoom += zoomSpeed;
  38. video.style.transform = "scale(" + zoom + ")";
  39. }
  40. }, 17);
  41.  
  42. var newButtonIncrease = document.createElement("button");
  43. newButtonIncrease.innerText = "+";
  44. prepareButton(newButtonIncrease);
  45.  
  46. var newButtonDecrease = document.createElement("button");
  47. newButtonDecrease.innerText = "-";
  48. prepareButton(newButtonDecrease);
  49.  
  50. var newButtonReset = document.createElement("button");
  51. newButtonReset.innerText = "Reset";
  52. prepareButton(newButtonReset);
  53.  
  54. newButtonIncrease.onmousedown = function() { zoomSpeed = 0.01; };
  55. newButtonIncrease.onmouseup = function() { zoomSpeed = 0; };
  56.  
  57. newButtonDecrease.onmousedown = function() { zoomSpeed = -0.01; };
  58. newButtonDecrease.onmouseup = function() { zoomSpeed = 0; };
  59.  
  60. newButtonReset.onclick = function() { zoom = 1.0; }
  61.  
  62. elemTitle.appendChild(newButtonIncrease);
  63. elemTitle.appendChild(newButtonDecrease);
  64. elemTitle.appendChild(newButtonReset);
  65. console.log(elemTitle);
  66. console.log("Everything done");
  67. }, 500);