Remove Youtube Block

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

当前为 2023-11-11 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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://greasyfork.org/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.

})();