Single Click To Copy Discord Message ID

Click any Discord message to copy its message ID

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Single Click To Copy Discord Message ID
// @namespace    https://greasyfork.org/users/1179204
// @version      0.0.1
// @description  Click any Discord message to copy its message ID
// @author       KaKa
// @match        https://discord.com/channels/*
// @license      MIT
// ==/UserScript==
(function () {
    'use strict';

    document.addEventListener('click', function (event) {
        const messageElement = event.target.closest('[id^="chat-messages-"]');
        if (!messageElement) return;

        const rawId = messageElement.id;
        if (!rawId.startsWith('chat-messages-')) return;

        const fullId = rawId.substring('chat-messages-'.length);
        const parts = fullId.split('-');
        const messageId = parts[1] || parts[0];

        navigator.clipboard.writeText(messageId).then(() => {
            messageElement.style.outline = '2px solid red';
            setTimeout(() =>{
                messageElement.style.outline = ''}, 500);
        }).catch(err => {
            console.error('Failed to copy message ID:', err);
        });
    });
})();