Resize Video To Window Size

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

目前为 2017-05-23 提交的版本。查看 最新版本

  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 16
  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/video/*
  18. // @grant GM_addStyle
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. var fixedOverlayPlayer = function(selector) {
  23. var css = selector + "{";
  24. css += "position: fixed;";
  25. css += "top: 0;";
  26. css += "left: 0;";
  27. css += "right: 0;";
  28. css += "bottom: 0;";
  29. css += "}";
  30. GM_addStyle(css);
  31. };
  32. var absoluteTopPlayer = function(selector, staticSelectors) {
  33. var css = selector + "{";
  34. css += "position: absolute;";
  35. css += "top: 0;";
  36. css += "left: 0;";
  37. css += "width: 100vw;";
  38. css += "height: 100vh;";
  39. css += "padding: 0;";
  40. css += "margin: 0;";
  41. css += "}";
  42. css += "body {";
  43. css += "margin-top: 100vh;";
  44. css += "margin-top: 100vh;";
  45. css += "padding-top: 0;";
  46. css += "}";
  47. if (staticSelectors) {
  48. css += staticSelectors + "{";
  49. css += "position: static";
  50. css += "}";
  51. }
  52. GM_addStyle(css);
  53. };
  54. var movedTopPlayer = function(videoBoxElement) {
  55. document.body.insertBefore(videoBoxElement, document.body.firstChild);
  56. videoBoxElement.style.width = '100%';
  57. videoBoxElement.style.height = '100%';
  58. videoBoxElement.style.backgroundColor = '#000';
  59. };
  60.  
  61. var urlMatch = function(regexStr) {
  62. regexStr = regexStr.replace(/\//g, '\\/'); // Auto escape forward slashes to make url regexes more legible.
  63. var regex = new RegExp(regexStr);
  64. return regex.exec(window.location.href);
  65. };
  66.  
  67. if (window.location.href.match(/^http:\/\/www\.crunchyroll\.(com|ca)\/.+\/.+-\d+\/?/)) {
  68. var videoBoxElement = document.getElementById('showmedia_video_box') || document.getElementById('showmedia_video_box_wide');
  69. if (!videoBoxElement) return;
  70. movedTopPlayer(videoBoxElement);
  71. var css = 'html, body { width: 100%; height: 100%; }';
  72. css += '#showmedia_video_box, #showmedia_video_box_wide, #showmedia_video_player { width: 100%; height: calc(100vh + 32px) !important; }';
  73. GM_addStyle(css);
  74. } else if (document.location.href.startsWith('https://docs.google.com/file/')) {
  75. fixedOverlayPlayer('#drive-viewer-video-player-object-0');
  76. } else if (document.location.href.startsWith('https://drive.google.com/')) {
  77. fixedOverlayPlayer('.drive-viewer-video-player');
  78. var css = '.drive-viewer-toolstrip { opacity: 0 !important; }';
  79. css += '.drive-viewer-toolstrip:hover { opacity: 1 !important; }';
  80. GM_addStyle(css);
  81. } else if (document.location.href.startsWith('https://vimeo.com/')) {
  82. var css = '.player_area-wrapper, .player_area, .player_container, .player, .video-wrapper, .video, .video * { width: 100vw !important; height: 100vh !important; max-height: 100vh !important; }';
  83. css += '.clip_main > *:not(.player_area-wrapper) { margin-top: 70px; }';
  84. css += '.VimeoBrand_ColorRibbon, .body_ribbon, .topnav_desktop, .topnav_mobile { position: absolute; top: 100vh; width: 100%; }';
  85. css += '.topnav_desktop { top: calc(100vh + 5px); }';
  86. GM_addStyle(css);
  87.  
  88. // autoplay
  89. function tick() {
  90. var e = document.querySelector('button.play[aria-label="Play"]');
  91. if (e) {
  92. e.click();
  93. } else {
  94. setTimeout(tick, 100);
  95. }
  96. }
  97. setTimeout(tick, 100);
  98. } else if (document.location.host.endsWith('onepieceofficial.com')) {
  99. movedTopPlayer(document.querySelector('#FUNimationVideo'));
  100. } else if (document.location.host.endsWith('eachvideo.com')) {
  101. absoluteTopPlayer('.videoWrapper', '.navbar.navbar-default.navbar-fixed-top.bs-docs-nav, .col-md-8.row-border');
  102. } else if (document.location.host == 'olympics.cbc.ca') {
  103. if (document.querySelector('figure.cbc-video--thumb-wrapper.cbc-big[style="display: none;"]')) {
  104. // Sports video
  105. movedTopPlayer(document.querySelector('.cbc-video--player-wrapper'));
  106. var css = 'body.asdf-16x9 .cbc-video--player-wrapper { width: 100vw !important; height: calc(27px + 100vh + 59px) !important; position: absolute; top: -27px; }';
  107. css += 'body.asdf-16x9 .cbc-video--player-wrapper.cbc-live-or-full-evt:hover { top: calc(-27px - 59px); }';
  108. css += 'body.asdf-16x9 { margin-top: 100vh; }';
  109. //css += 'body.asdf-fill-height .cbc-video--player-wrapper { width: calc((100vh - 60px - 59px) * 1.777777777) !important; height: 100vh !important; margin: 0 auto; }';
  110. //css += 'body.asdf-fill-width .cbc-video--player-wrapper { width: 100vw !important; height: calc(60px + 56.25vw + 59px) !important; }';
  111. GM_addStyle(css);
  112. function onResize() {
  113. var height = 59 + window.innerWidth * 0.5625 + window.innerHeight * 0.06;
  114. var ratio = window.innerWidth / window.innerHeight;
  115. console.log('onResize', height, ratio)
  116. if (1.7 <= ratio && ratio <= 1.8 ) { // 16:9 = 1.7777777...
  117. document.body.classList.remove('asdf-fill-width');
  118. document.body.classList.remove('asdf-fill-height');
  119. document.body.classList.add('asdf-16x9');
  120. } else if (height > window.innerHeight) {
  121. document.body.classList.remove('asdf-fill-width');
  122. document.body.classList.remove('asdf-16x9');
  123. document.body.classList.add('asdf-fill-height');
  124. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  125. videoBoxElement.style.width = "calc((100vh - 27px - 59px) * 1.777777777)";
  126. videoBoxElement.style.height = "100vh";
  127. videoBoxElement.style.margin = '0 auto';
  128. } else {
  129. document.body.classList.remove('asdf-fill-height');
  130. document.body.classList.remove('asdf-16x9');
  131. document.body.classList.add('asdf-fill-width');
  132. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  133. videoBoxElement.style.width = "100vw";
  134. videoBoxElement.style.height = "calc(27px + 56.25vw + 59px)";
  135. }
  136. }
  137. window.addEventListener('resize', onResize);
  138. window.addEventListener('click', function(){
  139. setTimeout(onResize, 1000);
  140. });
  141. onResize();
  142. } else {
  143. // Regular video
  144. movedTopPlayer(document.querySelector('.cbc-video'));
  145. var css = 'figure.cbc-video--thumb-wrapper.cbc-big { height: 100%; margin: 0; }';
  146. css += 'figure.cbc-video--thumb-wrapper.cbc-big picture { width: 100%; }';
  147. css += 'figure.cbc-video--thumb-wrapper.cbc-big picture img { width: 100%; }';
  148. GM_addStyle(css);
  149. function onResize() {
  150. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  151. var height = 26 + window.innerWidth * 0.5625;
  152. if (height > window.innerHeight) {
  153. videoBoxElement.style.width = "calc((100vh - 26px) * 1.77777777)";
  154. videoBoxElement.style.height = "100vh";
  155. videoBoxElement.style.margin = '0 auto';
  156. } else {
  157. videoBoxElement.style.width = "100vw";
  158. videoBoxElement.style.height = "calc(26px + 56.25vw)";
  159. }
  160. }
  161. window.addEventListener('resize', onResize);
  162. onResize();
  163. }
  164. } else if (document.location.host.endsWith('www.dailymotion.com')) {
  165. movedTopPlayer(document.querySelector('#player'));
  166. var css = '#player { height: 100vh!important; width: 100vw!important; }';
  167. GM_addStyle(css);
  168. }
  169. GM_addStyle('html::-webkit-scrollbar { width: 0; height: 0; } body::-webkit-scrollbar { width: 0; height: 0; }');
  170. })();