diff --git a/content.js b/content.js index 4179c28..69765f1 100644 --- a/content.js +++ b/content.js @@ -1,35 +1,26 @@ -console.log('[Buienradar Clicker] Content script loaded'); +(function() { + let handled = false; -let handled = false; + function dismissPaywall() { + if (handled) return; + const overlay = document.querySelector('.payok__wrap'); + if (!overlay) return; -function dismissPaywall() { - if (handled) return; - const overlay = document.querySelector('.payok__wrap'); - if (!overlay) return; + if (typeof window.Optanon?.AllowAll !== 'function') return; - console.log('[Buienradar Clicker] Dismissing paywall'); - handled = true; - clearInterval(pollInterval); - observer.disconnect(); + handled = true; + clearInterval(pollInterval); + observer.disconnect(); - const script = document.createElement('script'); - script.textContent = ` - (function() { - var w = document.querySelector('.payok__wrap'); - if (w && window.Optanon && typeof window.Optanon.AllowAll === 'function') { - window.Optanon.AllowAll(); - document.body.style.overflow = ''; - w.remove(); - } - })(); - `; - document.body.appendChild(script); - script.remove(); -} + window.Optanon.AllowAll(); + document.body.style.overflow = ''; + overlay.remove(); + } -const observer = new MutationObserver(dismissPaywall); -observer.observe(document.body, { childList: true, subtree: true }); + const observer = new MutationObserver(dismissPaywall); + observer.observe(document.body, { childList: true, subtree: true }); -const pollInterval = setInterval(dismissPaywall, 500); + const pollInterval = setInterval(dismissPaywall, 500); -dismissPaywall(); + dismissPaywall(); +})(); diff --git a/manifest.json b/manifest.json index e23322f..cf73c3b 100644 --- a/manifest.json +++ b/manifest.json @@ -7,7 +7,8 @@ { "matches": ["*://*.buienradar.nl/*"], "js": ["content.js"], - "run_at": "document_end" + "run_at": "document_end", + "world": "MAIN" } ], "icons": {