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

Rerun after a second (when scrolling)

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

+ 11
- 4
src/content_script.js View File

@@ -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') {


Loading…
Cancel
Save