Merge pull request #18 from nlevitt/ari-3771

to address ARI-3771 "Lasalle Facebook last scrolldown doesn't work", scr...
This commit is contained in:
Eldon 2014-04-04 16:04:38 -04:00
commit 4e72cbae58

View File

@ -1,9 +1,16 @@
//^https?://(?:www\.)?facebook.com/.*$ //^https?://(?:www\.)?facebook.com/.*$
// vim:set sw=8 et:
var isOnScreen = function(e) { var aboveBelowOrOnScreen = function(e) {
var eTop = e.getBoundingClientRect().top; var eTop = e.getBoundingClientRect().top;
return eTop > window.scrollY && eTop < window.scrollY + window.innerHeight; if (eTop < window.scrollY) {
}; return -1; // above
} else if (eTop > window.scrollY + window.innerHeight) {
return 1; // below
} else {
return 0; // on screen
}
}
// comments - 'a.UFIPagerLink > span, a.UFIPagerLink, span.UFIReplySocialSentenceLinkText' // comments - 'a.UFIPagerLink > span, a.UFIPagerLink, span.UFIReplySocialSentenceLinkText'
var THINGS_TO_CLICK_SELECTOR = 'a[href^="/browse/likes"], *[rel="theater"]'; var THINGS_TO_CLICK_SELECTOR = 'a[href^="/browse/likes"], *[rel="theater"]';
@ -26,12 +33,14 @@ var intervalFunc = function() {
var thingsToClick = document.querySelectorAll(THINGS_TO_CLICK_SELECTOR); var thingsToClick = document.querySelectorAll(THINGS_TO_CLICK_SELECTOR);
var clickedSomething = false; var clickedSomething = false;
var somethingLeftToClick = false; var somethingLeftBelow = false;
var missedAbove = 0;
for (var i = 0; i < thingsToClick.length; i++) { for (var i = 0; i < thingsToClick.length; i++) {
var target = thingsToClick[i]; var target = thingsToClick[i];
if (!(target in alreadyClicked)) { if (!(target in alreadyClicked)) {
if (isOnScreen(target)) { var where = aboveBelowOrOnScreen(target);
if (where == 0) { // on screen
// var pos = target.getBoundingClientRect().top; // var pos = target.getBoundingClientRect().top;
// window.scrollTo(0, target.getBoundingClientRect().top - 100); // window.scrollTo(0, target.getBoundingClientRect().top - 100);
console.log("clicking at " + target.getBoundingClientRect().top + " on " + target.outerHTML); console.log("clicking at " + target.getBoundingClientRect().top + " on " + target.outerHTML);
@ -42,19 +51,25 @@ var intervalFunc = function() {
alreadyClicked[target] = true; alreadyClicked[target] = true;
clickedSomething = true; clickedSomething = true;
break; break;
} else if (where > 0) {
somethingLeftBelow = true;
} else { } else {
somethingLeftToClick = true; missedAbove++;
} }
} }
} }
if (missedAbove > 0) {
console.log("somehow missed " + missedAbove + " click targets above");
}
if (!clickedSomething) { if (!clickedSomething) {
if (somethingLeftToClick) { if (somethingLeftBelow) {
console.log("scrolling because everything on this screen has been clicked but there's more below document.body.clientHeight=" + document.body.clientHeight); console.log("scrolling because everything on this screen has been clicked but there's more below document.body.clientHeight=" + document.body.clientHeight);
window.scrollBy(0, 100); window.scrollBy(0, 200);
} else if (window.scrollY + window.innerHeight + 10 < document.body.clientHeight) { } else if (window.scrollY + window.innerHeight + 10 < document.body.clientHeight) {
console.log("scrolling because we're not to the bottom yet document.body.clientHeight=" + document.body.clientHeight); console.log("scrolling because we're not to the bottom yet document.body.clientHeight=" + document.body.clientHeight);
window.scrollBy(0, 100); window.scrollBy(0, 200);
} }
} }
} }