Auto-Close oundhertobeconsist killer

Ferme automatiquement tout onglet qui charge oundhertobeconsist.org

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Auto-Close oundhertobeconsist killer
// @namespace    tab-killer
// @version      4.0
// @description  Ferme automatiquement tout onglet qui charge oundhertobeconsist.org
// @match        *://*/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const BLOCK = "oundhertobeconsist.org";

    // Fonction pour tuer la page
    function killPage() {
        // Tente de fermer directement (fonctionne si redirection popup)
        window.close();

        // Si pas fermé → tente retour arrière
        history.back();

        // Si impossible → force le blanc puis ferme
        setTimeout(() => {
            document.documentElement.innerHTML = "";
            location.replace("about:blank");
            setTimeout(() => window.close(), 10);
        }, 10);
    }

    // Si la page actuelle est le domaine bloqué → KILL
    if (location.hostname.includes(BLOCK)) {
        killPage();
        return;
    }

    // Bloque toutes redirections vers ce domaine
    const hardBlock = url => url && url.includes(BLOCK);

    const origAssign = window.location.assign;
    window.location.assign = function(url) {
        if (hardBlock(url)) return killPage();
        return origAssign.call(window.location, url);
    };

    const origReplace = window.location.replace;
    window.location.replace = function(url) {
        if (hardBlock(url)) return killPage();
        return origReplace.call(window.location, url);
    };

    Object.defineProperty(window.location, "href", {
        set(url) {
            if (hardBlock(url)) return killPage();
            return origAssign.call(window.location, url);
        }
    });

    // Bloque les clics sur les liens
    document.addEventListener("click", e => {
        const a = e.target.closest("a");
        if (!a) return;
        if (hardBlock(a.href)) {
            e.preventDefault();
            e.stopImmediatePropagation();
            killPage();
        }
    }, true);

})();