Skip to content

Instantly share code, notes, and snippets.

@jandre3000
Last active September 11, 2023 16:15
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 jandre3000/9f3d5937170a59a405e9f2a06e3eb9df to your computer and use it in GitHub Desktop.
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.
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