mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-06-24 14:50:31 -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
3 changed files with 21 additions and 5 deletions
|
@ -105,7 +105,7 @@ def behavior_script(url, template_parameters=None, behaviors_dir=None):
|
||||||
'''
|
'''
|
||||||
Returns the javascript behavior string populated with template_parameters.
|
Returns the javascript behavior string populated with template_parameters.
|
||||||
'''
|
'''
|
||||||
import re, logging
|
import re, logging, json
|
||||||
for behavior in behaviors(behaviors_dir=behaviors_dir):
|
for behavior in behaviors(behaviors_dir=behaviors_dir):
|
||||||
if re.match(behavior['url_regex'], url):
|
if re.match(behavior['url_regex'], url):
|
||||||
parameters = dict()
|
parameters = dict()
|
||||||
|
@ -118,7 +118,7 @@ def behavior_script(url, template_parameters=None, behaviors_dir=None):
|
||||||
script = template.render(parameters)
|
script = template.render(parameters)
|
||||||
logging.info(
|
logging.info(
|
||||||
'using template=%r populated with parameters=%r for %r',
|
'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 script
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,16 @@
|
||||||
url_regex: '^https?://(?:www\.)?facebook\.com/.*$'
|
url_regex: '^https?://(?:www\.)?facebook\.com/.*$'
|
||||||
behavior_js_template: facebook.js
|
behavior_js_template: facebook.js
|
||||||
request_idle_timeout_sec: 30
|
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/.*$'
|
url_regex: '^https?://(?:www\.)?marquette\.edu/.*$'
|
||||||
behavior_js_template: marquette_edu.js
|
behavior_js_template: marquette_edu.js
|
||||||
|
|
|
@ -25,7 +25,7 @@ class UmbraBehavior {
|
||||||
this.alreadyDone = [];
|
this.alreadyDone = [];
|
||||||
this.idleSince = null;
|
this.idleSince = null;
|
||||||
this.intervalId = null;
|
this.intervalId = null;
|
||||||
this.intervalTimeMs = 300;
|
this.intervalTimeMs = {{interval or 300}};
|
||||||
this.index = 0;
|
this.index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ class UmbraBehavior {
|
||||||
// should match older default and simpleclicks behavior, and more
|
// should match older default and simpleclicks behavior, and more
|
||||||
var k = this.index;
|
var k = this.index;
|
||||||
var selector = this.actions[k].selector;
|
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 action = this.actions[k].do ? this.actions[k].do : 'click';
|
||||||
var closeSelector = this.actions[k].closeSelector ? this.actions[k].closeSelector : null;
|
var closeSelector = this.actions[k].closeSelector ? this.actions[k].closeSelector : null;
|
||||||
var didSomething = false;
|
var didSomething = false;
|
||||||
|
@ -56,13 +58,17 @@ class UmbraBehavior {
|
||||||
doTarget(closeTargets[0], 'click');
|
doTarget(closeTargets[0], 'click');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (firstMatchOnly) {
|
||||||
|
var doTargets = [ documents[j].querySelector(selector) ];
|
||||||
|
} else {
|
||||||
var doTargets = documents[j].querySelectorAll(selector);
|
var doTargets = documents[j].querySelectorAll(selector);
|
||||||
|
}
|
||||||
var doTargetsLength = doTargets.length;
|
var doTargetsLength = doTargets.length;
|
||||||
if (!(doTargetsLength > 0)) {
|
if (!(doTargetsLength > 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for ( var i = 0; i < doTargetsLength; i++) {
|
for ( var i = 0; i < doTargetsLength; i++) {
|
||||||
if (this.alreadyDone.indexOf(doTargets[i]) > -1) {
|
if (!repeatSameElement && this.alreadyDone.indexOf(doTargets[i]) > -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!this.isVisible(doTargets[i])) {
|
if (!this.isVisible(doTargets[i])) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue