Resize Video To Window Size

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

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