Skip to content

Instantly share code, notes, and snippets.

@Shaddyjr
Last active November 27, 2022 06:43
Show Gist options
  • Save Shaddyjr/5ce0a4c2f6cc5ca83245b6d42c1751d3 to your computer and use it in GitHub Desktop.
Save Shaddyjr/5ce0a4c2f6cc5ca83245b6d42c1751d3 to your computer and use it in GitHub Desktop.
// video: https://youtu.be/1O5YH1jFVRs
////////////
// CONFIG //
////////////
const backgroundColor = "#000000"
const textColorByTag = {
"H1":"#7FFFD4",
"H2":"#7FFFD4",
"H3":"#7FFFD4",
"P":"#F5F5DC",
"SPAN":"#F5F5DC",
"DEFAULT":"#F0FFFF",
}
// More named colors here: https://www.w3schools.com/colors/colors_names.asp
/////////////////////////////////
// Main Logic after this point //
/////////////////////////////////
const walk = document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT,null,false)
while(textNode=walk.nextNode()){
const parent = textNode.parentElement
parent.style.backgroundColor = backgroundColor
const textColor = textColorByTag[parent.tagName]
parent.style.color = textColor || textColorByTag["DEFAULT"]
}
console.log("DONE!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment