阻止弹窗

good

目前為 2025-03-19 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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("弹窗屏蔽脚本已启用");

})();