diff options
Diffstat (limited to 'extension.js')
| -rw-r--r-- | extension.js | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/extension.js b/extension.js index 756c75e..dd7d229 100644 --- a/extension.js +++ b/extension.js @@ -1,4 +1,4 @@ -const start = () => { +const start = async () => { // if there is no chat if (document.querySelector("div[data-a-target=chat-input]") == null) { return; @@ -8,11 +8,40 @@ const start = () => { if (!channelName) { return; } + + const emotes = {}; + + // fetching instances + const instances = ["https://alright.party"]; + for (const instanceUrl of instances) { + const data = await getTinyEmotesUserByName(instanceUrl, channelName); + const user = data.data; + + // adding emotes + const emote_set = user.emote_sets.find((x) => x.id === user.active_emote_set_id); + for (const emote of emote_set.emotes) { + emotes[emote.code] = { + miniatureurl: `${instanceUrl}/static/userdata/emotes/${emote.id}/1x.${emote.ext}`, + fullurl: `${instanceUrl}/static/userdata/emotes/${emote.id}/3x.${emote.ext}`, + uploader: emote.uploaded_by ? emote.uploaded_by.username : "Anonymous*", + instance: instanceUrl + }; + } + } - getTinyEmotesUserByName("https://alright.party", channelName) - .then((x) => { - console.log(x); - }); + const observer = new MutationObserver(mutations => { + for (const m of mutations) { + m.addedNodes.forEach(node => { + if (node.nodeType !== 1) return; + const textEl = node.querySelector('[data-a-target=chat-message-text]'); + if (textEl) { + replaceEmotes(textEl, emotes); + } + }); + } + }); + + observer.observe(document.body, { childList: true, subtree: true }); }; function onPageReady(cb) { |
