Resize Video To Window Size

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

目前为 2017-08-09 提交的版本,查看 最新版本

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