Greasy Fork is available in English.

Twitter emoji to system emoji

as name

// ==UserScript==
// @name     Twitter emoji to system emoji
// @version  1
// @grant    none
// @match    https://twitter.com/*
// @description as name
// @namespace https://greasyfork.org/users/1107653
// ==/UserScript==

function replaceEmojis() {
    const images = document.getElementsByTagName('img');
    for (let i = 0; i < images.length; i++) {
        const image = images[i];
        // Check if the image is a Twitter emoji
        if (image.src.includes('abs-0.twimg.com/emoji')) {
            // Extract the Unicode code point from the image URL
            const match = image.src.match(/\/([0-9a-f]+)\.svg/);
            // Make sure that a match was found
            if (match) {
                const codePoint = match[1];
                // Convert the code point to a Unicode character
                const char = String.fromCodePoint(parseInt(codePoint, 16));
                // Replace the image with a span containing the Unicode character
                const span = document.createElement('span');
                span.textContent = char;
                image.parentNode.replaceChild(span, image);
            }
        }
    }
}

// Run the function initially
replaceEmojis();

// Set up a MutationObserver to run the function whenever new content is added to the page
const observer = new MutationObserver(replaceEmojis);
observer.observe(document.body, {childList: true, subtree: true});