阻止弹窗

阻止网页上的弹窗,同时保留正常的按钮功能

目前為 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.2

// @description  阻止网页上的弹窗,同时保留正常的按钮功能

// @author       You

// @license MIT

// @run-at       document-start

// @match        https://*/*

// @grant        none

// ==/UserScript==

(function() {
    // 阻止所有弹窗
    window.alert = function() {
        console.log("弹窗被阻止: ", arguments);
    };

    window.confirm = function() {
        console.log("确认弹窗被阻止: ", arguments);
        return true; // 默认返回true
    };

    window.prompt = function() {
        console.log("提示弹窗被阻止: ", arguments);
        return null; // 默认返回null
    };

    window.open = function() {
        console.log("弹窗被阻止: ", arguments);
        return null;
    };

    // 阻止通过addEventListener添加的事件
    document.addEventListener('DOMContentLoaded', function() {
        // 阻止特定类型的弹窗行为
        document.addEventListener('click', function(event) {
            const target = event.target;
            if (target.tagName === 'A' && target.target === '_blank') {
                event.preventDefault();
                console.log("阻止了新窗口打开: ", target.href);
            }
        }, true);

        // 阻止表单提交时的弹窗
        document.addEventListener('submit', function(event) {
            event.preventDefault();
            console.log("阻止了表单提交: ", event.target);
        }, true);
    });

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