Resize Video To Window Size

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

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

  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 34
  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. // @include http://*.ctvnews.ca/*
  23. // @include https://watch.cbc.ca/live/channel/*
  24. // @grant GM_addStyle
  25. // ==/UserScript==
  26.  
  27. (function() {
  28. var fixedOverlayPlayer = function(selector) {
  29. var css = selector + "{";
  30. css += "position: fixed;";
  31. css += "top: 0;";
  32. css += "left: 0;";
  33. css += "right: 0;";
  34. css += "bottom: 0;";
  35. css += "}";
  36. GM_addStyle(css);
  37. };
  38. var absoluteTopPlayer = function(selector, staticSelectors) {
  39. var css = selector + "{";
  40. css += "position: absolute;";
  41. css += "top: 0;";
  42. css += "left: 0;";
  43. css += "width: 100vw;";
  44. css += "height: 100vh;";
  45. css += "padding: 0;";
  46. css += "margin: 0;";
  47. css += "}";
  48. css += "body {";
  49. css += "margin-top: 100vh;";
  50. css += "margin-top: 100vh;";
  51. css += "padding-top: 0;";
  52. css += "}";
  53. if (staticSelectors) {
  54. css += staticSelectors + "{";
  55. css += "position: static";
  56. css += "}";
  57. }
  58. GM_addStyle(css);
  59. };
  60. var movedTopPlayer = function(videoBoxElement) {
  61. document.body.insertBefore(videoBoxElement, document.body.firstChild);
  62. videoBoxElement.style.width = '100%';
  63. videoBoxElement.style.height = '100%';
  64. videoBoxElement.style.backgroundColor = '#000';
  65. };
  66.  
  67. var urlMatch = function(regexStr) {
  68. regexStr = regexStr.replace(/\//g, '\\/'); // Auto escape forward slashes to make url regexes more legible.
  69. var regex = new RegExp(regexStr);
  70. return regex.exec(window.location.href);
  71. };
  72.  
  73. if (document.location.host.endsWith('crunchyroll.com')) {
  74. if (!window.location.href.match(/^http:\/\/www\.crunchyroll\.(com|ca)\/.+\/.+-\d+\/?/)) return;
  75. var videoBoxElement = document.getElementById('showmedia_video_box') || document.getElementById('showmedia_video_box_wide');
  76. if (!videoBoxElement) return;
  77. movedTopPlayer(videoBoxElement);
  78. videoBoxElement.addEventListener('keydown', function(e) {
  79. if (e.key == 'PageDown') {
  80. window.scrollBy(0, window.innerHeight * 0.9);
  81. } else if (e.key == 'PageUp') {
  82. window.scrollBy(0, -window.innerHeight * 0.9);
  83. } else if (e.key == 'ArrowDown') {
  84. window.scrollBy(0, 40);
  85. } else if (e.key == 'ArrowUp') {
  86. window.scrollBy(0, -40);
  87. }
  88. }, true);
  89. var css = 'html, body { width: 100%; height: 100%; }';
  90. css += '#showmedia_video_box, #showmedia_video_box_wide, #showmedia_video_player { width: 100%; height: calc(100vh + 32px) !important; }';
  91. GM_addStyle(css);
  92. } else if (document.location.href.startsWith('https://docs.google.com/file/')) {
  93. fixedOverlayPlayer('#drive-viewer-video-player-object-0');
  94. var css = 'body:not(:hover) .ytp-chrome-bottom { opacity: 0 !important; }';
  95. css += 'body:not(:hover) .drive-viewer-toolstrip { opacity: 0 !important; }';
  96. GM_addStyle(css);
  97. } else if (document.location.href.startsWith('https://drive.google.com/')) {
  98. fixedOverlayPlayer('.drive-viewer-video-player');
  99. var css = '.drive-viewer-toolstrip { opacity: 0 !important; }';
  100. css += '.drive-viewer-toolstrip:hover { opacity: 1 !important; }';
  101. GM_addStyle(css);
  102. } else if (document.location.href.startsWith('https://vimeo.com/')) {
  103. if (! /\/\d+/.exec(document.location.pathname))
  104. return;
  105. 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; }';
  106. css += '.vp-player-layout { left: 0 !important; top: 0 !important; width: 100vw !important; height: 100vh !important; }';
  107. css += '.clip_main > *:not(.player_area-wrapper) { margin-top: 70px; }';
  108. css += '.VimeoBrand_ColorRibbon, .body_ribbon, .topnav_desktop, .topnav_mobile { position: absolute; top: 100vh; width: 100%; }';
  109. css += '.topnav_desktop { top: calc(100vh + 5px); }';
  110. GM_addStyle(css);
  111.  
  112. // autoplay
  113. function tick() {
  114. var e = document.querySelector('button.play[aria-label="Play"]');
  115. if (e) {
  116. e.click();
  117. } else {
  118. setTimeout(tick, 100);
  119. }
  120. }
  121. setTimeout(tick, 100);
  122. } else if (document.location.host.endsWith('onepieceofficial.com')) {
  123. movedTopPlayer(document.querySelector('#FUNimationVideo'));
  124. } else if (document.location.host.endsWith('eachvideo.com')) {
  125. absoluteTopPlayer('.videoWrapper', '.navbar.navbar-default.navbar-fixed-top.bs-docs-nav, .col-md-8.row-border');
  126. } else if (document.location.host == 'olympics.cbc.ca') {
  127. if (document.querySelector('figure.cbc-video--thumb-wrapper.cbc-big[style="display: none;"]')) {
  128. // Sports video
  129. movedTopPlayer(document.querySelector('.cbc-video--player-wrapper'));
  130. var css = 'body.asdf-16x9 .cbc-video--player-wrapper { width: 100vw !important; height: calc(27px + 100vh + 59px) !important; position: absolute; top: -27px; }';
  131. css += 'body.asdf-16x9 .cbc-video--player-wrapper.cbc-live-or-full-evt:hover { top: calc(-27px - 59px); }';
  132. css += 'body.asdf-16x9 { margin-top: 100vh; }';
  133. //css += 'body.asdf-fill-height .cbc-video--player-wrapper { width: calc((100vh - 60px - 59px) * 1.777777777) !important; height: 100vh !important; margin: 0 auto; }';
  134. //css += 'body.asdf-fill-width .cbc-video--player-wrapper { width: 100vw !important; height: calc(60px + 56.25vw + 59px) !important; }';
  135. GM_addStyle(css);
  136. function onResize() {
  137. var height = 59 + window.innerWidth * 0.5625 + window.innerHeight * 0.06;
  138. var ratio = window.innerWidth / window.innerHeight;
  139. console.log('onResize', height, ratio)
  140. if (1.7 <= ratio && ratio <= 1.8 ) { // 16:9 = 1.7777777...
  141. document.body.classList.remove('asdf-fill-width');
  142. document.body.classList.remove('asdf-fill-height');
  143. document.body.classList.add('asdf-16x9');
  144. } else if (height > window.innerHeight) {
  145. document.body.classList.remove('asdf-fill-width');
  146. document.body.classList.remove('asdf-16x9');
  147. document.body.classList.add('asdf-fill-height');
  148. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  149. videoBoxElement.style.width = "calc((100vh - 27px - 59px) * 1.777777777)";
  150. videoBoxElement.style.height = "100vh";
  151. videoBoxElement.style.margin = '0 auto';
  152. } else {
  153. document.body.classList.remove('asdf-fill-height');
  154. document.body.classList.remove('asdf-16x9');
  155. document.body.classList.add('asdf-fill-width');
  156. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  157. videoBoxElement.style.width = "100vw";
  158. videoBoxElement.style.height = "calc(27px + 56.25vw + 59px)";
  159. }
  160. }
  161. window.addEventListener('resize', onResize);
  162. window.addEventListener('click', function(){
  163. setTimeout(onResize, 1000);
  164. });
  165. onResize();
  166. } else {
  167. // Regular video
  168. movedTopPlayer(document.querySelector('.cbc-video'));
  169. var css = 'figure.cbc-video--thumb-wrapper.cbc-big { height: 100%; margin: 0; }';
  170. css += 'figure.cbc-video--thumb-wrapper.cbc-big picture { width: 100%; }';
  171. css += 'figure.cbc-video--thumb-wrapper.cbc-big picture img { width: 100%; }';
  172. GM_addStyle(css);
  173. function onResize() {
  174. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  175. var height = 26 + window.innerWidth * 0.5625;
  176. if (height > window.innerHeight) {
  177. videoBoxElement.style.width = "calc((100vh - 26px) * 1.77777777)";
  178. videoBoxElement.style.height = "100vh";
  179. videoBoxElement.style.margin = '0 auto';
  180. } else {
  181. videoBoxElement.style.width = "100vw";
  182. videoBoxElement.style.height = "calc(26px + 56.25vw)";
  183. }
  184. }
  185. window.addEventListener('resize', onResize);
  186. onResize();
  187. }
  188. } else if (document.location.host.endsWith('www.dailymotion.com')) {
  189. var css = '#player:not(:hover) .dmp_will-transition.dmp_is-transitioned--fadeinslide { opacity: 0; }';
  190. if (document.location.pathname.startsWith('/playlist')) {
  191. css += '#player_container { height: 100vh!important; width: 100vw!important; }';
  192. css += '#playerv5-iframe { width: 100% !important; height: 100% !important; }'; // playlists
  193. css += '.sd_header.sd_header--fixed { top: 100vh; position: absolute; }';
  194. css += '#content { margin-top: 60px; }';
  195. movedTopPlayer(document.querySelector('#player_container'));
  196. absoluteTopPlayer('#player_container');
  197.  
  198. GM_addStyle(css);
  199.  
  200. } else if (document.location.pathname.startsWith('/video')) {
  201. //css +='.main-container-player { display: none; }';
  202. //css += '#player { height: 100vh!important; width: 100vw!important; }';
  203. css += '.Player { height: 100vh!important; width: 100vw!important; }';
  204. css += '.Player { top: 0!important; left: 0!important; }';
  205. css += 'header { position: absolute!important; top: 100vh !important; }';
  206. css += 'footer { margin-top: 50px; }';
  207. css += 'div[class^="Video__placeholder___"] { margin-top: -180px; height: 100vh!important; }';
  208. GM_addStyle(css);
  209. document.addEventListener('load',function(){
  210. movedTopPlayer(document.querySelector('.Player'));
  211. });
  212. }
  213.  
  214. } else if (document.location.host.endsWith('streamable.com')) {
  215. if (document.location.pathname == '/') {
  216. return;
  217. }
  218. var css = '#player-content, #player.container .media-container, #player.container #filler, #player.container .player { max-width: 100% !important; width:100%; }';
  219. css += '#player.container #filler { padding-bottom: 100vh !important; }';
  220. css += '.player { background: #000; }';
  221. css += '.player, #player.container video { max-height: 100vh; }';
  222. css += '#player > div[style="height:15px;"] { display: none; }';
  223. css += '#player.container .topbanner { display: none; }';
  224. GM_addStyle(css);
  225. } else if (document.location.host.endsWith('globaltv.com')) {
  226. var css = '#corusVideo_PlayerContainer { width: 100vw !important; height: 100vh !important; }';
  227. css += '#corusVideo_PlayerContainer + .playlist { display: none; }';
  228. css += '#corusVideo_PlayerContainer.jwplayer.jw-stretch-uniform video { object-fit: contain !important; }';
  229. GM_addStyle(css);
  230. var videoPlayerElement = document.querySelector('#corusVideo_PlayerContainer') // corusVideo_PlayerContainer shawVideo_PlaybackArea
  231. movedTopPlayer(videoPlayerElement);
  232.  
  233. window.addEventListener('keydown', function(e){
  234. if (e.key == ' ' && e.target == document.body) {
  235. var video = document.querySelector('.jw-video')
  236. if (video) {
  237. e.preventDefault();
  238. if (video.paused) {
  239. video.play()
  240. } else {
  241. video.pause()
  242. }
  243. }
  244. }
  245. });
  246. } else if (document.location.host.endsWith('much.com')) {
  247. var css = '#TopVideoWidgetSection, #ShowNav, #MainHeader, #MastHeadTakeover { display: none; }';
  248. css += '#ShowTop #PlayerWrapper, #ShowTop .container-fluid, #ShowTop #ShowInfo, #ShowTop {';
  249. css += 'margin: 0 !important; padding: 0 !important;';
  250. css += 'width: 100vw !important; height: 100vh !important; max-width: 100vw !important; max-height: 100vh !important;';
  251. css += '}';
  252. GM_addStyle(css);
  253. } else if (document.location.host.endsWith('ctvnews.ca')) {
  254. if (window.location.pathname == '/latest') {
  255. // Redirect to latest video
  256. document.body.style.opacity = "0"
  257. document.documentElement.style.transition = "background 0.4s"
  258. document.documentElement.style.background = "#000"
  259. var latestVideoLink = document.querySelector('.mainnavigation + .drop_down + script + .drop_down > .drop_down_element_container > div > div > ul > li:first-child > a')
  260. if (latestVideoLink) {
  261. window.location.href = latestVideoLink.href
  262. }
  263. } else if (window.location.pathname == '/video') {
  264. var contentWrapper = document.querySelector('body > .content > .video-header > .content-wrapper')
  265. if (contentWrapper) {
  266. var header = document.querySelector('body > header')
  267. document.body.insertBefore(contentWrapper, header)
  268. var mediaplayerdiv = document.querySelector('#mediaplayerdiv')
  269.  
  270. contentWrapper.querySelector('.topname').style.display = "none"
  271. contentWrapper.style.width = "100%"
  272. contentWrapper.style.height = "100vh"
  273. contentWrapper.style.maxWidth = "100vw"
  274. contentWrapper.style.maxHeight = "100vh"
  275. contentWrapper.style.background="#000"
  276.  
  277. function onWindowResize() {
  278. var viewportWidth = document.documentElement.clientWidth
  279. var viewportHeight = document.documentElement.clientHeight
  280. var translate = "translate(" + ((viewportWidth - 960)/2) + "px, " + ((viewportHeight - 540)/2) + "px)"
  281. var scale = "scale(" + Math.min(viewportWidth / 960, viewportHeight / 540) + ")"
  282. mediaplayerdiv.style.transform = translate + " " + scale
  283. }
  284. window.addEventListener('resize', onWindowResize);
  285. onWindowResize();
  286. return; // Keep scrollbars
  287. }
  288. } else {
  289. return; // Keep scrollbars
  290. }
  291. } else if (document.location.host.endsWith('watch.cbc.ca')) {
  292. var css = '#masthead { position: absolute; z-index: 1; width: 100%; opacity: 0; transition: opacity 250ms ease-in-out; }';
  293. css += '#masthead:hover { opacity: 1; }';
  294. css += '.regional-channel .container { max-width: 100%; }';
  295. css += '.player-container.live, .jwplayer.jw-flag-aspect-mode { max-height: 100vh; }';
  296. css += '.jwplayer.jw-stretch-uniform video { object-fit: contain !important; }';
  297. css += '.regional-channel footer.regional-channel-footer, section.content-article.live { padding: 10px 0; }';
  298. css += 'section.content-article.live-premium { display: none; }';
  299. GM_addStyle(css);
  300. }
  301.  
  302. GM_addStyle('html::-webkit-scrollbar { width: 0; height: 0; } body::-webkit-scrollbar { width: 0; height: 0; }');
  303. })();