mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-04-20 15:55:49 -04:00
Merge pull request #101 from galgeek/ARI-5617
repeatSameElement, firstMatchOnly, configurable interval timing, for ARI-5617
This commit is contained in:
commit
6aa8af9d80
@ -105,7 +105,7 @@ def behavior_script(url, template_parameters=None, behaviors_dir=None):
|
||||
'''
|
||||
Returns the javascript behavior string populated with template_parameters.
|
||||
'''
|
||||
import re, logging
|
||||
import re, logging, json
|
||||
for behavior in behaviors(behaviors_dir=behaviors_dir):
|
||||
if re.match(behavior['url_regex'], url):
|
||||
parameters = dict()
|
||||
@ -118,7 +118,7 @@ def behavior_script(url, template_parameters=None, behaviors_dir=None):
|
||||
script = template.render(parameters)
|
||||
logging.info(
|
||||
'using template=%r populated with parameters=%r for %r',
|
||||
behavior['behavior_js_template'], parameters, url)
|
||||
behavior['behavior_js_template'], json.dumps(parameters), url)
|
||||
return script
|
||||
return None
|
||||
|
||||
|
@ -21,6 +21,16 @@
|
||||
url_regex: '^https?://(?:www\.)?facebook\.com/.*$'
|
||||
behavior_js_template: facebook.js
|
||||
request_idle_timeout_sec: 30
|
||||
-
|
||||
url_regex: '^https?://americaspresidents\.si\.edu/gallery.*$'
|
||||
behavior_js_template: umbraBehavior.js.j2
|
||||
default_parameters:
|
||||
interval: 2500
|
||||
actions:
|
||||
- selector: div.see-more
|
||||
firstMatchOnly: true
|
||||
- selector: li.next
|
||||
repeatSameElement: true
|
||||
-
|
||||
url_regex: '^https?://(?:www\.)?marquette\.edu/.*$'
|
||||
behavior_js_template: marquette_edu.js
|
||||
|
@ -25,7 +25,7 @@ class UmbraBehavior {
|
||||
this.alreadyDone = [];
|
||||
this.idleSince = null;
|
||||
this.intervalId = null;
|
||||
this.intervalTimeMs = 300;
|
||||
this.intervalTimeMs = {{interval or 300}};
|
||||
this.index = 0;
|
||||
}
|
||||
|
||||
@ -33,6 +33,8 @@ class UmbraBehavior {
|
||||
// should match older default and simpleclicks behavior, and more
|
||||
var k = this.index;
|
||||
var selector = this.actions[k].selector;
|
||||
var repeatSameElement = this.actions[k].repeatSameElement ? this.actions[k].repeatSameElement : false;
|
||||
var firstMatchOnly = this.actions[k].firstMatchOnly ? this.actions[k].firstMatchOnly : false;
|
||||
var action = this.actions[k].do ? this.actions[k].do : 'click';
|
||||
var closeSelector = this.actions[k].closeSelector ? this.actions[k].closeSelector : null;
|
||||
var didSomething = false;
|
||||
@ -56,13 +58,17 @@ class UmbraBehavior {
|
||||
doTarget(closeTargets[0], 'click');
|
||||
}
|
||||
}
|
||||
var doTargets = documents[j].querySelectorAll(selector);
|
||||
if (firstMatchOnly) {
|
||||
var doTargets = [ documents[j].querySelector(selector) ];
|
||||
} else {
|
||||
var doTargets = documents[j].querySelectorAll(selector);
|
||||
}
|
||||
var doTargetsLength = doTargets.length;
|
||||
if (!(doTargetsLength > 0)) {
|
||||
continue;
|
||||
}
|
||||
for ( var i = 0; i < doTargetsLength; i++) {
|
||||
if (this.alreadyDone.indexOf(doTargets[i]) > -1) {
|
||||
if (!repeatSameElement && this.alreadyDone.indexOf(doTargets[i]) > -1) {
|
||||
continue;
|
||||
}
|
||||
if (!this.isVisible(doTargets[i])) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user