Resize Video To Window Size

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

当前为 2017-02-05 提交的版本,查看 最新版本

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