Last active
March 6, 2024 20:12
-
-
Save erikyo/a39142908137ad89aaf0383702b1394c to your computer and use it in GitHub Desktop.
Select all the emojis in the page and wrap them into a span. Fix for this wordpress dark mode block plugin
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
function wrapEmojisWithDiv() { | |
const emojiRegex = /\p{Emoji_Presentation}/gu; | |
// Select all elements containing text | |
const elementsWithText = document.querySelectorAll('*:not(script):not(style)'); | |
elementsWithText.forEach(function(element) { | |
// node 3 is "text" | |
if (element.childNodes[0]?.nodeType === 3) { | |
// Wrap emojis with a div with the class "no-dark" that disables the "invert" filter | |
element.innerHTML = element.innerHTML.replace(emojiRegex, '<span class="no-dark">$&</span>'); | |
} | |
}); | |
} | |
wrapEmojisWithDiv(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment