Skip to content

Instantly share code, notes, and snippets.

@winguse
Last active July 1, 2020 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save winguse/e570c74449fd3535dc650adb5a270bdf to your computer and use it in GitHub Desktop.
Save winguse/e570c74449fd3535dc650adb5a270bdf to your computer and use it in GitHub Desktop.
copy and paste this in your browsers' console...
const walk = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
const delay = [];
while (true) {
const node = walk.nextNode();
if (!node) break;
if (!node.textContent.trim()) continue;
const { parentElement } = node;
if (parentElement.tagName === 'STYLE') continue;
const { color, display } = getComputedStyle(parentElement);
if (display === 'inline') {
parentElement.style.backgroundColor = color;
} else {
const newNode = document.createElement('span');
newNode.innerHTML = node.textContent;
newNode.style.backgroundColor = color;
delay.push([node, newNode]);
}
}
for (let [o, n] of delay) {
o.replaceWith(n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment