Allow full screen on embedded Youtube

ViolentMonkey script

当前为 2021-03-15 提交的版本,查看 最新版本

// ==UserScript==
// @name        Allow full screen on embedded Youtube
// @namespace   [email protected]
// @website     https://github.com/mwisnicki/userscripts/blob/master/allowfullscreen-youtube-embed.user.js
// @match       *://*/*
// @grant       none
// @version     2
// @author      [email protected]
// @description ViolentMonkey script
// ==/UserScript==

const SELECTOR = [
  `iframe[src^="https://www.youtube.com/embed/"]:not([allowfullscreen])`,
  `iframe[src^="https://youtube.com/embed/"]:not([allowfullscreen])`
].join(', ');

function fixVideos() {
  const iframes = document.body.querySelectorAll(SELECTOR)
  for (const iframe of iframes) {
    iframe.setAttribute("allowfullscreen","");
    // force reload
    // TODO maybe there's a way to refresh state without reload?
    const span = document.createElement("span");
    iframe.replaceWith(span);
    span.replaceWith(iframe);
    console.log("Forced Youtube allowfullscreen on %o", iframe);
  }
}

fixVideos();

new MutationObserver(fixVideos).observe(document, { childList: true, subtree: true });

QingJ © 2025

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