Resize Video To Window Size

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

目前为 2016-08-04 提交的版本。查看 最新版本

  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 8
  7. // @include http://www.crunchyroll.com/*
  8. // @include https://docs.google.com/file/*
  9. // @include https://drive.google.com/drive/*
  10. // @include https://vimeo.com/*
  11. // @include http://onepieceofficial.com/videos.aspx*
  12. // @include http://www.onepieceofficial.com/videos.aspx*
  13. // @include http://eachvideo.com/watch*
  14. // @include http://olympics.cbc.ca/video/live/*
  15. // @grant GM_addStyle
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. var fixedOverlayPlayer = function(selector) {
  20. var css = selector + "{";
  21. css += "position: fixed;";
  22. css += "top: 0;";
  23. css += "left: 0;";
  24. css += "right: 0;";
  25. css += "bottom: 0;";
  26. css += "}";
  27. GM_addStyle(css);
  28. };
  29. var absoluteTopPlayer = function(selector, staticSelectors) {
  30. var css = selector + "{";
  31. css += "position: absolute;";
  32. css += "top: 0;";
  33. css += "left: 0;";
  34. css += "width: 100vw;";
  35. css += "height: 100vh;";
  36. css += "padding: 0;";
  37. css += "margin: 0;";
  38. css += "}";
  39. css += "body {";
  40. css += "margin-top: 100vh;";
  41. css += "margin-top: 100vh;";
  42. css += "padding-top: 0;";
  43. css += "}";
  44. if (staticSelectors) {
  45. css += staticSelectors + "{";
  46. css += "position: static";
  47. css += "}";
  48. }
  49. GM_addStyle(css);
  50. };
  51. var movedTopPlayer = function(videoBoxElement) {
  52. document.body.insertBefore(videoBoxElement, document.body.firstChild);
  53. videoBoxElement.style.width = '100%';
  54. videoBoxElement.style.height = '100%';
  55. videoBoxElement.style.backgroundColor = '#000';
  56. };
  57.  
  58. var urlMatch = function(regexStr) {
  59. regexStr = regexStr.replace(/\//g, '\\/'); // Auto escape forward slashes to make url regexes more legible.
  60. var regex = new RegExp(regexStr);
  61. return regex.exec(window.location.href);
  62. };
  63.  
  64. if (window.location.href.match(/^http:\/\/www\.crunchyroll\.(com|ca)\/.+\/.+-\d+\/?/)) {
  65. var videoBoxElement = document.getElementById('showmedia_video_box') || document.getElementById('showmedia_video_box_wide');
  66. if (!videoBoxElement) return;
  67. movedTopPlayer(videoBoxElement);
  68. var css = 'html, body { width: 100%; height: 100%; }';
  69. css += '#showmedia_video_box, #showmedia_video_box_wide, #showmedia_video_player { width: 100%; height: calc(100vh + 32px) !important; }';
  70. GM_addStyle(css);
  71. } else if (document.location.href.startsWith('https://docs.google.com/file/')) {
  72. fixedOverlayPlayer('#drive-viewer-video-player-object-0');
  73. } else if (document.location.href.startsWith('https://drive.google.com/drive/')) {
  74. fixedOverlayPlayer('#drive-viewer-video-player-object-0');
  75. } else if (document.location.href.startsWith('https://vimeo.com/')) {
  76. var css = '.player_area-wrapper, .player_area, .player_container, .player, .video-wrapper, .video, .video * { width: 100vw !important; height: 100vh !important; max-height: 100vh !important; }';
  77. css += '.clip_main > *:not(.player_area-wrapper) { margin-top: 70px; }';
  78. css += '.body_ribbon, .topnav_desktop, .topnav_mobile { position: absolute; top: 100vh; width: 100%; }';
  79. css += '.topnav_desktop { top: calc(100vh + 5px); }';
  80. GM_addStyle(css);
  81. // autoplay
  82. function tick() {
  83. var e = document.querySelector('button.play[aria-label="Play"]');
  84. if (e) {
  85. e.click();
  86. } else {
  87. setTimeout(tick, 100);
  88. }
  89. }
  90. setTimeout(tick, 100);
  91. } else if (document.location.host.endsWith('onepieceofficial.com')) {
  92. movedTopPlayer(document.querySelector('#FUNimationVideo'));
  93. } else if (document.location.host.endsWith('eachvideo.com')) {
  94. absoluteTopPlayer('.videoWrapper', '.navbar.navbar-default.navbar-fixed-top.bs-docs-nav, .col-md-8.row-border');
  95. } else if (document.location.host == 'olympics.cbc.ca') {
  96. movedTopPlayer(document.querySelector('.cbc-video--player-wrapper'));
  97. function onResize() {
  98. var videoBoxElement = document.querySelector('.cbc-video--player-wrapper');
  99. var height = 59 + window.innerWidth * 0.5625 + window.innerHeight * 0.06;
  100. if (height > window.innerHeight) {
  101. videoBoxElement.style.width = "calc((94vh - 59px) * 1.777777777)";
  102. videoBoxElement.style.height = "100vh";
  103. videoBoxElement.style.margin = '0 auto';
  104. } else {
  105. videoBoxElement.style.width = "100vw";
  106. videoBoxElement.style.height = "calc(59px + 56.25vw + 6vh)";
  107. }
  108. }
  109. window.addEventListener('resize', onResize);
  110. onResize();
  111. }
  112. })();