Skip to content

Instantly share code, notes, and snippets.

@winguse
Last active July 1, 2020 03:12
Embed
What would you like to do?
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