Last active
May 23, 2021 23:48
-
-
Save Random832/c91bd1af2ad1b9c8828e66c597f8f7b1 to your computer and use it in GitHub Desktop.
Twitter Emoji Alt Fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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