mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-07-26 08:15:43 -04:00
add limits
This commit is contained in:
parent
b1431ac2bb
commit
28130262ea
2 changed files with 48 additions and 34 deletions
|
@ -38,14 +38,13 @@
|
||||||
behavior_js_template: instagram.js
|
behavior_js_template: instagram.js
|
||||||
request_idle_timeout_sec: 10
|
request_idle_timeout_sec: 10
|
||||||
-
|
-
|
||||||
url_regex: '^https?://(?:www\.)?huffingtonpost\.com/.*$'
|
url_regex: '^https?://(?:www\.)?pm\.gc\.ca/.*$'
|
||||||
behavior_js_template: umbraBehavior.js.j2
|
behavior_js_template: umbraBehavior.js.j2
|
||||||
default_parameters:
|
default_parameters:
|
||||||
actions:
|
actions:
|
||||||
- selector: .slideshow
|
- selector: li.pager__item a
|
||||||
do: click
|
limit: 4
|
||||||
- selector: .slideshow-overlay__container__left__nav__next
|
- selector: div.teaser
|
||||||
do: click
|
|
||||||
-
|
-
|
||||||
url_regex: '^https?://(?:www\.)?huffingtonpost\.com/.*$'
|
url_regex: '^https?://(?:www\.)?huffingtonpost\.com/.*$'
|
||||||
behavior_js_template: huffpostslides.js
|
behavior_js_template: huffpostslides.js
|
||||||
|
|
|
@ -22,18 +22,24 @@ var umbraBehavior = {
|
||||||
alreadyDone : [],
|
alreadyDone : [],
|
||||||
idleSince : null,
|
idleSince : null,
|
||||||
intervalId : null,
|
intervalId : null,
|
||||||
|
actions : {{actions|json}},
|
||||||
|
|
||||||
intervalFunc: function() {
|
intervalFunc: function() {
|
||||||
|
var actionsLength = this.actions.length;
|
||||||
|
for (var k = 0; k < actionsLength; k++) {
|
||||||
var didSomething = false;
|
var didSomething = false;
|
||||||
var somethingLeftBelow = false;
|
var somethingLeftBelow = false;
|
||||||
var somethingLeftAbove = false;
|
var somethingLeftAbove = false;
|
||||||
|
|
||||||
var actions = {{actions|json}};
|
var selector = this.actions[k].selector;
|
||||||
var actionsLength = actions.length;
|
var action = this.actions[k].do ? this.actions[k].do : 'click';
|
||||||
|
var limit = this.actions[k].limit ? this.actions[k].limit : 0;
|
||||||
for (var k = 0; k < actionsLength; k++) {
|
if (limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= limit) {
|
||||||
var selector = actions[k].selector;
|
continue;
|
||||||
var action = actions[k].do;
|
}
|
||||||
|
if (limit && !(this.actions[k].alreadyDone)) {
|
||||||
|
this.actions[k].alreadyDone = [];
|
||||||
|
}
|
||||||
|
|
||||||
var iframes = document.querySelectorAll("iframe");
|
var iframes = document.querySelectorAll("iframe");
|
||||||
var documents = Array(iframes.length + 1);
|
var documents = Array(iframes.length + 1);
|
||||||
|
@ -48,31 +54,39 @@ var umbraBehavior = {
|
||||||
for (var j = 0; j < documentsLength; j++) {
|
for (var j = 0; j < documentsLength; j++) {
|
||||||
|
|
||||||
var doTargets = documents[j].querySelectorAll(selector);
|
var doTargets = documents[j].querySelectorAll(selector);
|
||||||
|
if (doTargets == []) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
doTargetsLength = doTargets.length;
|
doTargetsLength = doTargets.length;
|
||||||
for ( var i = 0; i < doTargetsLength; i++) {
|
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) {
|
if (this.alreadyDone.indexOf(doTargets[i]) > -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!this.isVisible(doTargets[i])) {
|
if (!this.isVisible(doTargets[i])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var where = this.aboveBelowOrOnScreen(doTargets[i]);
|
var where = this.aboveBelowOrOnScreen(doTargets[i]);
|
||||||
if (where == 0) {
|
if (where == 0) {
|
||||||
this.doTarget(doTargets[i], action);
|
this.doTarget(doTargets[i], action);
|
||||||
didSomething = true;
|
didSomething = true;
|
||||||
|
if (this.actions[k].alreadyDone) {
|
||||||
|
this.actions[k].alreadyDone.push(doTargets[i]);
|
||||||
|
}
|
||||||
} else if (where > 0) {
|
} else if (where > 0) {
|
||||||
somethingLeftBelow = true;
|
somethingLeftBelow = true;
|
||||||
} else if (where < 0) {
|
} else if (where < 0) {
|
||||||
somethingLeftAbove = true;
|
somethingLeftAbove = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (didSomething) {
|
if (didSomething) {
|
||||||
break; // break from doTargets loop, but not from documents loop
|
break; // break from doTargets loop, but not from documents loop
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!didSomething) {
|
|
||||||
if (somethingLeftAbove) {
|
if (somethingLeftAbove) {
|
||||||
// console.log("scrolling UP because everything on this screen has been done but we missed something above");
|
// console.log("scrolling UP because everything on this screen has been done but we missed something above");
|
||||||
window.scrollBy(0, -500);
|
window.scrollBy(0, -500);
|
||||||
|
@ -89,8 +103,9 @@ var umbraBehavior = {
|
||||||
this.idleSince = Date.now();
|
this.idleSince = Date.now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!idleSince) {
|
if (!this.idleSince) {
|
||||||
this.idleSince = Date.now();
|
this.idleSince = Date.now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +115,7 @@ var umbraBehavior = {
|
||||||
var that = this;
|
var that = this;
|
||||||
this.intervalId = setInterval(function() {
|
this.intervalId = setInterval(function() {
|
||||||
that.intervalFunc()
|
that.intervalFunc()
|
||||||
}, 250);
|
}, 1000);
|
||||||
},
|
},
|
||||||
|
|
||||||
isFinished : function() {
|
isFinished : function() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue