Resize Video To Window Size

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

目前為 2018-07-14 提交的版本,檢視 最新版本

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