Last active
December 1, 2020 15:41
-
-
Save j-f1/84f97cfdab222caa7bf8ca3c66a375d0 to your computer and use it in GitHub Desktop.
Replace the emoji on the Messenger website with the platform’s native ones
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 Messenger Native Emoji | |
// @namespace http://jedfox.com/ | |
// @version 1.0 | |
// @description Use native emoji on Messenger | |
// @author Jed Fox | |
// @match *://*.messenger.com/* | |
// @grant GM_addScript | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const codePointRe = /([0-9a-f]+(?:_[0-9a-f]+)*)\.png$/ | |
function parse(src) { | |
try { | |
const [, codes] = codePointRe.exec(src) | |
return codes.split("_").map(c => String.fromCodePoint(parseInt(c, 16))).join("") | |
} catch (err) { | |
return "�" | |
} | |
} | |
function run() { | |
document.querySelectorAll('img[src*="emoji.php"]').forEach(image => { | |
let emoji = parse(image.src) + '\u{FE0F}' | |
let { height } = image.getBoundingClientRect() | |
image.outerHTML = `<span ${height ? `style="font-size: ${height}px"` : ''}>${emoji}</span>` | |
}) | |
} | |
run() | |
let currentUrl = document.location.href | |
const observer = new MutationObserver(run); | |
const target = document.body; | |
const config = { childList: true, subtree: true }; | |
observer.observe(target, config); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment