// ==UserScript== // @name YouTube Rotate 90° // @namespace http://tampermonkey.net/ // @version 1.5 // @description 把Youtube影片旋轉0°、90°、180°、270°,讓你輕鬆觀看影片! // @author zaqwsx2205 // @match https://*.youtube.com/* // @match https://*.youtube.com/watch?v=* // @match https://www.youtube.com/embed/* // @match https://www.youtube-nocookie.com/embed/* // @require https://code.jquery.com/jquery-3.4.1.min.js // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; var width; var height; var heightTest; var bool = false; var click = 0; var safeTest = location.href; function transform90(){ setTimeout(function(){ width = $(".html5-video-container").outerWidth(); height = $(".html5-video-container").outerHeight(); heightTest = width - height; $(".video-test1").html(''); }, 20); } function transform(x){ $(".video-test, .video-test1").remove(); switch(x){ case 1: $(".html5-video-container").append('
'); $(".html5-video-container").append('
'); $(".video-test").html(''); transform90(); break; case 2: $(".html5-video-container").append('
'); $(".html5-video-container").append('
'); $(".video-test").html(''); break; case 3: $(".html5-video-container").append('
'); $(".html5-video-container").append('
'); $(".video-test").html(''); transform90(); break; case 4: click = 0; break; } } function build(){ $(".video-test, .video-test1, .video-test2, .transform90").remove(); if($(".ytp-embed").length > 0){ $(".html5-video-container").append('
'); $(".video-test2").html(''); $('.ytp-chrome-top-buttons').prepend(''); }else if($(".ytd-miniplayer #player-container #ytd-player").length > 0){ $(".ytp-miniplayer-scrim").prepend(''); }else{ $(".ytp-right-controls").prepend(''); } $('.transform90').on("click", function() { click++; transform(click); }); } function observeTEST() { var composeBox = $('#player-container video')[0]; var composeObserver = new MutationObserver(function(e) { if(safeTest != location.href){ safeTest = location.href; click = 0; build(); } }); if(!composeBox) { window.setTimeout(observeTEST,500); return; } var config = {characterData: true, childList: true, attributes: true}; composeObserver.observe(composeBox,config); } $(document).ready(function(){ build(); observeTEST(); $(window).resize( function () { transform(click); }); document.addEventListener("fullscreenchange", function( event ) { transform(click); }); $(".ytp-size-button").click(function(){ transform(click); }); }); })();