|
169 | 169 | } |
170 | 170 |
|
171 | 171 | const searchRegex = /[a-z0-9]/i; |
172 | | - onMount(() => { |
| 172 | + onMount(async () => { |
173 | 173 | document.addEventListener("keydown", (e) => { |
174 | 174 | if (!searchInput) return; |
175 | 175 | // Ignore keyboard shortcuts, special keys, non a-z0-9, or backspace, enter, delete, etc. |
|
216 | 216 |
|
217 | 217 | if (SessionState.ssr) return; |
218 | 218 |
|
219 | | - (async () => { |
220 | | - const enabled = !detectAdBlockEnabled() && State.isAHost(); |
221 | | - if (enabled) { |
222 | | - const host = browser ? window.location.hostname : "<SSR_HOST>"; |
223 | | - if (host in adSlotConfig) { |
224 | | - adSlots = adSlotConfig[host as keyof typeof adSlotConfig]; |
225 | | - } |
| 219 | + await detectAdBlockEnabled(); |
| 220 | + console.log("AdBlock Enabled:", SessionState.adBlockEnabled); |
| 221 | + adsEnabled = SessionState.adsEnabled; |
| 222 | + if (adsEnabled) { |
| 223 | + const host = browser ? window.location.hostname : "<SSR_HOST>"; |
| 224 | + if (host in adSlotConfig) { |
| 225 | + adSlots = adSlotConfig[host as keyof typeof adSlotConfig]; |
| 226 | + } |
| 227 | + (async () => { |
226 | 228 | const aHosts = await findAHosts(); |
227 | 229 | if (!aHosts) { |
228 | 230 | adsEnabled = false; |
| 231 | + SessionState.adsEnabled = false; |
229 | 232 | return; |
230 | 233 | } |
231 | 234 |
|
232 | 235 | const aHostData = aHosts.find((h) => h.hostname === host); |
233 | 236 | if (aHostData && aHostData.acode) { |
| 237 | + const scriptId = `ad-script-${aHostData.acode}`; |
| 238 | + if (document.getElementById(scriptId)) return; |
| 239 | +
|
234 | 240 | const script = document.createElement("script"); |
| 241 | + script.id = scriptId; |
235 | 242 | script.src = `//monu.delivery/site/${aHostData.acode}`; |
236 | 243 | script.setAttribute("data-cfasync", "false"); |
237 | 244 | script.defer = true; |
238 | 245 | document.head.appendChild(script); |
239 | | - adsEnabled = true; |
240 | 246 | } else { |
241 | | - if (!SessionState.devMode) { |
242 | | - adsEnabled = false; |
243 | | - } else { |
244 | | - const script = document.createElement("script"); |
245 | | - script.src = `//monu.delivery/site/${aHosts[0].acode}`; |
246 | | - script.setAttribute("data-cfasync", "false"); |
247 | | - script.defer = true; |
248 | | - document.head.appendChild(script); |
249 | | - adsEnabled = true; |
250 | | - if (!adSlots) { |
251 | | - adSlots = |
252 | | - adSlotConfig[ |
253 | | - aHosts[0].hostname as keyof typeof adSlotConfig |
254 | | - ]; |
255 | | - } |
256 | | - } |
| 247 | + adsEnabled = false; |
| 248 | + SessionState.adsEnabled = false; |
257 | 249 | } |
258 | | - } |
259 | | - })(); |
| 250 | + })(); |
| 251 | + } |
260 | 252 | }); |
261 | 253 |
|
262 | 254 | $effect(() => { |
|
0 commit comments