···62626363 adjustBackButtonPosition()
64646565- document.addEventListener('astro:page-load', () => {
6666- adjustBackButtonPosition()
6767- })
6868- document.addEventListener('DOMContentLoaded', () => {
6969- adjustBackButtonPosition()
7070- })
6565+ // Use only astro:page-load as it fires on initial load and navigation
6666+ document.addEventListener('astro:page-load', adjustBackButtonPosition)
7167 window.addEventListener('resize', adjustBackButtonPosition)
7268 })()
7369</script>
+1-1
src/components/ui/CopyCode.astro
···134134 })
135135 }
136136137137+ // Use only astro:page-load as it fires on initial load and navigation
137138 document.addEventListener('astro:page-load', initCopyCode)
138138- document.addEventListener('DOMContentLoaded', initCopyCode)
139139</script>
140140141141<style is:inline>
+5-8
src/components/ui/FaviconThemeSwitcher.astro
···8484 }
85858686 // Initialize favicon theme switcher
8787+ let faviconSwitcherInitialized = false
8788 function init() {
8989+ if (faviconSwitcherInitialized) return
9090+ faviconSwitcherInitialized = true
9191+8892 try {
8993 new FaviconThemeSwitcher()
9094 } catch (error) {
···9296 }
9397 }
94989595- // Initialize when DOM is ready
9696- if (document.readyState === 'loading') {
9797- document.addEventListener('DOMContentLoaded', init)
9898- } else {
9999- init()
100100- }
101101-102102- // Re-initialize on Astro page loads
9999+ // Use only astro:page-load as it fires on initial load and navigation
103100 document.addEventListener('astro:page-load', init)
104101</script>
+24-4
src/components/ui/GradientMask.astro
···33</div>
4455<script>
66+ let mask: HTMLElement | null = null
77+ let ticking = false
88+69 function updateMask() {
77- const mask = document.querySelector('.gradient-mask') as HTMLElement
1010+ if (!mask) {
1111+ mask = document.querySelector('.gradient-mask') as HTMLElement
1212+ }
1313+ if (!mask) return
1414+815 const threshold = 64
916 const scrollY = window.scrollY
1017···1522 }
1623 }
17241818- document.addEventListener('DOMContentLoaded', () => {
2525+ function onScroll() {
2626+ if (ticking) return
2727+ ticking = true
2828+ requestAnimationFrame(() => {
2929+ updateMask()
3030+ ticking = false
3131+ })
3232+ }
3333+3434+ function initGradientMask() {
3535+ mask = document.querySelector('.gradient-mask') as HTMLElement
1936 updateMask()
2020- window.addEventListener('scroll', updateMask)
2121- })
3737+ }
3838+3939+ // Use only astro:page-load as it fires on initial load and navigation
4040+ document.addEventListener('astro:page-load', initGradientMask)
4141+ window.addEventListener('scroll', onScroll, { passive: true })
2242</script>
23432444<style>
+6-5
src/components/ui/ImageOptimizer.astro
···55 if (img.complete) {
66 img.classList.remove('img-placeholder')
77 } else {
88+ // Skip if already bound
99+ if (img.dataset.placeholderBound) return
1010+ img.dataset.placeholderBound = 'true'
1111+812 img.addEventListener('load', function () {
913 img.classList.remove('img-placeholder')
1014 })
1115 }
1216 })
1317 }
1414- if (document.readyState === 'loading') {
1515- document.addEventListener('DOMContentLoaded', removeImgPlaceholder)
1616- } else {
1717- removeImgPlaceholder()
1818- }
1818+1919+ // Use only astro:page-load as it fires on initial load and navigation
1920 document.addEventListener('astro:page-load', removeImgPlaceholder)
2021</script>
+12-13
src/components/ui/ImageViewer.astro
···85858686 bindImageClickEvents()
87878888- const observer = new MutationObserver(() => {
8989- bindImageClickEvents()
9090- })
8888+ // Observe only the content area instead of the entire body
8989+ const contentArea = document.querySelector('.prose') || document.querySelector('.content') || document.querySelector('article')
9090+ if (contentArea) {
9191+ const observer = new MutationObserver(() => {
9292+ bindImageClickEvents()
9393+ })
91949292- observer.observe(document.body, {
9393- childList: true,
9494- subtree: true
9595- })
9595+ observer.observe(contentArea, {
9696+ childList: true,
9797+ subtree: true
9898+ })
9999+ }
9610097101 // Hide initially
98102 viewer!.style.visibility = 'hidden'
99103 }
100104101101- if (document.readyState === 'loading') {
102102- document.addEventListener('DOMContentLoaded', initImageViewer)
103103- } else {
104104- initImageViewer()
105105- }
106106-105105+ // Use only astro:page-load as it fires on initial load and navigation
107106 document.addEventListener('astro:page-load', initImageViewer)
108107</script>
109108