Resize Video To Window Size

Resize the video player for various sites to the window size.

当前为 2017-05-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Resize Video To Window Size
  3. // @description Resize the video player for various sites to the window size.
  4. // @author Chris H (Zren / Shade)
  5. // @namespace http://xshade.ca
  6. // @version 18
  7. // @include http://www.crunchyroll.com/*
  8. // @include https://docs.google.com/file/*
  9. // @include https://drive.google.com/drive/*
  10. // @include https://drive.google.com/file/*
  11. // @include https://vimeo.com/*
  12. // @include http://onepieceofficial.com/videos.aspx*
  13. // @include http://www.onepieceofficial.com/videos.aspx*
  14. // @include http://eachvideo.com/watch*
  15. // @include http://olympics.cbc.ca/video/live/*
  16. // @include http://olympics.cbc.ca/video/vod/*
  17. // @include http://www.dailymotion.com/video/*
  18. // @grant GM_addStyle
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. var fixedOverlayPlayer = function(selector) {
  23. var css = selector + "{";
  24. css += "position: fixed;";
  25. css += "top: 0;";
  26. css += "left: 0;";
  27. css += "right: 0;";
  28. css += "bottom: 0;";
  29. css += "}";
  30. GM_addStyle(css);
  31. };
  32. var absoluteTopPlayer = function(selector, staticSelectors) {
  33. var css = selector + "{";
  34. css += "position: absolute;";
  35. css += "top: 0;";
  36. css += "left: 0;";
  37. css += "width: 100vw;";
  38. css += "height: 100vh;";
  39. css += "padding: 0;";
  40. css += "margin: 0;";
  41. css += "}";
  42. css += "body {";
  43. css += "margin-top: 100vh;";
  44. css += "margin-top: 100vh;";
  45. css += "padding-top: 0;";
  46. css += "}";
  47. if (staticSelectors) {
  48. css += staticSelectors + "{";
  49. css += "position: static";
  50. css += "}";
  51. }
  52. GM_addStyle(css);
  53. };
  54. var movedTopPlayer = function(videoBoxElement) {
  55. document.body.insertBefore(videoBoxElement, document.body.firstChild);
  56. videoBoxElement.style.width = '100%';
  57. videoBoxElement.style.height = '100%';
  58. videoBoxElement.style.backgroundColor = '#000';
  59. };
  60.  
  61. var urlMatch = function(regexStr) {
  62. regexStr = regexStr.replace(/\//g, '\\/'); // Auto escape forward slashes to make url regexes more legible.
  63. var regex = new RegExp(regexStr);
  64. return regex.exec(window.location.href);
  65. };
  66.  
  67. if (window.location.href.match(/^http:\/\/www\.crunchyroll\.(com|ca)\/.+\/.+-\d+\/?/)) {
  68. var videoBoxElement = document.getElementById('showmedia_video_box') || document.getElementById('showmedia_video_box_wide');
  69. if (!videoBoxElement) return;
  70. movedTopPlayer(videoBoxElement);
  71. var css = 'html, body { width: 100%; height: 100%; }';
  72. css += '#showmedia_video_box, #showmedia_video_box_wide, #showmedia_video_player { width: 100%; height: calc(100vh + 32px) !important; }';
  73. GM_addStyle(css);
  74. } else if (document.location.href.startsWith('https://docs.google.com/file/')) {
  75. fixedOverlayPlayer('#drive-viewer-video-player-object-0');
  76. var css = 'body:not(:hover) .ytp-chrome-bottom { opacity: 0 !important; }';
  77. css += 'body:not(:hover) .drive-viewer-toolstrip { opacity: 0 !important; }';
  78. GM_addStyle(css);
  79. } else if (document.location.href.startsWith('https://drive.google.com/')) {
  80. fixedOverlayPlayer('.drive-viewer-video-player');
  81. var css = '.drive-viewer-toolstrip { opacity: 0 !important; }';
  82. css += '.drive-viewer-toolstrip:hover { opacity: 1 !important; }';
  83. GM_addStyle(css);
  84. } else if (document.location.href.startsWith('https://vimeo.com/')) {
  85. debugger;
  86. if (! /\/\d+/.exec(document.location.pathname))
  87. return;
  88. var css = '.player_area-wrapper, .player_area, .player_container, .player, .video-wrapper, .video, .video * { width: 100vw !important; height: 100vh !important; max-height: 100vh !important; }';
  89. css += '.clip_main > *:not(.player_area-wrapper) { margin-top: 70px; }';
  90. css += '.VimeoBrand_ColorRibbon, .body_ribbon, .topnav_desktop, .topnav_mobile { position: absolute; top: 100vh; width: 100%; }';
  91. css += '.topnav_desktop { top: calc(100vh + 5px); }';
  92. GM_addStyle(css);
  93.  
  94. // autoplay
  95. function tick() {
  96. var e = document.querySelector('button.play[aria-label="Play"]');
  97. if (e) {
  98. e.click();
  99. } else {
  100. setTimeout(tick, 100);
  101. }
  102. }
  103. setTimeout(tick, 100);
  104. } else if (document.location.host.endsWith('onepieceofficial.com')) {
  105. movedTopPlayer(document.querySelector('#FUNimationVideo'));
  106. } else if (document.location.host.endsWith('eachvideo.com')) {
  107. absoluteTopPlayer('.videoWrapper', '.navbar.navbar-default.navbar-fixed-top.bs-docs-nav, .col-md-8.row-border');
  108. } else if (document.location.host == 'olympics.cbc.ca') {
  109. if (document.querySelector('figure.cbc-video--thumb-wrapper.cbc-big[style="display: none;"]')) {
  110. // Sports video
  111. movedTopPlayer(document.querySelector('.cbc-video--player-wrapper'));
  112. var css = 'body.asdf-16x9 .cbc-video--player-wrapper { width: 100vw !important; height: calc(27px + 100vh + 59px) !important; position: absolute; top: -27px; }';
  113. css += 'body.asdf-16x9 .cbc-video--player-wrapper.cbc-live-or-full-evt:hover { top: calc(-27px - 59px); }';
  114. css += 'body.asdf-16x9 { margin-top: 100vh; }';
  115. //css += 'body.asdf-fill-height .cbc-video--player-wrapper { width: calc((100vh - 60px - 59px) * 1.777777777) !important; height: 100vh !important; margin: 0 auto; }';
  116. //css += 'body.asdf-fill-width .cbc-video--player-wrapper { width: 100vw !important; height: calc(60px + 56.25vw + 59px) !important; }';
  117. GM_addStyle(css);
  118. function onResize() {
  119. var height = 59 + window.innerWidth * 0.5625 + window.innerHeight * 0.06;
  120. var ratio = window.innerWidth / window.innerHeight;
  121. console.log('onResize', height, ratio)
  122. if (1.7 <= ratio && ratio <= 1.8 ) { // 16:9 = 1.7777777...
  123. document.body.classList.remove('asdf-fill-width');
  124. document.body.classList.remove('asdf-fill-height');
  125. document.body.classList.add('asdf-16x9');
  126. } else if (height > window.innerHeight) {
  127. document.body.classList.remove('asdf-fill-width');
  128. document.body.classList.remove('asdf-16x9');
  129. document.body.classList.add('asdf-fill-height');
  130. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  131. videoBoxElement.style.width = "calc((100vh - 27px - 59px) * 1.777777777)";
  132. videoBoxElement.style.height = "100vh";
  133. videoBoxElement.style.margin = '0 auto';
  134. } else {
  135. document.body.classList.remove('asdf-fill-height');
  136. document.body.classList.remove('asdf-16x9');
  137. document.body.classList.add('asdf-fill-width');
  138. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  139. videoBoxElement.style.width = "100vw";
  140. videoBoxElement.style.height = "calc(27px + 56.25vw + 59px)";
  141. }
  142. }
  143. window.addEventListener('resize', onResize);
  144. window.addEventListener('click', function(){
  145. setTimeout(onResize, 1000);
  146. });
  147. onResize();
  148. } else {
  149. // Regular video
  150. movedTopPlayer(document.querySelector('.cbc-video'));
  151. var css = 'figure.cbc-video--thumb-wrapper.cbc-big { height: 100%; margin: 0; }';
  152. css += 'figure.cbc-video--thumb-wrapper.cbc-big picture { width: 100%; }';
  153. css += 'figure.cbc-video--thumb-wrapper.cbc-big picture img { width: 100%; }';
  154. GM_addStyle(css);
  155. function onResize() {
  156. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  157. var height = 26 + window.innerWidth * 0.5625;
  158. if (height > window.innerHeight) {
  159. videoBoxElement.style.width = "calc((100vh - 26px) * 1.77777777)";
  160. videoBoxElement.style.height = "100vh";
  161. videoBoxElement.style.margin = '0 auto';
  162. } else {
  163. videoBoxElement.style.width = "100vw";
  164. videoBoxElement.style.height = "calc(26px + 56.25vw)";
  165. }
  166. }
  167. window.addEventListener('resize', onResize);
  168. onResize();
  169. }
  170. } else if (document.location.host.endsWith('www.dailymotion.com')) {
  171. movedTopPlayer(document.querySelector('#player'));
  172. var css = '#player { height: 100vh!important; width: 100vw!important; }';
  173. css += '#player:not(:hover) .dmp_will-transition.dmp_is-transitioned--fadeinslide { opacity: 0; }';
  174. GM_addStyle(css);
  175. }
  176. GM_addStyle('html::-webkit-scrollbar { width: 0; height: 0; } body::-webkit-scrollbar { width: 0; height: 0; }');
  177. })();