YouTube Rotate 90°

把Youtube影片旋轉0°、90°、180°、270°,讓你輕鬆觀看影片!

目前為 2020-09-27 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name YouTube Rotate 90°
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.6
  5. // @description 把Youtube影片旋轉0°、90°、180°、270°,讓你輕鬆觀看影片!
  6. // @author zaqwsx2205
  7. // @match https://*.youtube.com/*
  8. // @match https://*.youtube.com/watch?v=*
  9. // @match https://www.youtube.com/embed/*
  10. // @match https://www.youtube-nocookie.com/embed/*
  11. // @require https://code.jquery.com/jquery-3.4.1.min.js
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. var width;
  19. var height;
  20. var heightTest;
  21. var bool = false;
  22. var click = 0;
  23. var safeTest = location.href;
  24.  
  25. function transform90(){
  26. setTimeout(function(){
  27. width = $(".html5-video-container").outerWidth();
  28. height = $(".html5-video-container").outerHeight();
  29. heightTest = width - height;
  30. $(".video-test1").html('<style>.video-stream{width:calc(100% - '+heightTest+'px)!important;}</style>');
  31. }, 20);
  32. }
  33.  
  34. function transform(x){
  35. $(".video-test, .video-test1").remove();
  36. switch(x){
  37. case 1:
  38. $(".html5-video-container").append('<div class="video-test"></div>');
  39. $(".html5-video-container").append('<div class="video-test1"></div>');
  40. $(".video-test").html('<style>.html5-video-container {display: flex !important; justify-content: center !important; align-items: center !important; height: 100% !important;}.video-stream{position:relative !important; transform:rotate(90deg) !important; height:auto !important; left:0 !important; top:0 !important;}</style>');
  41. transform90();
  42. break;
  43. case 2:
  44. $(".html5-video-container").append('<div class="video-test"></div>');
  45. $(".html5-video-container").append('<div class="video-test1"></div>');
  46. $(".video-test").html('<style>.html5-video-container {display: flex !important; justify-content: center !important; align-items: center !important; height: 100% !important;}.video-stream{position:relative !important; transform:rotate(180deg) !important; height:auto !important; left:0 !important; top:0 !important;}</style>');
  47. break;
  48. case 3:
  49. $(".html5-video-container").append('<div class="video-test"></div>');
  50. $(".html5-video-container").append('<div class="video-test1"></div>');
  51. $(".video-test").html('<style>.html5-video-container {display: flex !important; justify-content: center !important; align-items: center !important; height: 100% !important;} .video-stream{position:relative !important; transform:rotate(270deg) !important; height:auto !important; left:0 !important; top:0 !important;}</style>');
  52. transform90();
  53. break;
  54. case 4:
  55. click = 0;
  56. break;
  57. }
  58. }
  59.  
  60. function build(){
  61. $(".video-test, .video-test1, .video-test2, .transform90").remove();
  62.  
  63. if($(".ytp-embed").length > 0){
  64. $(".html5-video-container").append('<div class="video-test2"></div>');
  65. $(".video-test2").html('<style>.ytp-autohide .transform90-top{opacity: 0 !important; -moz-transition: opacity .1s cubic-bezier(0.4,0.0,1,1) !important; -webkit-transition: opacity .1s cubic-bezier(0.4,0.0,1,1) !important; transition: opacity .1s cubic-bezier(0.4,0.0,1,1) !important;} .ytp-transform90-icon {margin: auto !important; width: 36px !important; height: 36px !important; position: relative !important;}.ytp-big-mode .ytp-transform90-icon {width: 54px !important; height: 54px !important;} .ytp-transform90-title{font-weight: 500 !important; text-align: center !important; font-size: 14px !important;} .ytp-big-mode .ytp-transform90-title{font-size: 20px !important;}</style>');
  66. $('.ytp-chrome-top-buttons').prepend('<button class="ytp-button transform90 transform90-top" data-tooltip-opaque="true" aria-label="" style="width: auto;height: auto;"><div class="ytp-transform90-icon" style="transform:scaleX(-1);"><svg version="1.1" x="0px" y="0px" viewBox="0 0 453.227 453.227" style="enable-background:new 0 0 453.227 453.227;" xml:space="preserve" width="50%" height="100%" class=""><g><g><g><g><path d="M139.453,120.747L1.107,259.093L139.453,397.44L277.8,259.093L139.453,120.747z M61.373,259.093l77.973-77.973 l78.08,77.973l-77.973,77.973L61.373,259.093z" data-original="#000000" class="active-path" data-old_color="#000000" fill="#FFFFFF"/><path d="M395.88,125.44C358.333,88,309.267,69.227,260.093,69.227V0l-90.56,90.56l90.56,90.453v-69.12 c38.187,0,76.48,14.613,105.6,43.733c58.347,58.347,58.347,152.853,0,211.2c-29.12,29.12-67.413,43.733-105.6,43.733 c-20.693,0-41.28-4.373-60.48-12.907l-31.787,31.787c28.587,15.787,60.373,23.787,92.267,23.787 c49.173,0,98.24-18.773,135.787-56.213C470.867,322.027,470.867,200.427,395.88,125.44z" data-original="#000000" class="active-path" data-old_color="#000000" fill="#FFFFFF"/></g></g></g></g> </svg></div><div class="ytp-transform90-title">Video Rotate 90°</div></button>');
  67. }else if($(".ytd-miniplayer #player-container #ytd-player").length > 0){
  68. $(".ytp-miniplayer-scrim").prepend('<button class="transform90 ytp-play-button ytp-button" title="Video Rotate 90°" aria-label="Video Rotate 90°" style="display: inline-flex;justify-content: center; transform:scaleX(-1);"><svg version="1.1" x="0px" y="0px" viewBox="0 0 453.227 453.227" style="enable-background:new 0 0 453.227 453.227;" xml:space="preserve" width="50%" height="100%" class=""><g><g><g><g><path d="M139.453,120.747L1.107,259.093L139.453,397.44L277.8,259.093L139.453,120.747z M61.373,259.093l77.973-77.973 l78.08,77.973l-77.973,77.973L61.373,259.093z" data-original="#000000" class="active-path" data-old_color="#000000" fill="#FFFFFF"/><path d="M395.88,125.44C358.333,88,309.267,69.227,260.093,69.227V0l-90.56,90.56l90.56,90.453v-69.12 c38.187,0,76.48,14.613,105.6,43.733c58.347,58.347,58.347,152.853,0,211.2c-29.12,29.12-67.413,43.733-105.6,43.733 c-20.693,0-41.28-4.373-60.48-12.907l-31.787,31.787c28.587,15.787,60.373,23.787,92.267,23.787 c49.173,0,98.24-18.773,135.787-56.213C470.867,322.027,470.867,200.427,395.88,125.44z" data-original="#000000" class="active-path" data-old_color="#000000" fill="#FFFFFF"/></g></g></g></g> </svg></button>');
  69. }else{
  70. $(".ytp-right-controls").prepend('<button class="transform90 ytp-button" title="Video Rotate 90°" aria-label="Video Rotate 90°" style="display: inline-flex;justify-content: center; transform:scaleX(-1);"><svg version="1.1" x="0px" y="0px" viewBox="0 0 453.227 453.227" style="enable-background:new 0 0 453.227 453.227;" xml:space="preserve" width="50%" height="100%" class=""><g><g><g><g><path d="M139.453,120.747L1.107,259.093L139.453,397.44L277.8,259.093L139.453,120.747z M61.373,259.093l77.973-77.973 l78.08,77.973l-77.973,77.973L61.373,259.093z" data-original="#000000" class="active-path" data-old_color="#000000" fill="#FFFFFF"/><path d="M395.88,125.44C358.333,88,309.267,69.227,260.093,69.227V0l-90.56,90.56l90.56,90.453v-69.12 c38.187,0,76.48,14.613,105.6,43.733c58.347,58.347,58.347,152.853,0,211.2c-29.12,29.12-67.413,43.733-105.6,43.733 c-20.693,0-41.28-4.373-60.48-12.907l-31.787,31.787c28.587,15.787,60.373,23.787,92.267,23.787 c49.173,0,98.24-18.773,135.787-56.213C470.867,322.027,470.867,200.427,395.88,125.44z" data-original="#000000" class="active-path" data-old_color="#000000" fill="#FFFFFF"/></g></g></g></g> </svg></button>');
  71. }
  72.  
  73. $('.transform90').on("click", function() {
  74. click++;
  75. transform(click);
  76. });
  77. }
  78.  
  79. function observeTEST() {
  80. var composeBox = $('#player-container video')[0];
  81. var composeObserver = new MutationObserver(function(e) {
  82. if(safeTest != location.href){
  83. safeTest = location.href;
  84. click = 0;
  85. build();
  86. }
  87. });
  88. if(!composeBox) {
  89. window.setTimeout(observeTEST,500);
  90. return;
  91. }
  92. var config = {characterData: true, childList: true, attributes: true};
  93. composeObserver.observe(composeBox,config);
  94. }
  95.  
  96. $(document).ready(function(){
  97. build();
  98. observeTEST();
  99.  
  100. $(window).resize( function () {
  101. transform(click);
  102. });
  103.  
  104. document.addEventListener("fullscreenchange", function( event ) {
  105. transform(click);
  106. });
  107.  
  108. $(".ytp-size-button").click(function(){
  109. transform(click);
  110. });
  111.  
  112. });
  113.  
  114. })();