Resize Video To Window Size

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

当前为 2018-10-09 提交的版本,查看 最新版本

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