📜 ⬆️ ⬇️

ScrollAll (script for greasemonkey)

I read Habralent in Google Reader, and I noticed a long time ago that blocks with scrolling by a couple of pixels appear in it with enviable regularity, which prevent the entire tape from scrolling further. You have to take the mouse to the window scroll bar - not difficult, of course, but annoying, especially when you read “diagonally”. Therefore, a script was written that finds all such elements and temporarily blocks scrolling when the element is scrolled to the end, thereby allowing the page to scroll down.



// ==UserScript==
// @name ScrollAll
// @version 0.4
// @namespace http://zij.habrahabr.ru
// @description ,
// @author ZIJ
// @include http://www.google.com/reader/*
// @include https://www.google.com/reader/*
// ==/UserScript==

// <>
var maxScrolls = 4 // " ",
var hideTime = 4000 // , ms
var checkInterval = 2000 // DOM, ms
// </>

var DOMModified = false
var scrollCount = 0
var lastScrollTop = -1
var lastScrollTime = 0

document .addEventListener( "DOMSubtreeModified" , function () { DOMModified = true }, false )

var I = setInterval(scan, checkInterval)

function scan() { //
if (DOMModified) {
DOMModified = false
for each (element in document .getElementsByTagName( "*" )) {
if (IsScrollable(element)) {
element.addEventListener( "DOMMouseScroll" , handleScroll, false )
}
}
}
}

function IsScrollable(element) { //
if (element.scrollHeight > element.clientHeight) {
with (window.getComputedStyle(element, null )) {
return (overflow == "scroll" ) || (overflow == "auto" )
}
} else return false
}

function handleScroll( event ) { // " "
if ( event .timeStamp != lastScrollTime) {
var newScrollTop = event .currentTarget.scrollTop
if (newScrollTop == lastScrollTop) {
scrollCount++
if (scrollCount >= maxScrolls) {
scrollCount = 0
hideScrollbars( event .currentTarget)
}
} else {
scrollCount = 0
lastScrollTop = newScrollTop
}
lastScrollTime = event .timeStamp
}
}

function hideScrollbars(element) { //
var prev = window.getComputedStyle(element, null ).overflow
element.style.overflow = "hidden"
setTimeout( function () { element.style.overflow = prev }, hideTime)
}


* This source code was highlighted with Source Code Highlighter .

')
Download Greasemonkey here.
The name of the script file must end with .user.js
The script is installed by drag-n-drop in the FF window (with Greasemonkey enabled), after which the page needs to be updated

UPD: Made a more visual and correct check of the document modification

Source: https://habr.com/ru/post/67651/


All Articles