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