Only Illegal Aliens

Replaces leftist terminology with "illegal alien" on all websites

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Only Illegal Aliens
// @namespace    http://tampermonkey.net/
// @version      1.2.2
// @description  Replaces leftist terminology with "illegal alien" on all websites
// @author       adamlproductions
// @match        *://*
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const phrases = [
        'illegal migrant',
        'undocumented immigrant',
        'illegal immigrant',
        'undocumented person',
        'unauthorized migrant',
        'non-citizen',
        'noncitizen',
        'unauthorized immigrant',
        'migrant',
        'undocumented'
    ];

    function escapeRegex(string) {
        return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
    }

    const regex = new RegExp(
        phrases.map(phrase => `\\b${escapeRegex(phrase)}(s?)\\b`).join('|'),
        'gi'
    );

    function isEditableElement(node) {
        while (node) {
            if (node.nodeType === Node.ELEMENT_NODE) {
                const tagName = node.tagName.toLowerCase();
                if (tagName === 'input' || tagName === 'textarea') {
                    return true;
                }
                if (node.hasAttribute('contenteditable') && node.getAttribute('contenteditable') !== 'false') {
                    return true;
                }
            }
            node = node.parentNode;
        }
        return false;
    }

    function replaceText(node) {
        if (node.nodeType === Node.TEXT_NODE) {
            if (!isEditableElement(node)) {
                let text = node.textContent;
                text = text.replace(regex, (match, ...groups) => {
                    const pluralIndicator = match[match.length - 1];
                    console.log("pluralIndicator:", pluralIndicator);
                    return pluralIndicator === 's' ? 'illegal aliens*' : 'illegal alien*';
                });
                node.textContent = text;
            }
        } else if (node.nodeType === Node.ELEMENT_NODE) {
            const tagName = node.tagName.toLowerCase();
            if (tagName !== 'script' && tagName !== 'style' && tagName !== 'input' && tagName !== 'textarea' && !node.hasAttribute('contenteditable')) {
                for (let child of node.childNodes) {
                    replaceText(child);
                }
            }
        }
    }

    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            mutation.addedNodes.forEach((node) => {
                replaceText(node);
            });
        });
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    replaceText(document.body);
})();