Resize Video To Window Size

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

当前为 2017-12-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 32
  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 http://olympics.cbc.ca/video/live/*
  16. // @include http://olympics.cbc.ca/video/vod/*
  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. // @grant GM_addStyle
  24. // ==/UserScript==
  25.  
  26. (function() {
  27. var fixedOverlayPlayer = function(selector) {
  28. var css = selector + "{";
  29. css += "position: fixed;";
  30. css += "top: 0;";
  31. css += "left: 0;";
  32. css += "right: 0;";
  33. css += "bottom: 0;";
  34. css += "}";
  35. GM_addStyle(css);
  36. };
  37. var absoluteTopPlayer = function(selector, staticSelectors) {
  38. var css = selector + "{";
  39. css += "position: absolute;";
  40. css += "top: 0;";
  41. css += "left: 0;";
  42. css += "width: 100vw;";
  43. css += "height: 100vh;";
  44. css += "padding: 0;";
  45. css += "margin: 0;";
  46. css += "}";
  47. css += "body {";
  48. css += "margin-top: 100vh;";
  49. css += "margin-top: 100vh;";
  50. css += "padding-top: 0;";
  51. css += "}";
  52. if (staticSelectors) {
  53. css += staticSelectors + "{";
  54. css += "position: static";
  55. css += "}";
  56. }
  57. GM_addStyle(css);
  58. };
  59. var movedTopPlayer = function(videoBoxElement) {
  60. document.body.insertBefore(videoBoxElement, document.body.firstChild);
  61. videoBoxElement.style.width = '100%';
  62. videoBoxElement.style.height = '100%';
  63. videoBoxElement.style.backgroundColor = '#000';
  64. };
  65.  
  66. var urlMatch = function(regexStr) {
  67. regexStr = regexStr.replace(/\//g, '\\/'); // Auto escape forward slashes to make url regexes more legible.
  68. var regex = new RegExp(regexStr);
  69. return regex.exec(window.location.href);
  70. };
  71.  
  72. if (document.location.host.endsWith('crunchyroll.com')) {
  73. if (!window.location.href.match(/^http:\/\/www\.crunchyroll\.(com|ca)\/.+\/.+-\d+\/?/)) return;
  74. var videoBoxElement = document.getElementById('showmedia_video_box') || document.getElementById('showmedia_video_box_wide');
  75. if (!videoBoxElement) return;
  76. movedTopPlayer(videoBoxElement);
  77. videoBoxElement.addEventListener('keydown', function(e) {
  78. if (e.key == 'PageDown') {
  79. window.scrollBy(0, window.innerHeight * 0.9);
  80. } else if (e.key == 'PageUp') {
  81. window.scrollBy(0, -window.innerHeight * 0.9);
  82. } else if (e.key == 'ArrowDown') {
  83. window.scrollBy(0, 40);
  84. } else if (e.key == 'ArrowUp') {
  85. window.scrollBy(0, -40);
  86. }
  87. }, true);
  88. var css = 'html, body { width: 100%; height: 100%; }';
  89. css += '#showmedia_video_box, #showmedia_video_box_wide, #showmedia_video_player { width: 100%; height: calc(100vh + 32px) !important; }';
  90. GM_addStyle(css);
  91. } else if (document.location.href.startsWith('https://docs.google.com/file/')) {
  92. fixedOverlayPlayer('#drive-viewer-video-player-object-0');
  93. var css = 'body:not(:hover) .ytp-chrome-bottom { opacity: 0 !important; }';
  94. css += 'body:not(:hover) .drive-viewer-toolstrip { opacity: 0 !important; }';
  95. GM_addStyle(css);
  96. } else if (document.location.href.startsWith('https://drive.google.com/')) {
  97. fixedOverlayPlayer('.drive-viewer-video-player');
  98. var css = '.drive-viewer-toolstrip { opacity: 0 !important; }';
  99. css += '.drive-viewer-toolstrip:hover { opacity: 1 !important; }';
  100. GM_addStyle(css);
  101. } else if (document.location.href.startsWith('https://vimeo.com/')) {
  102. if (! /\/\d+/.exec(document.location.pathname))
  103. return;
  104. 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; }';
  105. css += '.vp-player-layout { left: 0 !important; top: 0 !important; width: 100vw !important; height: 100vh !important; }';
  106. css += '.clip_main > *:not(.player_area-wrapper) { margin-top: 70px; }';
  107. css += '.VimeoBrand_ColorRibbon, .body_ribbon, .topnav_desktop, .topnav_mobile { position: absolute; top: 100vh; width: 100%; }';
  108. css += '.topnav_desktop { top: calc(100vh + 5px); }';
  109. GM_addStyle(css);
  110.  
  111. // autoplay
  112. function tick() {
  113. var e = document.querySelector('button.play[aria-label="Play"]');
  114. if (e) {
  115. e.click();
  116. } else {
  117. setTimeout(tick, 100);
  118. }
  119. }
  120. setTimeout(tick, 100);
  121. } else if (document.location.host.endsWith('onepieceofficial.com')) {
  122. movedTopPlayer(document.querySelector('#FUNimationVideo'));
  123. } else if (document.location.host.endsWith('eachvideo.com')) {
  124. absoluteTopPlayer('.videoWrapper', '.navbar.navbar-default.navbar-fixed-top.bs-docs-nav, .col-md-8.row-border');
  125. } else if (document.location.host == 'olympics.cbc.ca') {
  126. if (document.querySelector('figure.cbc-video--thumb-wrapper.cbc-big[style="display: none;"]')) {
  127. // Sports video
  128. movedTopPlayer(document.querySelector('.cbc-video--player-wrapper'));
  129. var css = 'body.asdf-16x9 .cbc-video--player-wrapper { width: 100vw !important; height: calc(27px + 100vh + 59px) !important; position: absolute; top: -27px; }';
  130. css += 'body.asdf-16x9 .cbc-video--player-wrapper.cbc-live-or-full-evt:hover { top: calc(-27px - 59px); }';
  131. css += 'body.asdf-16x9 { margin-top: 100vh; }';
  132. //css += 'body.asdf-fill-height .cbc-video--player-wrapper { width: calc((100vh - 60px - 59px) * 1.777777777) !important; height: 100vh !important; margin: 0 auto; }';
  133. //css += 'body.asdf-fill-width .cbc-video--player-wrapper { width: 100vw !important; height: calc(60px + 56.25vw + 59px) !important; }';
  134. GM_addStyle(css);
  135. function onResize() {
  136. var height = 59 + window.innerWidth * 0.5625 + window.innerHeight * 0.06;
  137. var ratio = window.innerWidth / window.innerHeight;
  138. console.log('onResize', height, ratio)
  139. if (1.7 <= ratio && ratio <= 1.8 ) { // 16:9 = 1.7777777...
  140. document.body.classList.remove('asdf-fill-width');
  141. document.body.classList.remove('asdf-fill-height');
  142. document.body.classList.add('asdf-16x9');
  143. } else if (height > window.innerHeight) {
  144. document.body.classList.remove('asdf-fill-width');
  145. document.body.classList.remove('asdf-16x9');
  146. document.body.classList.add('asdf-fill-height');
  147. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  148. videoBoxElement.style.width = "calc((100vh - 27px - 59px) * 1.777777777)";
  149. videoBoxElement.style.height = "100vh";
  150. videoBoxElement.style.margin = '0 auto';
  151. } else {
  152. document.body.classList.remove('asdf-fill-height');
  153. document.body.classList.remove('asdf-16x9');
  154. document.body.classList.add('asdf-fill-width');
  155. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  156. videoBoxElement.style.width = "100vw";
  157. videoBoxElement.style.height = "calc(27px + 56.25vw + 59px)";
  158. }
  159. }
  160. window.addEventListener('resize', onResize);
  161. window.addEventListener('click', function(){
  162. setTimeout(onResize, 1000);
  163. });
  164. onResize();
  165. } else {
  166. // Regular video
  167. movedTopPlayer(document.querySelector('.cbc-video'));
  168. var css = 'figure.cbc-video--thumb-wrapper.cbc-big { height: 100%; margin: 0; }';
  169. css += 'figure.cbc-video--thumb-wrapper.cbc-big picture { width: 100%; }';
  170. css += 'figure.cbc-video--thumb-wrapper.cbc-big picture img { width: 100%; }';
  171. GM_addStyle(css);
  172. function onResize() {
  173. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  174. var height = 26 + window.innerWidth * 0.5625;
  175. if (height > window.innerHeight) {
  176. videoBoxElement.style.width = "calc((100vh - 26px) * 1.77777777)";
  177. videoBoxElement.style.height = "100vh";
  178. videoBoxElement.style.margin = '0 auto';
  179. } else {
  180. videoBoxElement.style.width = "100vw";
  181. videoBoxElement.style.height = "calc(26px + 56.25vw)";
  182. }
  183. }
  184. window.addEventListener('resize', onResize);
  185. onResize();
  186. }
  187. } else if (document.location.host.endsWith('www.dailymotion.com')) {
  188. var css = '#player:not(:hover) .dmp_will-transition.dmp_is-transitioned--fadeinslide { opacity: 0; }';
  189. if (document.location.pathname.startsWith('/playlist')) {
  190. css += '#player_container { height: 100vh!important; width: 100vw!important; }';
  191. css += '#playerv5-iframe { width: 100% !important; height: 100% !important; }'; // playlists
  192. css += '.sd_header.sd_header--fixed { top: 100vh; position: absolute; }';
  193. css += '#content { margin-top: 60px; }';
  194. movedTopPlayer(document.querySelector('#player_container'));
  195. absoluteTopPlayer('#player_container');
  196.  
  197. GM_addStyle(css);
  198.  
  199. } else if (document.location.pathname.startsWith('/video')) {
  200. //css +='.main-container-player { display: none; }';
  201. //css += '#player { height: 100vh!important; width: 100vw!important; }';
  202. css += '.Player { height: 100vh!important; width: 100vw!important; }';
  203. css += '.Player { top: 0!important; left: 0!important; }';
  204. css += 'header { position: absolute!important; top: 100vh !important; }';
  205. css += 'footer { margin-top: 50px; }';
  206. css += 'div[class^="Video__placeholder___"] { margin-top: -180px; height: 100vh!important; }';
  207. GM_addStyle(css);
  208. document.addEventListener('load',function(){
  209. movedTopPlayer(document.querySelector('.Player'));
  210. });
  211. }
  212.  
  213. } else if (document.location.host.endsWith('streamable.com')) {
  214. if (document.location.pathname == '/') {
  215. return;
  216. }
  217. var css = '#player-content, #player.container .media-container, #player.container #filler, #player.container .player { max-width: 100% !important; width:100%; }';
  218. css += '#player.container #filler { padding-bottom: 100vh !important; }';
  219. css += '.player { background: #000; }';
  220. css += '.player, #player.container video { max-height: 100vh; }';
  221. css += '#player > div[style="height:15px;"] { display: none; }';
  222. css += '#player.container .topbanner { display: none; }';
  223. GM_addStyle(css);
  224. } else if (document.location.host.endsWith('globaltv.com')) {
  225. var css = '#corusVideo_PlayerContainer { width: 100vw !important; height: 100vh !important; }';
  226. css += '#corusVideo_PlayerContainer + .playlist { display: none; }';
  227. css += '#corusVideo_PlayerContainer.jwplayer.jw-stretch-uniform video { object-fit: contain !important; }';
  228. GM_addStyle(css);
  229. var videoPlayerElement = document.querySelector('#corusVideo_PlayerContainer') // corusVideo_PlayerContainer shawVideo_PlaybackArea
  230. movedTopPlayer(videoPlayerElement);
  231.  
  232. window.addEventListener('keydown', function(e){
  233. if (e.key == ' ' && e.target == document.body) {
  234. var video = document.querySelector('.jw-video')
  235. if (video) {
  236. e.preventDefault();
  237. if (video.paused) {
  238. video.play()
  239. } else {
  240. video.pause()
  241. }
  242. }
  243. }
  244. });
  245. } else if (document.location.host.endsWith('much.com')) {
  246. var css = '#TopVideoWidgetSection, #ShowNav, #MainHeader, #MastHeadTakeover { display: none; }';
  247. css += '#ShowTop #PlayerWrapper, #ShowTop .container-fluid, #ShowTop #ShowInfo, #ShowTop {';
  248. css += 'margin: 0 !important; padding: 0 !important;';
  249. css += 'width: 100vw !important; height: 100vh !important; max-width: 100vw !important; max-height: 100vh !important;';
  250. css += '}';
  251. GM_addStyle(css);
  252. } else if (document.location.host.endsWith('ctvnews.ca')) {
  253. if (window.location.pathname == '/latest') {
  254. // Redirect to latest video
  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. }
  288.  
  289. GM_addStyle('html::-webkit-scrollbar { width: 0; height: 0; } body::-webkit-scrollbar { width: 0; height: 0; }');
  290. })();