Browser extension to hide view-reducing screen junk from websites.
Browse Source

Listen to scroll events

tags/v1.0.0
Gerben 6 years ago
parent
commit
661a2687bc
1 changed files with 18 additions and 10 deletions
  1. +18
    -10
      src/content_script.js

+ 18
- 10
src/content_script.js View File

@@ -47,20 +47,28 @@ function hideBanners() {
} }




function startCheckingLoop() {
function main() {
let active = false
let revert let revert


function checkScroll() {
if (window.scrollY > 20 && !revert) {
revert = hideBanners()
} else if (window.scrollY <= 0 && revert) {
revert()
revert = undefined
function onScroll() {
let action
if (window.scrollY > 20 && !active) {
active = true
action = () => { revert = hideBanners() }
} else if (window.scrollY <= 0 && active) {
active = false
action = () => {
revert && revert()
revert = undefined
}
}
if (action) {
window.requestAnimationFrame(action)
} }
window.requestAnimationFrame(checkScroll);
} }


window.requestAnimationFrame(checkScroll);
window.addEventListener('scroll', onScroll)
} }


startCheckingLoop();
main()

Loading…
Cancel
Save