-
-
Save deltabravozulu/a33973a5503262d4aba23e06c7c14c4c to your computer and use it in GitHub Desktop.
Bookmarklet to Autoscroll Webpages (with commands); sped up-- also works on facebook now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (function() { | |
var a = document.body.clientHeight | |
var b = document.documentElement.scrollHeight | |
var c = document.documentElement.clientHeight | |
var d = innerHeight | |
var e = document.height | |
console.log("document.body.clientHeight:\t\t\t\t\t" + a + ";\ndocument.documentElement.scrollHeight:\t\t" + b + ";\ndocument.documentElement.clientHeight:\t\t" + c + ";\ninnerHeight:\t\t\t\t\t\t\t\t" + d + ";\ndocument.height:\t\t\t\t\t\t\t" + e); | |
if (document.URL.includes("facebook.com")) { | |
(function() { | |
var intervalObj = null; | |
var retry = 0; | |
var clickHandler = function() { | |
console.log("Clicked; stopping autoscroll"); | |
clearInterval(intervalObj); | |
document.body.removeEventListener("click", clickHandler); | |
} | |
function scrollDown() { | |
var scrollHeight = document.body.scrollHeight, | |
scrollTop = document.body.scrollTop, | |
innerHeight = window.innerHeight, | |
difference = (scrollHeight - scrollTop) - innerHeight | |
if (difference > 0) { | |
window.scrollBy(0, difference); | |
if (retry > 0) { | |
retry = 0; | |
} | |
console.log("scrolling down more"); | |
} else { | |
if (retry >= 3) { | |
console.log("reached bottom of page; stopping"); | |
clearInterval(intervalObj); | |
document.body.removeEventListener("click", clickHandler); | |
} else { | |
console.log("[apparenty] hit bottom of page; retrying: " + (retry + 1)); | |
retry++; | |
} | |
} | |
} | |
document.body.addEventListener("click", clickHandler); | |
intervalObj = setInterval(scrollDown, 1000); | |
})() | |
} else { | |
let _ss_interval_pointer; | |
let _ss_speed = 1; | |
let _ss_speed_pairs = [ | |
[0, 0], | |
[25, 200.0], | |
[36, 120.0], | |
[49, 72.0], | |
[64, 43.2], | |
[81, 25.9], | |
[100, 31.0], | |
[121, 37.2], | |
[144, 44.8], | |
[169, 26.4], | |
[196, 32.0] | |
]; | |
let _ss_last_onkeypress = document.onkeypress; | |
_ss_stop = function() { | |
clearTimeout(_ss_interval_pointer) | |
}; | |
_ss_start = function() { | |
_ss_abs_speed = Math.abs(_ss_speed); | |
_ss_direction = _ss_speed / _ss_abs_speed; | |
_ss_speed_pair = _ss_speed_pairs[_ss_abs_speed]; | |
//_ss_interval_pointer = setInterval('scrollBy(0,' + _ss_direction * _ss_speed_pair[0] + '); if((pageYOffset<=1)||(pageYOffset==document.height-innerHeight)) _ss_speed=0;', _ss_speed_pair[1]); | |
_ss_interval_pointer = setInterval('scrollBy(0,' + _ss_direction * _ss_speed_pair[0] + '); if((pageYOffset<=1)||(pageYOffset==document.documentElement.scrollHeight-innerHeight)) _ss_speed=0;', _ss_speed_pair[1]); | |
}; | |
_ss_adj = function(q) { | |
_ss_speed += q; | |
if (Math.abs(_ss_speed) >= _ss_speed_pairs.length) _ss_speed = (_ss_speed_pairs.length - 1) * (_ss_speed / Math.abs(_ss_speed)) | |
}; | |
_ss_quit = function() { | |
_ss_stop(); | |
document.onkeypress = _ss_last_onkeypress; | |
}; | |
document.onkeypress = function(e) { | |
if ((e.charCode == 113) || (e.keyCode == 27)) { | |
_ss_quit(); | |
return; | |
}; | |
if (e.charCode >= 48 && e.charCode <= 57) _ss_speed = e.charCode - 48; | |
else switch (e.charCode) { | |
case 95: | |
_ss_adj(-2); | |
case 45: | |
_ss_adj(-1); | |
break; | |
case 43: | |
_ss_adj(2); | |
case 61: | |
_ss_adj(1); | |
break; | |
}; | |
_ss_stop(); | |
_ss_start(); | |
}; | |
_ss_stop(); | |
_ss_start(); | |
}; | |
/* | |
0-9 : Set scroll speed, 0 being stand-still and 9 being skim-speed | |
– : Decrease speed | |
= : Increase speed | |
q : Quit | |
Credit: http://tim.theenchanter.com/2008/08/autoscroll-in-safari-firefox.html | |
*/ | |
})() | |
//below is the same script except in bookmarklet form | |
/* | |
javascript:(function(){var a=document.body.clientHeight,b=document.documentElement.scrollHeight,c=document.documentElement.clientHeight,d=innerHeight,e=document.height;if(console.log("document.body.clientHeight:\t\t\t\t\t"+a+";\ndocument.documentElement.scrollHeight:\t\t"+b+";\ndocument.documentElement.clientHeight:\t\t"+c+";\ninnerHeight:\t\t\t\t\t\t\t\t"+d+";\ndocument.height:\t\t\t\t\t\t\t"+e),document.URL.includes("facebook.com"))!function(){var e=null,t=0,s=function(){console.log("Clicked; stopping autoscroll"),clearInterval(e),document.body.removeEventListener("click",s)};document.body.addEventListener("click",s),e=setInterval(function(){var o=document.body.scrollHeight-document.body.scrollTop-window.innerHeight;o>0?(window.scrollBy(0,o),t>0&&(t=0),console.log("scrolling down more")):t>=3?(console.log("reached bottom of page; stopping"),clearInterval(e),document.body.removeEventListener("click",s)):(console.log("[apparenty] hit bottom of page; retrying: "+(t+1)),t++)},1e3)}();else{let e,t=1,s=[[0,0],[25,200],[36,120],[49,72],[64,43.2],[81,25.9],[100,31],[121,37.2],[144,44.8],[169,26.4],[196,32]],o=document.onkeypress;_ss_stop=function(){clearTimeout(e)},_ss_start=function(){_ss_abs_speed=Math.abs(t),_ss_direction=t/_ss_abs_speed,_ss_speed_pair=s[_ss_abs_speed],e=setInterval("scrollBy(0,"+_ss_direction*_ss_speed_pair[0]+"); if((pageYOffset<=1)||(pageYOffset==document.documentElement.scrollHeight-innerHeight)) _ss_speed=0;",_ss_speed_pair[1])},_ss_adj=function(e){t+=e,Math.abs(t)>=s.length&&(t=(s.length-1)*(t/Math.abs(t)))},_ss_quit=function(){_ss_stop(),document.onkeypress=o},document.onkeypress=function(e){if(113!=e.charCode&&27!=e.keyCode){if(e.charCode>=48&&e.charCode<=57)t=e.charCode-48;else switch(e.charCode){case 95:_ss_adj(-2);case 45:_ss_adj(-1);break;case 43:_ss_adj(2);case 61:_ss_adj(1)}_ss_stop(),_ss_start()}else _ss_quit()},_ss_stop(),_ss_start()}})() | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment