Allow full screen on embedded Youtube

3/8/2020, 10:42:28 PM

当前为 2020-03-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Allow full screen on embedded Youtube
  3. // @namespace mwisnicki@gmail.com
  4. // @match *://*/*
  5. // @grant none
  6. // @version 1.0
  7. // @author mwisnicki@gmail.com
  8. // @description 3/8/2020, 10:42:28 PM
  9. // ==/UserScript==
  10.  
  11. function fixVideos() {
  12. const iframes = document.body.querySelectorAll('iframe[src^="https://www.youtube.com/embed/"]:not([allowfullscreen])')
  13. for (const iframe of iframes) {
  14. iframe.setAttribute("allowfullscreen","");
  15. // force reload
  16. // TODO maybe there's a way to refresh state without reload?
  17. const span = document.createElement("span");
  18. iframe.replaceWith(span);
  19. span.replaceWith(iframe);
  20. console.log("Forced Youtube allowfullscreen on %o", iframe);
  21. }
  22. }
  23.  
  24. fixVideos();
  25.  
  26. new MutationObserver(fixVideos).observe(document, { childList: true, subtree: true });