Discord SetName Replacer

Replace words in Discord messages (e.g., "ah" -> "ASC")

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name         Discord SetName Replacer
// @namespace    http://tampermonkey.net/
// @version      0.3.1
// @description  Replace words in Discord messages (e.g., "ah" -> "ASC")
// @match        https://discord.com/*
// @match        https://*.discord.com/*
// @grant        none
// @license      MIT
// ==/UserScript==
(function() {
    'use strict';

    // Configuration - in must be lowercase
    const translations = [
        {in: ["cr"], out: "CRI"},
        {in: ["po"], out: "POR"},
        {in: ["ah"], out: "ASC"},
        {in: ["pf", "phf"], out: "PFL"},
        {in: ["wf"], out: "WHT"},
        {in: ["bbl"], out: "BLK"},
        {in: ["dr"], out: "DRI"},
        {in: ["jt"], out: "JTG"},
        {in: ["ss"], out: "SSP"},
        {in: ["sc"], out: "SCR"},
        {in: ["sf"], out: "SFA"},
        {in: ["tm"], out: "TWM"},
        {in: ["tf"], out: "TEF"},
        {in: ["pf"], out: "PAF"},
        {in: ["pr"], out: "PAR"},
        {in: ["obf"], out: "OBF"},
        {in: ["pe"], out: "PAL"},
        {in: ["bb"], out: "BoosterBox"},
        {in: ["bbs"], out: "BoosterBoxes"},
        {in: ["prissy", "pris", "prizzy", "prizz", "priz"], out: "PRE"}
    ];

    // Process text with word boundary checks
    function replaceWords(text) {
        let result = text;
        translations.forEach(({in: inputs, out: output}) => {
            inputs.forEach(word => {
                // Escape special regex characters
                const escapedWord = word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
                // Create case-insensitive regex with word boundaries
                const regex = new RegExp(`\\b${escapedWord}\\b`, 'gi');
                result = result.replace(regex, output);
            });
        });
        return result;
    }

    // Replace text in text nodes only
    function replaceInElement(el) {
        el.childNodes.forEach(node => {
            if (node.nodeType === Node.TEXT_NODE) {
                // Only replace in text nodes
                const originalText = node.textContent;
                const newText = replaceWords(originalText);
                if (originalText !== newText) {
                    node.textContent = newText;
                }
            } else if (node.nodeType === Node.ELEMENT_NODE && !['CODE', 'PRE'].includes(node.tagName)) {
                // Recursively process child elements (but skip code/pre)
                replaceInElement(node);
            }
        });
    }

    // Mutation observer to watch for new messages
    const observer = new MutationObserver(() => {
        // Find message elements and replace text
        document.querySelectorAll('[id^=message-content-]').forEach(el => {
            // Skip if already processed
            if (el.dataset.replaced) return;

            // Replace text while preserving HTML elements
            replaceInElement(el);

            // Mark as processed
            el.dataset.replaced = 'true';
        });
    });


    observer.observe(document.body, { childList: true, subtree: true });
    console.log('Ultimate Discord SetName Replacer');
})();