Skip to content

Commit 7b528af

Browse files
committed
Update Fonts snippet
1 parent f9e1792 commit 7b528af

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,18 @@ console.log('Fonts and Weights Loaded in the Document')
263263
loadedFonts.forEach(font => console.log(`${font}`))
264264
console.log('')
265265

266-
const aboveFoldElements = Array.from(document.querySelectorAll('body > *:not(script):not(style)')).filter(el => {
267-
const rect = el.getBoundingClientRect();
268-
return (
269-
rect.top >= 0 &&
270-
rect.left >= 0 &&
271-
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
272-
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
273-
);
274-
});
275-
const usedFonts = Array.from(new Set([...aboveFoldElements].map(e => `${getComputedStyle(e).fontFamily} - ${getComputedStyle(e).fontWeight}`)));
266+
const childrenSlector = 'body * > *:not(script):not(style):not(link):not(source)'
267+
const aboveFoldElements = Array.from(document.querySelectorAll(childrenSlector)).filter(elm => {
268+
const rect = elm.getBoundingClientRect();
269+
return (
270+
rect.top >= 0 &&
271+
rect.left >= 0 &&
272+
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
273+
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
274+
)
275+
})
276+
277+
const usedFonts = Array.from(new Set([...aboveFoldElements].map(e => `${getComputedStyle(e).fontFamily} | ${getComputedStyle(e).fontWeight} | ${getComputedStyle(e).fontStyle}`)));
276278

277279
console.log('Fonts and Weights Used Avobe the Fold')
278280
usedFonts.forEach(font => console.log(`${font}`))

0 commit comments

Comments
 (0)