perf: optimize dom selectors for better performance

This commit is contained in:
radishzzz 2025-05-19 03:12:55 +01:00
parent bfe3771571
commit beb3386edc
10 changed files with 26 additions and 23 deletions

View file

@ -154,7 +154,7 @@ function setupTOCHighlight() {
if (!tocContent)
return
const tocLinks = tocContent.querySelectorAll('a')
const tocLinks = tocContent.getElementsByTagName('a')
if (tocLinks.length === 0)
return
@ -163,7 +163,7 @@ function setupTOCHighlight() {
// Build mapping from heading IDs to TOC links
const headingMap = new Map<string, HTMLAnchorElement>()
tocLinks.forEach((link) => {
Array.from(tocLinks).forEach((link) => {
const id = link.getAttribute('href')?.substring(1)
if (id)
headingMap.set(id, link as HTMLAnchorElement)