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

Walk 4 states, concat revertSteps

tags/v1.0.0
Gerben 6 years ago
parent
commit
664398defb
1 changed files with 14 additions and 11 deletions
  1. +14
    -11
      src/content_script.js

+ 14
- 11
src/content_script.js View File

@@ -42,25 +42,28 @@ function hideBanners() {
})
})

const revert = () => revertSteps.forEach(step => step())
return revert
return revertSteps
}


function main() {
let active = false
let revert
let state = 'off'
let revertSteps = []

function onScroll() {
let action
if (window.scrollY > 20 && !active) {
active = true
action = () => { revert = hideBanners() }
} else if (window.scrollY <= 0 && active) {
active = false
if (window.scrollY > 20 && state === 'off') {
state = 'starting'
action = () => {
revert && revert()
revert = undefined
revertSteps = revertSteps.concat(hideBanners())
state = 'on'
}
} else if (window.scrollY <= 0 && state === 'on') {
state = 'stopping'
action = () => {
revertSteps.forEach(step => step())
revertSteps = []
state = 'off'
}
}
if (action) {


Loading…
Cancel
Save