Resize Video To Window Size

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

目前为 2017-10-27 提交的版本。查看 最新版本

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