Skip to content

Instantly share code, notes, and snippets.

@pointydev
Last active August 19, 2021 03:38
Show Gist options
  • Save pointydev/f2d96ec634f393286593dc92bee19efc to your computer and use it in GitHub Desktop.
Save pointydev/f2d96ec634f393286593dc92bee19efc to your computer and use it in GitHub Desktop.
Twemoji Everywhere Userscript - Replaces the browser emoji implementation with Twemoji
// ==UserScript==
// @name Twemoji Everywhere
// @namespace pointydev
// @author pointydev
// @match http*://*/*
// @inject-into content
// @grant GM_addStyle
// @version 0.1.0
// @homepageURL https://gist.github.com/pointydev/f2d96ec634f393286593dc92bee19efc
// @updateURL https://gist.githubusercontent.com/pointydev/f2d96ec634f393286593dc92bee19efc/raw/twemoji_everywhere.user.js
// @icon https://twemoji.maxcdn.com/v/latest/72x72/1f603.png
// @require https://twemoji.maxcdn.com/v/latest/twemoji.min.js
// @description Replaces the browser emoji implementation with Twemoji
// ==/UserScript==
const parser = function(node) {
twemoji.parse(node.target, {
folder: 'svg',
ext: '.svg',
className: "pointydev-twemoji"
});
};
const update = function(mutation, observer) { mutation.forEach(parser); };
const observer = new MutationObserver(update);
try {
GM_addStyle("img.pointydev-twemoji {height: 1em; width: 1em; margin: 0 .05em 0 .1em; vertical-align: -0.1em;}");
observer.observe(document.body, {subtree: true, childList: true, characterData: true});
parser({target: document.body});
console.info("%c[Twemoji Everywhere]", "color: #1DA1F2; font-style: bold", "Initialised!");
}
catch(e) {
observer.disconnect()
console.warn("%c[Twemoji Everywhere]", "color: #1DA1F2; font-style: bold", "Failed to initialise!\n", e);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment