阻止js脚本运行

这个脚本用于阻止指定的 JavaScript 文件在特定网站上运行。

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         阻止js脚本运行
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  这个脚本用于阻止指定的 JavaScript 文件在特定网站上运行。
// @author       veip007
// @match        *://*.sexinsex.net/*
// @match        *://*.91porn.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // 要阻止的JS文件列表
    const blockedScripts = ['indexonly.js', 'myjavascriptajax.js', 'adblock.js'];

    // 拦截并阻止特定的JS文件
    const originalOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url) {
        for (let script of blockedScripts) {
            if (url.includes(script)) {
                console.log('Blocked:', url);
                return;
            }
        }
        originalOpen.apply(this, arguments);
    };

    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            mutation.addedNodes.forEach((node) => {
                if (node.tagName === 'SCRIPT') {
                    blockedScripts.forEach((script) => {
                        if (node.src.includes(script)) {
                            node.parentNode.removeChild(node);
                            console.log('Blocked:', node.src);
                        }
                    });
                }
            });
        });
    });

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