Created
March 8, 2021 11:20
-
-
Save yaci/133325a3e4dbc34f398dfec67256f69e to your computer and use it in GitHub Desktop.
Annotates elements on page with their properties (e.g. font size, colour) so you don't have to open dev tools for testing/debugging
This file contains 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 getProp(elem, prop) { | |
const propValue = window.getComputedStyle(elem).getPropertyValue(prop); | |
return `${prop}: ${propValue}; `; | |
} | |
function annotateElements(elems) { | |
for (let e of elems) { | |
let sBuilder = "<span style='font-size: 8px;'>"; | |
sBuilder += getProp(e, 'font-size'); | |
//add more properties if needed e.g.: | |
//sBuilder += getProp(e, 'color'); | |
//sBuilder += getProp(e, 'font-weight'); | |
sBuilder += '</span>'; | |
e.innerHTML = sBuilder + e.innerHTML; | |
} | |
} | |
for (let tag of ['span', 'a', 'p', 'h1', 'h2', 'h3', 'h4', 'h5']) { | |
const elems = document.querySelectorAll('main ' + tag); | |
//eliminate empty tags, e.g. <span> that only have spaces inside | |
const nonEmptyElements = [...elems].filter(e => e.innerHTML.trim()); | |
annotateElements(nonEmptyElements); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment