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 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name     Video zooming buttons
// @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.
// @version  1
// @grant    none
// @match    https://www.youtube.com/*
// @namespace https://greasyfork.org/users/442760
// ==/UserScript==

function prepareButton(b)
{
  b.style.float = "right";
}

function getVideo()
{
  return document.querySelector(".html5-main-video");
}

console.log("Start waiting");

var waitInterval = setInterval(function() {
  var elemTitle = document.querySelector("yt-formatted-string.ytd-video-primary-info-renderer:nth-child(1)");

  if (!elemTitle || !getVideo()) {
    return;
  }

  clearInterval(waitInterval);
  console.log("Clear interval");
  
  var zoomSpeed = 0.0;
  var zoom = 1.0;

  setInterval(function() {
    var video = getVideo();
    if (video) {
    	zoom += zoomSpeed;
    	video.style.transform = "scale(" + zoom + ")";
    }
  }, 17);

  var newButtonIncrease = document.createElement("button");
  newButtonIncrease.innerText = "+";
  prepareButton(newButtonIncrease);

  var newButtonDecrease = document.createElement("button");
  newButtonDecrease.innerText = "-";
  prepareButton(newButtonDecrease);

  var newButtonReset = document.createElement("button");
  newButtonReset.innerText = "Reset";
  prepareButton(newButtonReset);

  newButtonIncrease.onmousedown = function() { zoomSpeed = 0.01; };
  newButtonIncrease.onmouseup = function() { zoomSpeed = 0; };

  newButtonDecrease.onmousedown = function() { zoomSpeed = -0.01; };
  newButtonDecrease.onmouseup = function() { zoomSpeed = 0; };

  newButtonReset.onclick = function() { zoom = 1.0; }

  elemTitle.appendChild(newButtonIncrease);
  elemTitle.appendChild(newButtonDecrease);
  elemTitle.appendChild(newButtonReset);
  
  console.log(elemTitle);
  console.log("Everything done");
}, 500);