Resize Video To Window Size

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

当前为 2018-02-12 提交的版本,查看 最新版本

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