Last active
September 11, 2023 16:15
-
-
Save jandre3000/9f3d5937170a59a405e9f2a06e3eb9df to your computer and use it in GitHub Desktop.
A Gist that highlights non-standard font-sizes on Wikipedia and outputs all computed font-size values into a console table and log.
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
const treeWalker = document.createTreeWalker( | |
document.body, | |
NodeFilter.SHOW_ELEMENT | |
); | |
const fontSizeTable = {}; | |
while (treeWalker.nextNode()) { | |
const node = treeWalker.currentNode; | |
const computedStyles = window.getComputedStyle(node); | |
const fontSize = computedStyles.getPropertyValue( 'font-size'); | |
const fontSizeNumber = parseFloat( fontSize ); | |
if ( fontSizeTable[ fontSize ] ) { | |
fontSizeTable[ fontSize ].push ( node ); | |
} else { | |
fontSizeTable[ fontSize ] = [ node ]; | |
} | |
if ( !Number.isInteger( fontSizeNumber ) || fontSizeNumber === 13 || fontSizeNumber < 12 ) { | |
node.style.backgroundColor = 'pink'; | |
node.style.outline = '2px solid red'; | |
} | |
node.classList.add( 'tree-node', 'fs-' + fontSize.replace('.', '_') ); | |
} | |
console.table( fontSizeTable ); | |
console.log( fontSizeTable ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment