YouTube Popup Window

Enhances YouTube with a popup window feature.

目前为 2023-06-15 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Popup Window
  3. // @name:zh-TW YouTube Popup Window
  4. // @name:ja YouTube Popup Window
  5. // @namespace http://tampermonkey.net/
  6. // @version 0.1.3
  7. // @description Enhances YouTube with a popup window feature.
  8. // @description:zh-TW 透過彈出視窗功能增強YouTube。
  9. // @description:ja YouTubeをポップアップウィンドウ機能で強化します。
  10. // @author CY Fung
  11. // @license MIT
  12. // @match https://www.youtube.com/*
  13. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  14. // @grant GM_registerMenuCommand
  15. // @allFrames
  16. // ==/UserScript==
  17.  
  18. (function $$() {
  19. 'use strict';
  20. const winName = 'x4tGg';
  21. const styleName = 'rCbM3';
  22.  
  23. const getWindowType = () => {
  24.  
  25. let isPopupWindow = false;
  26. try {
  27. if (window.name === winName && window === top) {
  28. isPopupWindow = true;
  29. }
  30. } catch (e) { }
  31. if (isPopupWindow) return 1;
  32.  
  33. let isIframeInsidePopupWindow = false;
  34. try {
  35. if (window !== top && top.name === winName) {
  36. isIframeInsidePopupWindow = true;
  37. }
  38. } catch (e) { }
  39. if (isIframeInsidePopupWindow) return 2;
  40.  
  41. return 0;
  42. };
  43.  
  44. const windowType = getWindowType();
  45.  
  46.  
  47. if (windowType === 1) {
  48. // popup window
  49.  
  50. if (!document.head) return requestAnimationFrame($$);
  51.  
  52. let style = document.createElement('style');
  53. style.id = styleName;
  54.  
  55. style.textContent = `
  56. *[class][id].style-scope.ytd-watch-flexy {
  57. min-width: unset !important;
  58. min-height: unset !important;
  59. }
  60. `
  61.  
  62. document.head.appendChild(style);
  63.  
  64. } else if (windowType === 2) {
  65. // iframe in popup window
  66.  
  67.  
  68. if (!document.head) return requestAnimationFrame($$);
  69.  
  70. let style = document.createElement('style');
  71. style.id = styleName;
  72.  
  73. style.textContent = `
  74. * {
  75. min-width: unset !important;
  76. min-height: unset !important;
  77. }
  78. `
  79.  
  80. document.head.appendChild(style);
  81.  
  82.  
  83. } else if (window === top) {
  84. // normal window
  85.  
  86. function openPopup() {
  87. var currentUrl = window.location.href;
  88. let rect = document.querySelector('ytd-app').getBoundingClientRect();
  89. let w = rect.width;
  90. let h = rect.height;
  91. var popupOptions = `toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=${w},height=${h}`;
  92.  
  93.  
  94. let video = document.querySelector('#player video');
  95.  
  96. if (video) {
  97. video.pause();
  98. }
  99. let win = window.open(currentUrl, '', popupOptions);
  100. win.name = winName;
  101.  
  102.  
  103. document.querySelector('#x4tGg').remove();
  104.  
  105. }
  106.  
  107.  
  108.  
  109. GM_registerMenuCommand('Open Popup Window', function () {
  110.  
  111. if (document.querySelector('#x4tGg')) return;
  112.  
  113. let div = document.body.appendChild(document.createElement('div'));
  114. div.id = 'x4tGg';
  115. div.textContent = 'Click to Open Popup'
  116.  
  117. Object.assign(div.style, {
  118. 'position': 'fixed',
  119. 'left': '50vw',
  120. 'top': '50vh',
  121. 'padding': '28px',
  122. 'backgroundColor': 'rgb(56, 94, 131)',
  123. 'color': '#fff',
  124. 'borderRadius': '16px',
  125. 'fontSize': '18pt',
  126. 'zIndex': '9999',
  127. 'transform': 'translate(-50%, -50%)'
  128. })
  129.  
  130. div.onclick = function () {
  131.  
  132. openPopup();
  133. }
  134.  
  135. });
  136.  
  137. }
  138. // Your code here...
  139. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址