@@ -103,6 +103,9 @@ document.getElementById("goBackBtn").addEventListener("click", () => {
103103 const SESSION_INIT = "dmInitialized" , SESSION_USER_TOGGLED = "dmUserToggled" ;
104104 let applyTimer = 0 , observer = null ;
105105
106+ // USER CONFIG: array of CSS selectors or elements that dark mode should ignore
107+ const EXCLUDE_ELEMENTS = [ "#my-special-div123" , ".no-dark123" ] ;
108+
106109 // insert stylesheet once
107110 if ( ! document . getElementById ( STYLE_ID ) ) {
108111 const s = document . createElement ( "style" ) ;
@@ -130,11 +133,19 @@ document.getElementById("goBackBtn").addEventListener("click", () => {
130133 }
131134 const brightness = rgb => rgb ? ( rgb [ 0 ] * 299 + rgb [ 1 ] * 587 + rgb [ 2 ] * 114 ) / 1000 : 255 ;
132135
136+ function isExcluded ( el ) {
137+ if ( ! EXCLUDE_ELEMENTS || ! EXCLUDE_ELEMENTS . length ) return false ;
138+ return EXCLUDE_ELEMENTS . some ( sel => {
139+ if ( typeof sel === "string" ) return el . matches ( sel ) ;
140+ return el === sel ;
141+ } ) ;
142+ }
143+
133144 function applyDark ( ) {
134145 clearTimeout ( applyTimer ) ;
135146 applyTimer = setTimeout ( ( ) => requestAnimationFrame ( ( ) => {
136147 document . querySelectorAll ( "body *" ) . forEach ( el => {
137- if ( el . dataset . dmProcessed ) return ;
148+ if ( el . dataset . dmProcessed || isExcluded ( el ) ) return ;
138149 try {
139150 el . dataset . dmOriginalStyle = el . getAttribute ( "style" ) || "" ;
140151 const cs = getComputedStyle ( el ) , bg = cs . backgroundColor || "" , fs = parseFloat ( cs . fontSize || 0 ) ;
@@ -184,7 +195,6 @@ document.getElementById("goBackBtn").addEventListener("click", () => {
184195 sessionStorage . setItem ( SESSION_USER_TOGGLED , "1" ) ;
185196 localStorage . setItem ( STORAGE_KEY , enabled ? "true" : "false" ) ;
186197 if ( enabled ) {
187- // one-time transition on first toggle
188198 BODY . classList . add ( "dm-transition" ) ;
189199 applyDark ( ) ;
190200 startObserver ( ) ;
0 commit comments