Greasy Fork 还支持 简体中文。

Block Sub-Links

Removes all links and scripts with predefined domains on all sites.

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/478532/1272142/Block%20Sub-Links.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Block Sub-Links
// @description  Removes all links and scripts with predefined domains on all sites.
// @author       HIDDEN-lo
// @version      1.0
// @match        *://*/*
// @match        *://akuma.moe/*
// @license MIT
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    var blockedLinks = [
        'enquirysavagely.com',
        'janzuyejxmm.com',
        'fzkqshbim.com',
        'bootstrap.js',
        '2734478852/a.js',
        'googletagmanager.com',
        'jads.co',
        'hammer.js',
        'jquery.typeahead.min.js',
        'app.js',
        'reader.js',
        'betteradsystem.com',
        'window.adsbyjuicy',
        'betteradsystem.com',
        'adsco.re',
        'trackwilltrk.com',
        'adsbyjuicy',
        'onclickalgo.com'
    ];

    var blockedScriptContent = [
        'f128e7d4965281fb9bfdd3dbeb9285be',
        'betteradsystem.com',
        'adsbyjuicy',
        'gtag'
    ];

    function removeElement(element) {
        if (element && element.parentNode) {
            element.parentNode.removeChild(element);
        }
    };

    function checkBlocked() {
        // Checks each of the blockedLinks and sees if one matches the current page. If so, close the page.
        console.log('Checking for blocked links...');
        blockedLinks.forEach(function(link) {
            if (window.location.href.indexOf(link) > -1) {
                window.close();
                console.log('Removed redirect: ' + window.location.href);
            }
        });
    };

    function checkAndRemoveLinks() {
        console.log('Checking for blocked links...');
        var links = document.querySelectorAll('a');
        for (var i = 0; i < links.length; i++) {
            for (var j = 0; j < blockedLinks.length; j++) {
                if (links[i].href.includes(blockedLinks[j])) {
                    removeElement(links[i]);
                    console.log("Removed blocked link: " + links[i].href);
                }
            }
        }
    };

    function checkAndRemoveRedirects() {
        console.log('Checking for blocked redirects...');
        var metaRefreshTags = document.querySelectorAll('meta[http-equiv="refresh"]');
        for (var i = 0; i < metaRefreshTags.length; i++) {
            var content = metaRefreshTags[i].getAttribute('content');
            for (var j = 0; j < blockedLinks.length; j++) {
                if (content.includes(blockedLinks[j])) {
                    removeElement(metaRefreshTags[i]);
                    console.log("Removed blocked redirect: " + content);
                }
            }
        }
    };

    function checkAndRemoveScripts() {
        console.log('Checking for blocked scripts...');
        var scripts = document.querySelectorAll('script');
        for (var i = 0; i < scripts.length; i++) {
            var scriptSrc = scripts[i].getAttribute('src');
            var scriptContent = scripts[i].textContent || scripts[i].innerText;
    
            // Check the script's content and src attribute for blocked links and specific script content
            for (var j = 0; j < blockedLinks.length; j++) {
                if (scriptSrc && scriptSrc.includes(blockedLinks[j])) {
                    removeElement(scripts[i]);
                    console.log("Removed blocked script (by src): " + scriptSrc);
                } else if (scriptContent.includes(blockedScriptContent[j])) {
                    removeElement(scripts[i]);
                    console.log("Removed blocked script (by content): " + scriptContent);
                }
            }
        }
    };

    function checkAndRemoveIframes() {
        console.log('Checking for blocked iframes...');
        var iframes = document.querySelectorAll('iframe');
        for (var i = 0; i < iframes.length; i++) {
            var iframeSrc = iframes[i].getAttribute('src');
            for (var j = 0; j < blockedLinks.length; j++) {
                if (iframeSrc && iframeSrc.includes(blockedLinks[j])) {
                    removeElement(iframes[i]);
                    console.log("Removed blocked iframe: " + iframeSrc);
                }
            }
        }
    };



    // Check and remove links, redirects, and scripts on page load
    checkAll();
    function checkAll() {
        checkBlocked();
        checkAndRemoveLinks();
        checkAndRemoveRedirects();
        checkAndRemoveScripts();
        checkAndRemoveIframes();
    };

    // Timer to slow loops, as ads dont appear as ofter after a set time.
    var interval = 1000;

    function timerCounter() {
        if (interval <= 6000) {
            interval = interval + 200;
        }
    };
    
    function executeWithDynamicInterval() {
        timerCounter();
        checkAll();
        console.log("Interval: " + interval);
    
        setTimeout(executeWithDynamicInterval, interval);
    };

    executeWithDynamicInterval();
    

    document.addEventListener("DOMContentLoaded", function () {
        console.log('DOM loaded! Checking...');
        checkAll();
    });

    // Listen for DOM changes and check/remove links, redirects, and scripts again
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            console.log('Mutation detected! Removing...');
            checkAll();
        });
    });

    // Use a MutationObserver to detect dynamic script additions
    var scriptObserver = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.addedNodes) {
                console.log('Script Mutation Found! Checking...');
                for (var i = 0; i < mutation.addedNodes.length; i++) {
                    var addedNode = mutation.addedNodes[i];
                    if (addedNode.tagName === 'SCRIPT') {
                        console.log('Mutation detected! Removing...');
                        checkAll();
                    }
                }
            }
        });
    });

    observer.observe(document.body, { subtree: true, childList: true });
    scriptObserver.observe(document, { childList: true, subtree: true });

})();