mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-08-11 16:00:38 -04:00
add limits
This commit is contained in:
parent
9db30b089c
commit
ac70617a05
2 changed files with 28 additions and 11 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,23 @@ var umbraBehavior = {
|
||||||
alreadyDone : [],
|
alreadyDone : [],
|
||||||
idleSince : null,
|
idleSince : null,
|
||||||
intervalId : null,
|
intervalId : null,
|
||||||
|
actions : {{actions|json}},
|
||||||
|
|
||||||
intervalFunc: function() {
|
intervalFunc: function() {
|
||||||
var didSomething = false;
|
var didSomething = false;
|
||||||
var somethingLeftBelow = false;
|
var somethingLeftBelow = false;
|
||||||
var somethingLeftAbove = false;
|
var somethingLeftAbove = false;
|
||||||
|
var actionsLength = this.actions.length;
|
||||||
var actions = {{actions|json}};
|
|
||||||
var actionsLength = actions.length;
|
|
||||||
|
|
||||||
for (var k = 0; k < actionsLength; k++) {
|
for (var k = 0; k < actionsLength; k++) {
|
||||||
var selector = actions[k].selector;
|
var selector = this.actions[k].selector;
|
||||||
var action = actions[k].do;
|
var action = this.actions[k].do ? this.actions[k].do : 'click';
|
||||||
|
if (this.actions[k].limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= this.actions[k].limit) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (this.actions[k].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);
|
||||||
|
@ -47,20 +52,33 @@ var umbraBehavior = {
|
||||||
documentsLength = documents.length;
|
documentsLength = documents.length;
|
||||||
for (var j = 0; j < documentsLength; j++) {
|
for (var j = 0; j < documentsLength; j++) {
|
||||||
|
|
||||||
|
if (this.actions[k].limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= this.actions[k].limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
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 (this.actions[k].limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= this.actions[k].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) {
|
||||||
|
@ -90,7 +108,7 @@ var umbraBehavior = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!idleSince) {
|
if (!this.idleSince) {
|
||||||
this.idleSince = Date.now();
|
this.idleSince = Date.now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue