Remove Youtube Block

I'm not going to uninstall adblocker, Youtube. Never.

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

// ==UserScript==
// @name         Remove Youtube Block
// @version      1.3
// @description  I'm not going to uninstall adblocker, Youtube. Never.
// @author       Misnomer
// @match        https://www.youtube.com/*
// @license      MIT
// @namespace https://gf.qytechs.cn/users/1215479
// ==/UserScript==


(function() {
  'use strict';

  const IFRAME_ID = 'embedded-youtube-' + Math.random().toString(36).substring(7);

  function embedYouTubeIframe() {
    const isExistIframe = document.getElementById(IFRAME_ID);
    const playerDiv = document.getElementById('player');

    if (!playerDiv) return;

    if (isExistIframe) {
      clearInterval(intervalId);
      return;
    }

    const currentUrl = window.location.href;

    if (currentUrl.includes('/watch')) {
      const videoId = currentUrl.match(/v=([^&]+)/)[1];
      const embedUrl = `https://www.youtube.com/embed/${videoId}`;
      const playerWidth = playerDiv.clientWidth;
      const playerHeight = playerDiv.clientHeight;

      const iframe = document.createElement('iframe');
      iframe.id = IFRAME_ID;
      iframe.src = embedUrl;
      iframe.width = playerWidth + 'px';
      iframe.height = playerHeight + 'px';
      iframe.style.border = 'none';

      const wrapperDiv = document.createElement('div');
      wrapperDiv.style.width = playerWidth + 'px';
      wrapperDiv.style.height = playerHeight + 'px';
      wrapperDiv.appendChild(iframe);

      playerDiv.innerHTML = '';
      playerDiv.appendChild(wrapperDiv);
    }
  }

  const intervalId = setInterval(embedYouTubeIframe, 1000); //Trying to make it seemless but this might cause performance issue the lower the value.

})();

QingJ © 2025

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