diff --git a/src/content_script.js b/src/content_script.js index ab5e76c..257ec3f 100644 --- a/src/content_script.js +++ b/src/content_script.js @@ -5,7 +5,10 @@ function hideBanners() { /* Hide all elements with position:fixed */ const fixedElements = Array.from(document.querySelectorAll('*')) - .filter(el => getComputedStyle(el).position === 'fixed') + .filter(el => ( + getComputedStyle(el).position === 'fixed' + && el.style.opacity !== '0' // ignore if we already hid this one + )) fixedElements.forEach(el => { const originalDisplay = el.style.display @@ -49,13 +52,17 @@ function hideBanners() { function main() { let state = 'off' let revertSteps = [] + let lastRun - function onScroll() { + function onScroll(event) { let action - if (window.scrollY > 20 && state === 'off') { + if (window.scrollY > 20 && + (state === 'off' || (state === 'on' && event.timeStamp - lastRun > 1000)) + ) { + lastRun = event.timeStamp state = 'starting' action = () => { - revertSteps = revertSteps.concat(hideBanners()) + revertSteps = hideBanners().concat(revertSteps) state = 'on' } } else if (window.scrollY <= 0 && state === 'on') {