Greasy Fork 还支持 简体中文。

Resize Video To Window Size

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

目前為 2017-09-08 提交的版本,檢視 最新版本

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