Disable JavaScript Alert Boxes

Blocks annoying page-load alert boxes during the first 5 seconds

目前為 2026-05-08 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Disable JavaScript Alert Boxes
// @namespace    RGlzYWJsZSBqYXZhc2NyaXB0IGFsZXJ0IGJveGVz
// @version      1.1
// @description  Blocks annoying page-load alert boxes during the first 5 seconds
// @author       smed79
// @license      GPLv3
// @icon         https://i25.servimg.com/u/f25/11/94/21/24/x10.jpg
// @include      *://*/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Inject directly into the Main World so we actually intercept the page's alerts
    const payload = `(function() {
        try {
            // Keep a private, hidden reference to the original alert
            const originalAlert = window.alert;

            // Override the page's alert function to do absolutely nothing
            window.alert = function() {};

            // Restore the original alert after 5 seconds
            setTimeout(() => {
                window.alert = originalAlert;
            }, 5000);
        } catch (e) {}
    })();`;

    // Create the script tag
    const script = document.createElement('script');
    script.textContent = payload;

    // Inject instantly at document-start before the website's spam scripts run
    if (document.documentElement) {
        document.documentElement.appendChild(script);
        script.remove(); // Clean up the tag so the website doesn't know we are there
    }
})();