Client-side messenger editor

change your friend text (client-side)

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Client-side messenger editor
// @namespace    SơnARSENAL
// @version      2.0
// @description  change your friend text (client-side)
// @author       SơnARSENAL
// @match        https://discord.com/*
// @run-at       document-idle
// @grant        none
// ==/UserScript==

(() => {
    "use strict";

    console.log(
        "%c✏️ sửa tin nhắn client-side by SơnARSENAL",
        "color:#00ff88;font-size:18px;font-weight:bold"
    );

    let mouseTarget = null;

    // Nhớ element đang được rê chuột lên
    document.addEventListener("mousemove", e => {
        mouseTarget = e.target;
    }, true);

    // Bấm ~ để sửa tin nhắn đang rê chuột
    document.addEventListener("keydown", e => {

        // Không làm gì nếu đang gõ text
        if (
            e.target.tagName === "INPUT" ||
            e.target.tagName === "TEXTAREA" ||
            e.target.isContentEditable
        ) {
            return;
        }

        // ~ / `
        if (e.key !== "~" && e.code !== "Backquote") {
            return;
        }

        if (!mouseTarget) return;

        const message =
            mouseTarget.closest('[class*="messageContent"]') ||
            mouseTarget.closest('[class*="markup"]');

        if (!message) {
            console.log(
                "%c⚠️ Hãy đưa chuột lên một tin nhắn rồi bấm ~",
                "color:#ffaa00;font-weight:bold"
            );
            return;
        }

        e.preventDefault();
        e.stopPropagation();

        const oldText = message.innerText;

        const newText = prompt(
            "✏️ sửa tin nhắn client-side by SơnARSENAL",
            oldText
        );

        if (newText === null) return;

        message.innerText = newText;

        console.log(
            "%c✓ Đã sửa client-side",
            "color:#00ffff;font-weight:bold"
        );
    }, true);

    console.log(
        "%c🟢 READY | Rê chuột lên tin nhắn → bấm ~",
        "color:#00ff88;font-weight:bold"
    );
})();