Last active
May 23, 2017 12:56
-
-
Save unarist/113400ddf6e8a16b907531e727bc0681 to your computer and use it in GitHub Desktop.
Mastodon - Emoji Guide
This file contains 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 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