Resize Video To Window Size

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

目前為 2019-06-10 提交的版本,檢視 最新版本

  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 51
  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. var css = '.jwplayer { width: 100vw !important; height: 100vh !important; max-height: 100vh !important; }';
  226. css += '.playlist { height: 260px !important; }';
  227. css += '.jwplayer.jw-stretch-uniform video { object-fit: contain !important; }';
  228. GM_addStyle(css);
  229. waitFor('.jwplayer', function(jwPlayerElement) {
  230. movedTopPlayer(jwPlayerElement);
  231.  
  232. waitFor('.jwplayer video', function(videoElement) {
  233. setTimeout(function() {
  234. videoElement.muted = false;
  235. window.scroll(0, 0);
  236. }, 200)
  237. });
  238. });
  239.  
  240. window.addEventListener('keydown', function(e){
  241. if (e.key == ' ' && e.target == document.body) {
  242. var video = document.querySelector('.jwplayer video')
  243. if (video) {
  244. e.preventDefault();
  245. if (video.paused) {
  246. video.play()
  247. } else {
  248. video.pause()
  249. }
  250. }
  251. }
  252. });
  253. } else if (document.location.host.endsWith('much.com')) {
  254. var css = '#TopVideoWidgetSection, #ShowNav, #MainHeader, #MastHeadTakeover { display: none; }';
  255. css += '#ShowTop #PlayerWrapper, #ShowTop .container-fluid, #ShowTop #ShowInfo, #ShowTop {';
  256. css += 'margin: 0 !important; padding: 0 !important;';
  257. css += 'width: 100vw !important; height: 100vh !important; max-width: 100vw !important; max-height: 100vh !important;';
  258. css += '}';
  259. css += '#ShowTop #ShowInfo #EpisodeInfo { margin-top: 0 !important; }';
  260. css += '.jwplayer { max-height: 100vh; }';
  261. css += '#EpisodeInfo .new-episodes { display: none !important; }';
  262. GM_addStyle(css);
  263. } else if (document.location.host.endsWith('ctvnews.ca')) {
  264. if (window.location.pathname == '/latest') {
  265. // Redirect to latest video
  266. document.body.style.opacity = "0"
  267. document.documentElement.style.transition = "background 0.4s"
  268. document.documentElement.style.background = "#000"
  269. var latestVideoLink = document.querySelector('.mainnavigation + .drop_down + script + .drop_down > .drop_down_element_container > div > div > ul > li:first-child > a')
  270. if (latestVideoLink) {
  271. window.location.href = latestVideoLink.href
  272. }
  273. } else if (window.location.pathname == '/video') {
  274. var contentWrapper = document.querySelector('body > .content > .video-header > .content-wrapper')
  275. if (contentWrapper) {
  276. var header = document.querySelector('body > header')
  277. document.body.insertBefore(contentWrapper, header)
  278. var mediaplayerdiv = document.querySelector('#mediaplayerdiv')
  279.  
  280. contentWrapper.querySelector('.topname').style.display = "none"
  281. contentWrapper.style.width = "100%"
  282. contentWrapper.style.height = "100vh"
  283. contentWrapper.style.maxWidth = "100vw"
  284. contentWrapper.style.maxHeight = "100vh"
  285. contentWrapper.style.background="#000"
  286.  
  287. function onWindowResize() {
  288. var viewportWidth = document.documentElement.clientWidth
  289. var viewportHeight = document.documentElement.clientHeight
  290. var translate = "translate(" + ((viewportWidth - 960)/2) + "px, " + ((viewportHeight - 540)/2) + "px)"
  291. var scale = "scale(" + Math.min(viewportWidth / 960, viewportHeight / 540) + ")"
  292. mediaplayerdiv.style.transform = translate + " " + scale
  293. }
  294. window.addEventListener('resize', onWindowResize);
  295. onWindowResize();
  296. return; // Keep scrollbars
  297. }
  298. } else {
  299. return; // Keep scrollbars
  300. }
  301. } else if (document.location.host.endsWith('watch.cbc.ca')) {
  302. var css = '#masthead { position: absolute; z-index: 1; width: 100%; opacity: 0; transition: opacity 250ms ease-in-out; }';
  303. css += '#masthead:hover { opacity: 1; }';
  304. css += '.regional-channel .container { max-width: 100%; }';
  305. css += '.player-container.live, .jwplayer.jw-flag-aspect-mode { max-height: 100vh; }';
  306. css += '.jwplayer.jw-stretch-uniform video { object-fit: contain !important; }';
  307. css += '.regional-channel footer.regional-channel-footer, section.content-article.live { padding: 10px 0; }';
  308. css += 'section.content-article.live-premium { display: none; }';
  309. css += '.upgrade-banner, .live-premium, iframe.zEWidget-launcher { display: none; }';
  310. css += '.upgrade-banner + .app-container.with-banner-large { top: 0; }';
  311. css += '.content-article { padding-top: 0; padding-bottom: 0; }';
  312. css += '.content-section.live-detail-layout { max-width: 100%; }';
  313. GM_addStyle(css);
  314. } else if (document.location.host.endsWith('www.ctv.ca')) {
  315. var css = ''
  316. css += '#leaderboard_container { margin-top: 0px !important; }'
  317. css += 'body.tablet #leaderboard_container.attach_to_nav ~ .site-wrapper .navigation-wrapper,'
  318. css += 'body.web #leaderboard_container.attach_to_nav ~ .site-wrapper .navigation-wrapper,'
  319. css += 'body.web_xl #leaderboard_container.attach_to_nav ~ .site-wrapper .navigation-wrapper,'
  320. css += 'html .page-top.container-fluid { position: static !important; }'
  321. css += 'html .jwplayer { max-height: 100vh !important; }'
  322. css += 'html .jwplayer.jw-flag-aspect-mode { height: 100vh !important; }'
  323. css += '.video-socialshare { display: none !important; }'
  324. css += '@media screen and (max-width: 992px) and (min-width: 320px) { .mobile-flyout { display: none !important; } }'
  325. GM_addStyle(css);
  326. waitFor('.jwplayer', function(jwPlayerElement) {
  327. movedTopPlayer(jwPlayerElement);
  328.  
  329. waitFor('.jwplayer video', function(videoElement) {
  330. setTimeout(function() {
  331. videoElement.muted = false;
  332. }, 200)
  333. });
  334. });
  335. } else if (document.location.host.endsWith('funimation.com')) {
  336. var videoBoxElement = document.querySelector('.video-player-section .video-player-container');
  337. if (!videoBoxElement) return;
  338. movedTopPlayer(videoBoxElement);
  339. videoBoxElement.classList.remove('col-md-10');
  340. var css = 'html, body { width: 100%; height: 100%; }';
  341. css += '.video-player-container { width: 100vw !important; height: 100vh !important; }';
  342. css += '#funimation-main-site-header { position: absolute; top: 100vh; }';
  343. GM_addStyle(css);
  344. } else if (document.location.host.endsWith('crave.ca')) {
  345. if (document.location.pathname.startsWith('/live')) return;
  346. var videoBoxElement = document.querySelector('video-player');
  347. if (!videoBoxElement) return;
  348. var css = 'footer, .back-button-wrapper, #mega-menu { display: none !important; }';
  349. css += '.container-site-margin { margin-left: 0; margin-right: 0; }';
  350. css += '.web-videoplayer { margin: 0; }';
  351. css += 'html .jwplayer.jw-flag-aspect-mode { height: 100vh !important; }';
  352. GM_addStyle(css);
  353. } else if (document.location.host.endsWith('tubitv.com')) {
  354. var css = 'header { transition: transform .3s, opacity .3s !important; }';
  355. css += 'header.hide-header { opacity: 0 !important }';
  356. css += 'header.hide-header:hover { opacity: 1 !important; }';
  357. 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; }';
  358. css += 'header + div > div:first-child > div:first-child > div:nth-child(2) > div:first-child > section { padding-top: 0 !important; height: 100vh !important; }';
  359. 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%); }';
  360. 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%); }';
  361. css += '#captionsComponent > span { background: none !important; font-size: 3rem !important;';
  362. 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;';
  363. css += '}';
  364. GM_addStyle(css);
  365. var updateHeader = function() {
  366. var header = document.querySelector('header')
  367. if (header) {
  368. var video = document.querySelector('video')
  369. if (video) {
  370. header.classList.add('hide-header')
  371. } else {
  372. header.classList.remove('hide-header')
  373. }
  374. }
  375. }
  376. updateHeader()
  377. setInterval(updateHeader, 1000)
  378. }
  379.  
  380. GM_addStyle('html::-webkit-scrollbar { width: 0; height: 0; } body::-webkit-scrollbar { width: 0; height: 0; }');
  381. GM_addStyle('html { scrollbar-width: none; } body { scrollbar-width: none; }');
  382. })();