mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-04-20 23:56:34 -04:00
More changes for handling psu24 site
This commit is contained in:
parent
ea41653c44
commit
3467670900
@ -1,3 +1,5 @@
|
||||
var umbraEndConditionTarget;
|
||||
|
||||
var umbraAboveBelowOrOnScreen = function(e) {
|
||||
var eTop = e.getBoundingClientRect().top;
|
||||
if (eTop < window.scrollY) {
|
||||
@ -19,7 +21,14 @@ var umbraSimpleScrollsAndClicksBehavior = {
|
||||
var somethingLeftBelow = false;
|
||||
var somethingLeftAbove = false;
|
||||
var cssSelector = "${click_css_selector}";
|
||||
var cssSelectorClickEndCondition = "${click_css_selector_end_condition}";
|
||||
var cssSelectorClickComputedStyleEndCondition = "${click_css_selector_computed_style_end_condition}";
|
||||
|
||||
//fixup cssSelectorClickEndCondition value if this argument has not been set in behaviors.yaml
|
||||
if (cssSelectorClickEndCondition == "") {
|
||||
cssSelectorClickEndCondition = "#uniq-selector-for-nothing";
|
||||
}
|
||||
|
||||
var iframes = document.querySelectorAll("iframe");
|
||||
var documents = Array(iframes.length + 1);
|
||||
documents[0] = document;
|
||||
@ -30,34 +39,46 @@ var umbraSimpleScrollsAndClicksBehavior = {
|
||||
|
||||
for (var j = 0; j < documents.length; j++) {
|
||||
|
||||
var clickTargets = documents[j].querySelectorAll("button.sc-button-play, button.playButton");
|
||||
var clickTargets = documents[j].querySelectorAll(cssSelector);
|
||||
umbraEndConditionTarget = documents[j].querySelector(cssSelectorClickEndCondition);
|
||||
|
||||
if (umbraEndConditionTarget) {
|
||||
if (cssSelectorClickComputedStyleEndCondition != "") {
|
||||
var dynamicCode = umbraCreateDynamicCodeToCheckSelectorCondition(cssSelectorClickComputedStyleEndCondition);
|
||||
|
||||
if (eval(dynamicCode)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (cssSelectorClickComputedStyleEndCondition == "") {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < clickTargets.length; i++) {
|
||||
if (clickTargets[i].umbraClicked) {
|
||||
//has already been clicked so no need to check again. if we did check
|
||||
// and element was above screen, we would go back up and never reach the bottom
|
||||
if (clickTargets[i].umbraClicked && cssSelectorClickEndCondition == "#uniq-selector-for-nothing") {
|
||||
//has already been clicked so no need to check again unless there is a click end condition value set
|
||||
//for this url in behaviors.yaml. then we keep clicking until the end condition is met
|
||||
continue;
|
||||
}
|
||||
|
||||
var where = umbraAboveBelowOrOnScreen(clickTargets[i]);
|
||||
|
||||
if (where == 0) {
|
||||
if (!clickTargets[i].umbraClicked) {
|
||||
console.log("clicking on " + clickTargets[i].outerHTML);
|
||||
// do mouse over event on click target
|
||||
// since some urls are requsted only on
|
||||
// this event - see
|
||||
// https://webarchive.jira.com/browse/AITFIVE-451
|
||||
var mouseOverEvent = document.createEvent('Events');
|
||||
mouseOverEvent.initEvent("mouseover",true, false);
|
||||
clickTargets[i].dispatchEvent(mouseOverEvent);
|
||||
clickTargets[i].click();
|
||||
clickedSomething = true;
|
||||
this.idleSince = null;
|
||||
clickTargets[i].umbraClicked = true;
|
||||
console.log("clicking on " + clickTargets[i].outerHTML);
|
||||
// do mouse over event on click target
|
||||
// since some urls are requsted only on
|
||||
// this event - see
|
||||
// https://webarchive.jira.com/browse/AITFIVE-451
|
||||
var mouseOverEvent = document.createEvent('Events');
|
||||
mouseOverEvent.initEvent("mouseover",true, false);
|
||||
clickTargets[i].dispatchEvent(mouseOverEvent);
|
||||
clickTargets[i].click();
|
||||
clickedSomething = true;
|
||||
this.idleSince = null;
|
||||
clickTargets[i].umbraClicked = true;
|
||||
|
||||
break;
|
||||
}
|
||||
break; //break from clickTargets loop, but not from iframe loop
|
||||
} else if (where > 0) {
|
||||
somethingLeftBelow = true;
|
||||
} else if (where < 0) {
|
||||
@ -112,6 +133,12 @@ var umbraSimpleScrollsAndClicksBehavior = {
|
||||
},
|
||||
};
|
||||
|
||||
var umbraCreateDynamicCodeToCheckSelectorCondition = function(condition) {
|
||||
if (!condition || condition == "") return;
|
||||
|
||||
return eval("var dynamicFunction = new Function('return function testCondition(target){ if (!target) return false; var computedStyle=window.getComputedStyle(target); return computedStyle." + condition + " }' )(); dynamicFunction(umbraEndConditionTarget);");
|
||||
}
|
||||
|
||||
// Called from outside of this script.
|
||||
var umbraBehaviorFinished = function() {
|
||||
return umbraSimpleScrollsAndClicksBehavior.isFinished()
|
||||
|
@ -32,7 +32,13 @@ class Behavior:
|
||||
behavior_js = os.path.sep.join(__file__.split(os.path.sep)[:-1] + ["behaviors.d"] + [behavior["behavior_js"]])
|
||||
behavior["script"] = open(behavior_js, encoding="utf-8").read()
|
||||
elif "click_css_selector" in behavior:
|
||||
behavior["script"] = simpleclicks_js_template.substitute(click_css_selector=behavior["click_css_selector"])
|
||||
if "click_css_selector_end_condition" not in behavior:
|
||||
behavior["click_css_selector_end_condition"] = "";
|
||||
|
||||
if "click_css_selector_computed_style_end_condition" not in behavior:
|
||||
behavior["click_css_selector_computed_style_end_condition"] = "";
|
||||
|
||||
behavior["script"] = simpleclicks_js_template.substitute(click_css_selector=behavior["click_css_selector"], click_css_selector_end_condition=behavior["click_css_selector_end_condition"], click_css_selector_computed_style_end_condition=behavior["click_css_selector_computed_style_end_condition"])
|
||||
|
||||
return Behavior._behaviors
|
||||
|
||||
|
@ -31,6 +31,8 @@ behaviors:
|
||||
# https://webarchive.jira.com/browse/ARI-4128
|
||||
url_regex: '^https?://(?:www\.)?psu24.psu.edu/.*$'
|
||||
click_css_selector: a[id='load-more']
|
||||
click_css_selector_end_condition: a[id='load-more'][class='disabled']
|
||||
click_css_selector_computed_style_end_condition: visibility=='hidden'
|
||||
- # https://webarchive.jira.com/browse/AITFIVE-451
|
||||
url_regex: '^https?://(?:www\.)?soundcloud.com/.*$'
|
||||
click_css_selector: button.sc-button-play, button.playButton
|
||||
|
Loading…
x
Reference in New Issue
Block a user