Discord SetName Replacer

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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');
})();