Resize Video To Window Size

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

当前为 2019-06-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 52
  7. // @include https://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 https://www.youpak.com/watch*
  15. // @include https://olympics.cbc.ca/video/*
  16. // @include https://olympics.cbc.ca/divaPlayer/*
  17. // @include http://www.dailymotion.com/*
  18. // @include https://www.dailymotion.com/*
  19. // @include https://streamable.com/*
  20. // @include https://www.globaltv.com/shows/the-late-show-with-stephen-colbert/*
  21. // @include https://www.much.com/shows/south-park/episode/*/*/
  22. // @include http://*.ctvnews.ca/*
  23. // @include https://watch.cbc.ca/live/channel/*
  24. // @include https://watch.cbc.ca/live/*
  25. // @include https://www.ctv.ca/video/*
  26. // @include https://www.ctv.ca/*/Video*
  27. // @include https://www.ctv.ca/Movie/*
  28. // @include https://www.funimation.com/shows/*
  29. // @include https://www.crave.ca/*
  30. // @include https://tubitv.com/*
  31. // @grant GM_addStyle
  32. // ==/UserScript==
  33.  
  34. (function() {
  35. var fixedOverlayPlayer = function(selector) {
  36. var css = selector + "{";
  37. css += "position: fixed;";
  38. css += "top: 0;";
  39. css += "left: 0;";
  40. css += "right: 0;";
  41. css += "bottom: 0;";
  42. css += "}";
  43. GM_addStyle(css);
  44. };
  45.  
  46. var absoluteTopPlayer = function(selector, staticSelectors) {
  47. var css = selector + "{";
  48. css += "position: absolute;";
  49. css += "top: 0;";
  50. css += "left: 0;";
  51. css += "width: 100vw;";
  52. css += "height: 100vh;";
  53. css += "padding: 0;";
  54. css += "margin: 0;";
  55. css += "}";
  56. css += "body {";
  57. css += "margin-top: 100vh;";
  58. css += "margin-top: 100vh;";
  59. css += "padding-top: 0;";
  60. css += "}";
  61. if (staticSelectors) {
  62. css += staticSelectors + "{";
  63. css += "position: static";
  64. css += "}";
  65. }
  66. GM_addStyle(css);
  67. };
  68.  
  69. var movedTopPlayer = function(videoBoxElement) {
  70. document.body.insertBefore(videoBoxElement, document.body.firstChild);
  71. videoBoxElement.style.width = '100%';
  72. videoBoxElement.style.height = '100%';
  73. videoBoxElement.style.backgroundColor = '#000';
  74. };
  75.  
  76. var waitFor = function(selector, callback) {
  77. var tick = function(){
  78. var e = document.querySelector(selector);
  79. if (e) {
  80. callback(e);
  81. } else {
  82. setTimeout(tick, 100);
  83. }
  84. };
  85. tick();
  86. };
  87.  
  88. var urlMatch = function(regexStr) {
  89. regexStr = regexStr.replace(/\//g, '\\/'); // Auto escape forward slashes to make url regexes more legible.
  90. var regex = new RegExp(regexStr);
  91. return regex.exec(window.location.href);
  92. };
  93.  
  94. if (document.location.host.endsWith('crunchyroll.com')) {
  95. if (!window.location.href.match(/^https:\/\/www\.crunchyroll\.(com|ca)\/.+\/.+-\d+\/?/)) return;
  96. var videoBoxElement = document.getElementById('showmedia_video_box') || document.getElementById('showmedia_video_box_wide');
  97. if (!videoBoxElement) return;
  98. movedTopPlayer(videoBoxElement);
  99. videoBoxElement.addEventListener('keydown', function(e) {
  100. if (e.key == 'PageDown') {
  101. window.scrollBy(0, window.innerHeight * 0.9);
  102. } else if (e.key == 'PageUp') {
  103. window.scrollBy(0, -window.innerHeight * 0.9);
  104. } else if (e.key == 'ArrowDown') {
  105. window.scrollBy(0, 40);
  106. } else if (e.key == 'ArrowUp') {
  107. window.scrollBy(0, -40);
  108. }
  109. }, true);
  110. var videoObject = videoBoxElement.querySelector('object');
  111. if (videoObject) {
  112. videoObject.focus();
  113. }
  114. var css = 'html, body { width: 100%; height: 100%; }';
  115. css += '#showmedia_video_box, #showmedia_video_box_wide, #showmedia_video_player { width: 100%; height: calc(100vh) !important; }';
  116. css += '.html5-video-player { width: 100% !important; height: calc(100vh) !important; }'; // https://github.com/YePpHa/crunchyroll-html5
  117. GM_addStyle(css);
  118. } else if (document.location.href.startsWith('https://docs.google.com/file/')) {
  119. fixedOverlayPlayer('#drive-viewer-video-player-object-0');
  120. var css = 'body:not(:hover) .ytp-chrome-bottom { opacity: 0 !important; }';
  121. css += 'body:not(:hover) .drive-viewer-toolstrip { opacity: 0 !important; }';
  122. GM_addStyle(css);
  123. } else if (document.location.href.startsWith('https://drive.google.com/')) {
  124. fixedOverlayPlayer('.drive-viewer-video-player');
  125. var css = '.drive-viewer-toolstrip { opacity: 0 !important; }';
  126. css += '.drive-viewer-toolstrip:hover { opacity: 1 !important; }';
  127. GM_addStyle(css);
  128. } else if (document.location.href.startsWith('https://vimeo.com/')) {
  129. if (! /\/\d+/.exec(document.location.pathname))
  130. return;
  131. 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; }';
  132. css += '.vp-player-layout { left: 0 !important; top: 0 !important; width: 100vw !important; height: 100vh !important; }';
  133. css += '.clip_main > *:not(.player_area-wrapper) { margin-top: 70px; }';
  134. css += '.VimeoBrand_ColorRibbon, .body_ribbon, .topnav_desktop, .topnav_mobile { position: absolute; top: 100vh; width: 100%; }';
  135. css += '.topnav_desktop { top: calc(100vh + 5px); }';
  136. GM_addStyle(css);
  137.  
  138. // autoplay
  139. function tick() {
  140. var e = document.querySelector('button.play[aria-label="Play"]');
  141. if (e) {
  142. e.click();
  143. } else {
  144. setTimeout(tick, 100);
  145. }
  146. }
  147. setTimeout(tick, 100);
  148. } else if (document.location.host.endsWith('onepieceofficial.com')) {
  149. movedTopPlayer(document.querySelector('#FUNimationVideo'));
  150. } else if (document.location.host.endsWith('youpak.com')) {
  151. movedTopPlayer(document.querySelector('.videoWrapper'))
  152. var css = 'body > .container { padding-top: 60px; }'
  153. css += '.navbar-fixed-top { position: absolute; top: 100vh; }'
  154. css += 'body { padding-top: 0; }'
  155. GM_addStyle(css)
  156. } else if (document.location.host == 'olympics.cbc.ca') {
  157. console.log(document.location.pathname, document.location.pathname.match(/\/video\/([^\/]+)\/([^\/]+)(\/?)/))
  158. if (document.location.pathname.match(/\/video\/([^\/]+)\/([^\/]+)(\/?)/)) {
  159. var css = '.cbc-video--player-wrapper { position: static !important; }'
  160. css += '.cbc-video {'
  161. css += ' position: absolute !important;'
  162. css += ' top: 0 !important;'
  163. css += ' left: 0 !important;'
  164. css += ' padding: 0px !important;'
  165. css += ' margin: 0px !important;'
  166. css += ' width: 100% !important;'
  167. css += ' height: 100vh !important;'
  168. css += '}'
  169. css += 'figure.cbc-video--thumb-wrapper, a[data-js-hook="play-video"] picture img { max-height: 100vh !important; }'
  170. css += '.or-podium .or-box { position: static !important; }'
  171. css += '.or-podium .col-xs-1, .or-podium .col-sm-1, .or-podium .col-md-1, .or-podium .col-lg-1, .or-podium .col-xs-2, .or-podium .col-sm-2, .or-podium .col-md-2, .or-podium .col-lg-2, .or-podium .col-xs-3, .or-podium .col-sm-3, .or-podium .col-md-3, .or-podium .col-lg-3, .or-podium .col-xs-4, .or-podium .col-sm-4, .or-podium .col-md-4, .or-podium .col-lg-4, .or-podium .col-xs-5, .or-podium .col-sm-5, .or-podium .col-md-5, .or-podium .col-lg-5, .or-podium .col-xs-6, .or-podium .col-sm-6, .or-podium .col-md-6, .or-podium .col-lg-6, .or-podium .col-xs-7, .or-podium .col-sm-7, .or-podium .col-md-7, .or-podium .col-lg-7, .or-podium .col-xs-8, .or-podium .col-sm-8, .or-podium .col-md-8, .or-podium .col-lg-8, .or-podium .col-xs-9, .or-podium .col-sm-9, .or-podium .col-md-9, .or-podium .col-lg-9, .or-podium .col-xs-10, .or-podium .col-sm-10, .or-podium .col-md-10, .or-podium .col-lg-10, .or-podium .col-xs-11, .or-podium .col-sm-11, .or-podium .col-md-11, .or-podium .col-lg-11, .or-podium .col-xs-12, .or-podium .col-sm-12, .or-podium .col-md-12, .or-podium .col-lg-12 { position: static; }'
  172. css += 'body:not(.cbc-main-page) { padding-top: 100vh; }'
  173. GM_addStyle(css);
  174. var playVideoButton = document.querySelector('a[data-js-hook="play-video"]')
  175. if (playVideoButton) {
  176. playVideoButton.click()
  177. }
  178. } else if (document.location.pathname.startsWith('/divaPlayer')) {
  179. var css = '#videoContainer:not(:hover) > .caption { opacity: 0; }'
  180. css += '#videoContainer:not(:hover) .controlbar-diva { opacity: 0 !important; }'
  181. css += '#videoContainer:not(:hover) #icon-menu-diva { opacity: 0; }'
  182. css += '#videoContainer:not(:hover) diva-simple-controls { opacity: 0 !important; }'
  183. GM_addStyle(css);
  184. } else {
  185. return; // Keep scrollbars
  186. }
  187. } else if (document.location.host.endsWith('www.dailymotion.com')) {
  188. var css = '#player:not(:hover) .dmp_will-transition.dmp_is-transitioned--fadeinslide { opacity: 0; }';
  189. if (document.location.pathname.startsWith('/playlist')) {
  190. css += '#player_container { height: 100vh!important; width: 100vw!important; }';
  191. css += '#playerv5-iframe { width: 100% !important; height: 100% !important; }'; // playlists
  192. css += '.sd_header.sd_header--fixed { top: 100vh; position: absolute; }';
  193. css += '#content { margin-top: 60px; }';
  194. movedTopPlayer(document.querySelector('#player_container'));
  195. absoluteTopPlayer('#player_container');
  196.  
  197. GM_addStyle(css);
  198.  
  199. } else if (document.location.pathname.startsWith('/video')) {
  200. //css +='.main-container-player { display: none; }';
  201. //css += '#player { height: 100vh!important; width: 100vw!important; }';
  202. css += '.Player { height: 100vh!important; width: 100vw!important; }';
  203. css += '.Player { top: 0!important; left: 0!important; }';
  204. css += 'header { position: absolute!important; top: 100vh !important; }';
  205. css += 'footer { margin-top: 50px; }';
  206. css += 'div[class^="Video__placeholder___"] { margin-top: -180px; height: 100vh!important; }';
  207. GM_addStyle(css);
  208. document.addEventListener('load',function(){
  209. movedTopPlayer(document.querySelector('.Player'));
  210. });
  211. }
  212.  
  213. } else if (document.location.host.endsWith('streamable.com')) {
  214. if (document.location.pathname == '/') {
  215. return;
  216. }
  217. var css = '#player-content, #player.container .media-container, #player.container #filler, #player.container .player { max-width: 100% !important; width:100%; }';
  218. css += '#player.container #filler { padding-bottom: 100vh !important; }';
  219. css += '.player { background: #000; }';
  220. css += '.player, #player.container video { max-height: 100vh; }';
  221. css += '#player > div[style="height:15px;"] { display: none; }';
  222. css += '#player.container .topbanner { display: none; }';
  223. GM_addStyle(css);
  224. } else if (document.location.host.endsWith('globaltv.com')) {
  225. if (document.location.pathname == '/shows/the-late-show-with-stephen-colbert/') {
  226. return
  227. }
  228. var css = '.jwplayer { width: 100vw !important; height: 100vh !important; max-height: 100vh !important; }';
  229. css += '.playlist { height: 260px !important; }';
  230. css += '.jwplayer.jw-stretch-uniform video { object-fit: contain !important; }';
  231. GM_addStyle(css);
  232.  
  233. waitFor('.jwplayer', function(jwPlayerElement) {
  234. movedTopPlayer(jwPlayerElement);
  235.  
  236. jwPlayerElement.classList.add('content-wrapper') // trick to jquery scroll animation to stop at this element
  237.  
  238. waitFor('.jwplayer video', function(videoElement) {
  239. setTimeout(function() {
  240. videoElement.muted = false;
  241. window.scroll(0, 0);
  242. }, 200)
  243. });
  244. });
  245.  
  246. window.addEventListener('keydown', function(e){
  247. if (e.key == ' ' && e.target == document.body) {
  248. var video = document.querySelector('.jwplayer video')
  249. if (video) {
  250. e.preventDefault();
  251. if (video.paused) {
  252. video.play()
  253. } else {
  254. video.pause()
  255. }
  256. }
  257. }
  258. });
  259.  
  260. /*if (typeof jQuery !== "undefined") {
  261. jQuery(function($){
  262. $('html, body').prop('scrollTop', 0)
  263. })
  264. }*/
  265. } else if (document.location.host.endsWith('much.com')) {
  266. var css = '#TopVideoWidgetSection, #ShowNav, #MainHeader, #MastHeadTakeover { display: none; }';
  267. css += '#ShowTop #PlayerWrapper, #ShowTop .container-fluid, #ShowTop #ShowInfo, #ShowTop {';
  268. css += 'margin: 0 !important; padding: 0 !important;';
  269. css += 'width: 100vw !important; height: 100vh !important; max-width: 100vw !important; max-height: 100vh !important;';
  270. css += '}';
  271. css += '#ShowTop #ShowInfo #EpisodeInfo { margin-top: 0 !important; }';
  272. css += '.jwplayer { max-height: 100vh; }';
  273. css += '#EpisodeInfo .new-episodes { display: none !important; }';
  274. GM_addStyle(css);
  275. } else if (document.location.host.endsWith('ctvnews.ca')) {
  276. if (window.location.pathname == '/latest') {
  277. // Redirect to latest video
  278. document.body.style.opacity = "0"
  279. document.documentElement.style.transition = "background 0.4s"
  280. document.documentElement.style.background = "#000"
  281. var latestVideoLink = document.querySelector('.mainnavigation + .drop_down + script + .drop_down > .drop_down_element_container > div > div > ul > li:first-child > a')
  282. if (latestVideoLink) {
  283. window.location.href = latestVideoLink.href
  284. }
  285. } else if (window.location.pathname == '/video') {
  286. var contentWrapper = document.querySelector('body > .content > .video-header > .content-wrapper')
  287. if (contentWrapper) {
  288. var header = document.querySelector('body > header')
  289. document.body.insertBefore(contentWrapper, header)
  290. var mediaplayerdiv = document.querySelector('#mediaplayerdiv')
  291.  
  292. contentWrapper.querySelector('.topname').style.display = "none"
  293. contentWrapper.style.width = "100%"
  294. contentWrapper.style.height = "100vh"
  295. contentWrapper.style.maxWidth = "100vw"
  296. contentWrapper.style.maxHeight = "100vh"
  297. contentWrapper.style.background="#000"
  298.  
  299. function onWindowResize() {
  300. var viewportWidth = document.documentElement.clientWidth
  301. var viewportHeight = document.documentElement.clientHeight
  302. var translate = "translate(" + ((viewportWidth - 960)/2) + "px, " + ((viewportHeight - 540)/2) + "px)"
  303. var scale = "scale(" + Math.min(viewportWidth / 960, viewportHeight / 540) + ")"
  304. mediaplayerdiv.style.transform = translate + " " + scale
  305. }
  306. window.addEventListener('resize', onWindowResize);
  307. onWindowResize();
  308. return; // Keep scrollbars
  309. }
  310. } else {
  311. return; // Keep scrollbars
  312. }
  313. } else if (document.location.host.endsWith('watch.cbc.ca')) {
  314. var css = '#masthead { position: absolute; z-index: 1; width: 100%; opacity: 0; transition: opacity 250ms ease-in-out; }';
  315. css += '#masthead:hover { opacity: 1; }';
  316. css += '.regional-channel .container { max-width: 100%; }';
  317. css += '.player-container.live, .jwplayer.jw-flag-aspect-mode { max-height: 100vh; }';
  318. css += '.jwplayer.jw-stretch-uniform video { object-fit: contain !important; }';
  319. css += '.regional-channel footer.regional-channel-footer, section.content-article.live { padding: 10px 0; }';
  320. css += 'section.content-article.live-premium { display: none; }';
  321. css += '.upgrade-banner, .live-premium, iframe.zEWidget-launcher { display: none; }';
  322. css += '.upgrade-banner + .app-container.with-banner-large { top: 0; }';
  323. css += '.content-article { padding-top: 0; padding-bottom: 0; }';
  324. css += '.content-section.live-detail-layout { max-width: 100%; }';
  325. GM_addStyle(css);
  326. } else if (document.location.host.endsWith('www.ctv.ca')) {
  327. var css = ''
  328. css += '#leaderboard_container { margin-top: 0px !important; }'
  329. css += 'body.tablet #leaderboard_container.attach_to_nav ~ .site-wrapper .navigation-wrapper,'
  330. css += 'body.web #leaderboard_container.attach_to_nav ~ .site-wrapper .navigation-wrapper,'
  331. css += 'body.web_xl #leaderboard_container.attach_to_nav ~ .site-wrapper .navigation-wrapper,'
  332. css += 'html .page-top.container-fluid { position: static !important; }'
  333. css += 'html .jwplayer { max-height: 100vh !important; }'
  334. css += 'html .jwplayer.jw-flag-aspect-mode { height: 100vh !important; }'
  335. css += '.video-socialshare { display: none !important; }'
  336. css += '@media screen and (max-width: 992px) and (min-width: 320px) { .mobile-flyout { display: none !important; } }'
  337. GM_addStyle(css);
  338. waitFor('.jwplayer', function(jwPlayerElement) {
  339. movedTopPlayer(jwPlayerElement);
  340.  
  341. waitFor('.jwplayer video', function(videoElement) {
  342. setTimeout(function() {
  343. videoElement.muted = false;
  344. }, 200)
  345. });
  346. });
  347. } else if (document.location.host.endsWith('funimation.com')) {
  348. var videoBoxElement = document.querySelector('.video-player-section .video-player-container');
  349. if (!videoBoxElement) return;
  350. movedTopPlayer(videoBoxElement);
  351. videoBoxElement.classList.remove('col-md-10');
  352. var css = 'html, body { width: 100%; height: 100%; }';
  353. css += '.video-player-container { width: 100vw !important; height: 100vh !important; }';
  354. css += '#funimation-main-site-header { position: absolute; top: 100vh; }';
  355. GM_addStyle(css);
  356. } else if (document.location.host.endsWith('crave.ca')) {
  357. if (document.location.pathname.startsWith('/live')) return;
  358. var videoBoxElement = document.querySelector('video-player');
  359. if (!videoBoxElement) return;
  360. var css = 'footer, .back-button-wrapper, #mega-menu { display: none !important; }';
  361. css += '.container-site-margin { margin-left: 0; margin-right: 0; }';
  362. css += '.web-videoplayer { margin: 0; }';
  363. css += 'html .jwplayer.jw-flag-aspect-mode { height: 100vh !important; }';
  364. GM_addStyle(css);
  365. } else if (document.location.host.endsWith('tubitv.com')) {
  366. var css = 'header { transition: transform .3s, opacity .3s !important; }';
  367. css += 'header.hide-header { opacity: 0 !important }';
  368. css += 'header.hide-header:hover { opacity: 1 !important; }';
  369. css += 'header + div > div:first-child > div:first-child > div:nth-child(2) { top: 0 !important; left: 0 !important; width: 100% !important; height: 100vh !important; }';
  370. css += 'header + div > div:first-child > div:first-child > div:nth-child(2) > div:first-child > section { padding-top: 0 !important; height: 100vh !important; }';
  371. css += 'header + div > div:first-child > div:first-child > div:nth-child(2) > div:first-child > section > div > div:nth-child(2) > div:first-child { background-image: linear-gradient(0deg,rgba(0,0,0,0), rgba(0,0,0,0.25) 30%, rgba(0, 0, 0, 1) 90%); }';
  372. css += 'header + div > div:first-child > div:first-child > div:nth-child(2) > div:first-child > section > div > div:nth-child(2) > div:nth-child(2) { background-image: linear-gradient(180deg,rgba(0,0,0,0), rgba(0,0,0,0.25) 30%, rgba(0, 0, 0, 1) 90%); }';
  373. css += '#captionsComponent > span { background: none !important; font-size: 3rem !important;';
  374. css += 'text-shadow: 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000, 0 0 0.5rem #000;';
  375. css += '}';
  376. GM_addStyle(css);
  377. var updateHeader = function() {
  378. var header = document.querySelector('header')
  379. if (header) {
  380. var video = document.querySelector('video')
  381. if (video) {
  382. header.classList.add('hide-header')
  383. } else {
  384. header.classList.remove('hide-header')
  385. }
  386. }
  387. }
  388. updateHeader()
  389. setInterval(updateHeader, 1000)
  390. }
  391.  
  392. GM_addStyle('html::-webkit-scrollbar { width: 0; height: 0; } body::-webkit-scrollbar { width: 0; height: 0; }');
  393. GM_addStyle('html { scrollbar-width: none; } body { scrollbar-width: none; }');
  394. })();