Resize Video To Window Size

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

当前为 2020-02-21 提交的版本,查看 最新版本

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