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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);