Skip to content

Instantly share code, notes, and snippets.

@erikyo
Last active March 6, 2024 20:12
Show Gist options
  • Save erikyo/a39142908137ad89aaf0383702b1394c to your computer and use it in GitHub Desktop.
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
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