Resize Video To Window Size

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

目前为 2020-01-31 提交的版本。查看 最新版本

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