Allow full screen on embedded Youtube

ViolentMonkey script

  1. // ==UserScript==
  2. // @name Allow full screen on embedded Youtube
  3. // @namespace mwisnicki@gmail.com
  4. // @homepage https://github.com/mwisnicki/userscripts/blob/master/allowfullscreen-youtube-embed.user.js
  5. // @match *://*/*
  6. // @grant none
  7. // @version 6
  8. // @author mwisnicki@gmail.com
  9. // @description ViolentMonkey script
  10. // ==/UserScript==
  11.  
  12. const URLs = [
  13. "https://www.youtube.com/embed/",
  14. "https://youtube.com/embed/",
  15. "https://www.youtube-nocookie.com/embed/"
  16. ];
  17.  
  18. const SELECTOR = URLs.map(url => `iframe[src^="${url}"]:not([allowfullscreen])`).join(', ');
  19.  
  20. function reloadIframe(iframe) {
  21. iframe.src = iframe.src;
  22. }
  23.  
  24. function fixVideos() {
  25. const iframes = document.body.querySelectorAll(SELECTOR)
  26. for (const iframe of iframes) {
  27. iframe.setAttribute("allowfullscreen","");
  28. reloadIframe(iframe);
  29. console.log("Forced Youtube allowfullscreen on %o", iframe);
  30. }
  31. }
  32.  
  33. fixVideos();
  34.  
  35. new MutationObserver(fixVideos).observe(document, { childList: true, subtree: true });

QingJ © 2025

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