|
|
@@ -1,6 +1,9 @@ |
|
|
|
import browser from 'webextension-polyfill' |
|
|
|
import throttle from 'lodash/throttle' |
|
|
|
|
|
|
|
import { onEnabledChange, isEnabled } from './perOrigin' |
|
|
|
|
|
|
|
|
|
|
|
function hideBanners() { |
|
|
|
const revertSteps = [] |
|
|
|
|
|
|
@@ -47,20 +50,27 @@ function hideBanners() { |
|
|
|
return revertSteps |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function main() { |
|
|
|
let revertSteps = [] |
|
|
|
|
|
|
|
function onScroll(event) { |
|
|
|
if (window.scrollY > 20) { |
|
|
|
// XXX We read the location only once, but it may be changed by page scripts. |
|
|
|
// Fortunately we only need the origin, which should remain the same. |
|
|
|
const url = window.location.href |
|
|
|
|
|
|
|
async function run() { |
|
|
|
const enabled = await isEnabled(url) |
|
|
|
if (enabled && window.scrollY > 20) { |
|
|
|
// Hide everything that looks annoying. Remember the steps to revert this. |
|
|
|
revertSteps = hideBanners().concat(revertSteps) |
|
|
|
} else if (window.scrollY <= 0) { |
|
|
|
} else if (!enabled || window.scrollY <= 0) { |
|
|
|
// Unhide everything we have hidden. |
|
|
|
revertSteps.forEach(step => step()) |
|
|
|
revertSteps = [] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
window.addEventListener('scroll', throttle(onScroll, 1000)) |
|
|
|
window.addEventListener('scroll', throttle(run, 300)) |
|
|
|
onEnabledChange(url, run) |
|
|
|
} |
|
|
|
|
|
|
|
main() |