Discord SetName Replacer

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

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

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