mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-04-21 16:16:28 -04:00
add limits
This commit is contained in:
parent
b1431ac2bb
commit
28130262ea
@ -38,14 +38,13 @@
|
||||
behavior_js_template: instagram.js
|
||||
request_idle_timeout_sec: 10
|
||||
-
|
||||
url_regex: '^https?://(?:www\.)?huffingtonpost\.com/.*$'
|
||||
url_regex: '^https?://(?:www\.)?pm\.gc\.ca/.*$'
|
||||
behavior_js_template: umbraBehavior.js.j2
|
||||
default_parameters:
|
||||
actions:
|
||||
- selector: .slideshow
|
||||
do: click
|
||||
- selector: .slideshow-overlay__container__left__nav__next
|
||||
do: click
|
||||
- selector: li.pager__item a
|
||||
limit: 4
|
||||
- selector: div.teaser
|
||||
-
|
||||
url_regex: '^https?://(?:www\.)?huffingtonpost\.com/.*$'
|
||||
behavior_js_template: huffpostslides.js
|
||||
|
@ -22,18 +22,24 @@ var umbraBehavior = {
|
||||
alreadyDone : [],
|
||||
idleSince : null,
|
||||
intervalId : null,
|
||||
actions : {{actions|json}},
|
||||
|
||||
intervalFunc: function() {
|
||||
var didSomething = false;
|
||||
var somethingLeftBelow = false;
|
||||
var somethingLeftAbove = false;
|
||||
|
||||
var actions = {{actions|json}};
|
||||
var actionsLength = actions.length;
|
||||
|
||||
var actionsLength = this.actions.length;
|
||||
for (var k = 0; k < actionsLength; k++) {
|
||||
var selector = actions[k].selector;
|
||||
var action = actions[k].do;
|
||||
var didSomething = false;
|
||||
var somethingLeftBelow = false;
|
||||
var somethingLeftAbove = false;
|
||||
|
||||
var selector = this.actions[k].selector;
|
||||
var action = this.actions[k].do ? this.actions[k].do : 'click';
|
||||
var limit = this.actions[k].limit ? this.actions[k].limit : 0;
|
||||
if (limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= limit) {
|
||||
continue;
|
||||
}
|
||||
if (limit && !(this.actions[k].alreadyDone)) {
|
||||
this.actions[k].alreadyDone = [];
|
||||
}
|
||||
|
||||
var iframes = document.querySelectorAll("iframe");
|
||||
var documents = Array(iframes.length + 1);
|
||||
@ -48,49 +54,58 @@ var umbraBehavior = {
|
||||
for (var j = 0; j < documentsLength; j++) {
|
||||
|
||||
var doTargets = documents[j].querySelectorAll(selector);
|
||||
if (doTargets == []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
doTargetsLength = doTargets.length;
|
||||
for ( var i = 0; i < doTargetsLength; i++) {
|
||||
if (limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= limit) {
|
||||
break;
|
||||
}
|
||||
if (this.alreadyDone.indexOf(doTargets[i]) > -1) {
|
||||
continue;
|
||||
}
|
||||
if (!this.isVisible(doTargets[i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var where = this.aboveBelowOrOnScreen(doTargets[i]);
|
||||
if (where == 0) {
|
||||
this.doTarget(doTargets[i], action);
|
||||
didSomething = true;
|
||||
if (this.actions[k].alreadyDone) {
|
||||
this.actions[k].alreadyDone.push(doTargets[i]);
|
||||
}
|
||||
} else if (where > 0) {
|
||||
somethingLeftBelow = true;
|
||||
} else if (where < 0) {
|
||||
somethingLeftAbove = true;
|
||||
}
|
||||
|
||||
if (didSomething) {
|
||||
break; // break from doTargets loop, but not from documents loop
|
||||
}
|
||||
|
||||
if (somethingLeftAbove) {
|
||||
// console.log("scrolling UP because everything on this screen has been done but we missed something above");
|
||||
window.scrollBy(0, -500);
|
||||
this.idleSince = null;
|
||||
} else if (somethingLeftBelow) {
|
||||
// console.log("scrolling because everything on this screen has been done but there's more below");
|
||||
window.scrollBy(0, 200);
|
||||
this.idleSince = null;
|
||||
} else if (window.scrollY + window.innerHeight < document.documentElement.scrollHeight) {
|
||||
// console.log("scrolling because we're not to the bottom yet");
|
||||
window.scrollBy(0, 200);
|
||||
this.idleSince = null;
|
||||
} else if (this.idleSince == null) {
|
||||
this.idleSince = Date.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!didSomething) {
|
||||
if (somethingLeftAbove) {
|
||||
// console.log("scrolling UP because everything on this screen has been done but we missed something above");
|
||||
window.scrollBy(0, -500);
|
||||
this.idleSince = null;
|
||||
} else if (somethingLeftBelow) {
|
||||
// console.log("scrolling because everything on this screen has been done but there's more below");
|
||||
window.scrollBy(0, 200);
|
||||
this.idleSince = null;
|
||||
} else if (window.scrollY + window.innerHeight < document.documentElement.scrollHeight) {
|
||||
// console.log("scrolling because we're not to the bottom yet");
|
||||
window.scrollBy(0, 200);
|
||||
this.idleSince = null;
|
||||
} else if (this.idleSince == null) {
|
||||
this.idleSince = Date.now();
|
||||
}
|
||||
}
|
||||
|
||||
if (!idleSince) {
|
||||
if (!this.idleSince) {
|
||||
this.idleSince = Date.now();
|
||||
}
|
||||
}
|
||||
@ -100,7 +115,7 @@ var umbraBehavior = {
|
||||
var that = this;
|
||||
this.intervalId = setInterval(function() {
|
||||
that.intervalFunc()
|
||||
}, 250);
|
||||
}, 1000);
|
||||
},
|
||||
|
||||
isFinished : function() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user