Created
July 14, 2024 20:37
-
-
Save TheOpponent/80c741bc8b674b70753663868e6cd3f4 to your computer and use it in GitHub Desktop.
Twitch - Nullify Gigantify Emote userscript
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 Twitch - Nullify Gigantify Emote | |
| // @version 0.1 | |
| // @description Workaround to undo the gigantic emote power-up and replace it with an emote of regular size, as of Jul 1 2024 | |
| // @include https://*.twitch.tv/* | |
| // @include https://twitch.tv/* | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| "use strict"; | |
| function changeClass(mutationList) { | |
| mutationList.forEach(mutation => { | |
| if (mutation.type === "childList") { | |
| mutation.addedNodes.forEach(node => { | |
| if (node.nodeType === Node.ELEMENT_NODE) { | |
| let elements = node.querySelectorAll(".chat-line__message--emote-button-gigantified"); | |
| if (node.classList && node.classList.contains("chat-line__message--emote-button-gigantified")) { | |
| elements = [node, ...elements]; | |
| } | |
| elements.forEach(el => { | |
| console.log("Nullifying gigantic emote."); | |
| el.classList.remove("chat-line__message--emote-button-gigantified"); | |
| el.classList.add("chat-line__message--emote-button"); | |
| let imgTags = el.querySelectorAll(".chat-image.chat-line__message--emote-gigantified"); | |
| imgTags.forEach(img => { | |
| img.classList.remove("chat-image", "chat-line__message--emote-gigantified"); | |
| img.classList.add("chat-image", "chat-line__message--emote"); | |
| if (img.src.endsWith("/3.0")) { | |
| img.src = img.src.replace("/3.0", "/1.0"); | |
| } | |
| if (img.srcset.endsWith("/3.0 1x")) { | |
| let baseUrl = img.srcset.split(" ")[0].replace("/3.0", ""); | |
| img.srcset = `${baseUrl}/1.0 1x ${baseUrl}/2.0 2x ${baseUrl}/3.0 4x`; | |
| } | |
| }); | |
| }); | |
| } | |
| }); | |
| } | |
| }); | |
| } | |
| function observeChatContainer() { | |
| const chatContainer = document.querySelector(".stream-chat"); | |
| if (chatContainer) { | |
| const observer = new MutationObserver(changeClass); | |
| observer.observe(chatContainer, { | |
| childList: true, | |
| subtree: true | |
| }); | |
| console.log("Observing Twitch chat."); | |
| } else { | |
| setTimeout(observeChatContainer, 1000); | |
| } | |
| } | |
| window.addEventListener("load", observeChatContainer); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment