Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Mastodon - Emoji Guide
// ==UserScript==
// @name Mastodon - Emoji Guide
// @namespace https://github.com/unarist/
// @version 0.3
// @description Add :shortname: as title attribute to emoji
// @author unarist
// @match https://*/web/*
// @require https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.7/lib/js/emojione.min.js
// @downloadURL https://gist.github.com/unarist/113400ddf6e8a16b907531e727bc0681/raw/mastodon-emoji-guide.user.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Mastodon1.4では標準搭載(#2784)なので、1.3向けの検知ロジックだけ
if (!document.querySelector('.app-holder[data-react-class="Mastodon"]')) {
if (document.querySelector('#mastodon'))
console.log('mastodon-emoji-guide.user.js: Mastodon1.4では標準搭載なので終了します。');
return;
}
const observe_root = document.querySelector('.columns-area');
const mappedUnicode = emojione.mapUnicodeToShort();
new MutationObserver(records =>
records.reduce((p, {target}) => p.concat([...target.querySelectorAll('.emojione:not([title])')]), [])
.forEach(elem => elem.title = mappedUnicode[emojione.jsEscapeMap[elem.alt]]))
.observe(observe_root, {childList: true, subtree: true});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment