阻止弹窗

good

当前为 2025-03-19 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==

// @name         阻止弹窗

// @namespace    https://viayoo.com/

// @version      0.1

// @description good

// @author       You

// @run-at       document-start

// @match        https://*/*

// @grant        none

// @license     pp

// ==/UserScript==

// 阻止所有弹窗

(function() {

    // 覆盖window.alert方法

    window.alert = function() {

        console.log("弹窗被阻止: ", arguments);

    };

    // 覆盖window.confirm方法

    window.confirm = function() {

        console.log("确认弹窗被阻止: ", arguments);

        return true; // 默认返回true

    };

    // 覆盖window.prompt方法

    window.prompt = function() {

        console.log("提示弹窗被阻止: ", arguments);

        return null; // 默认返回null

    };

    // 阻止通过window.open打开的弹窗

    window.open = function() {

        console.log("弹窗被阻止: ", arguments);

        return null;

    };

    // 阻止通过addEventListener添加的事件

    document.addEventListener('DOMContentLoaded', function() {

        var elements = document.querySelectorAll('*');

        elements.forEach(function(element) {

            element.onclick = null; // 移除点击事件

            element.onload = null; // 移除加载事件

        });

    });

    console.log("弹窗屏蔽脚本已启用");

})();