Greasy Fork

来自缓存

Greasy Fork is available in English.

Youtube AdBlock ban bypass

Fix the "Ad blockers violate YouTube's Terms of Service" Error

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    // ==UserScript==
    // @name         Youtube AdBlock ban bypass
    // @namespace    http://tampermonkey.net/
    // @version      1.1
    // @description  Fix the "Ad blockers violate YouTube's Terms of Service" Error
    // @author       Obelous
    // @match        https://www.youtube.com/*
    // @match        https://www.youtube-nocookie.com/*
    // @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
    // @grant        none
    // @license      MIT
    // ==/UserScript==

    let currentPageUrl = window.location.href;

    window.addEventListener('beforeunload', function () {
        currentPageUrl = window.location.href;
    });

    // this is necessary because the script isnt reloaded whenever the user goes to a new video
    document.addEventListener('yt-navigate-finish', function () {
        const newUrl = window.location.href;
        // if player is present and there is a change in url then change the url to the new one
        if (document.getElementById('youtube-iframe') && newUrl !== currentPageUrl) {
            const url = "https://www.youtube-nocookie.com/embed/" + splitUrl(newUrl) + "?autoplay=1";
            const player = document.getElementById("youtube-iframe");
            player.setAttribute('src', url);
        }
        // else if the player is not present create one
        else if(document.getElementById('youtube-iframe') == null){
            setTimeout(run, 1000);
        }
        // if all else fails reload the page
        else{
            location.reload();
        }
    });

    // returns the video ID
    function splitUrl(str) {
        return str.split('=')[1];
    }

    // main function
    function run() {
        console.log("Loaded");
        // remove block screen
        const block = document.querySelector('.yt-playability-error-supported-renderers');
        if(!block) return;
        block.parentNode.removeChild(block);
        // get the url for the iframe
        const url = "https://www.youtube-nocookie.com/embed/" + splitUrl(window.location.href) + "?autoplay=1";
        // get the mount point for the iframe
        const oldplayer = document.getElementById("error-screen");
        // create the iframe
        const player = document.createElement('iframe');
        player.setAttribute('src', url);
        player.setAttribute('allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share');
        player.setAttribute('frameborder', '0');
        player.setAttribute('allowfullscreen', true);
        player.style = "height:100%;width:100%;border-radius:12px;";
        player.id = "youtube-iframe";
        // append the elements to the DOM
        oldplayer.appendChild(player);
        console.log('Finished');
    }

    // Execute the code
    (function() {
        'use strict';
        //|             |||
        // RUN DELAY    VVV
        setTimeout(run, 1000);
    })();