Skip to content

Instantly share code, notes, and snippets.

@Random832
Last active May 23, 2021 23:48
Show Gist options
  • Save Random832/c91bd1af2ad1b9c8828e66c597f8f7b1 to your computer and use it in GitHub Desktop.
Save Random832/c91bd1af2ad1b9c8828e66c597f8f7b1 to your computer and use it in GitHub Desktop.
Twitter Emoji Alt Fix
// ==UserScript==
// @name Twitter Emoji Alt Fix
// @description Set the alt text of Twitter Emoji images so that they can be copied correctly
// @version 1
// @grant none
// @include https://twitter.com/*
// ==/UserScript==
const SELECTOR = 'img[src*="twimg.com/emoji/"]'
function fixup(img) {
let tmp = img.src.split('/');
let hexs = tmp[tmp.length - 1].split('.')[0].split('-');
let alt = '';
for(let hex of hexs) alt += String.fromCodePoint(parseInt(hex, 16));
img.alt = alt;
}
function fixAll() {
document
.querySelectorAll(SELECTOR)
.forEach(fixup);
}
fixAll();
setInterval(fixAll, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment