mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-02-24 08:39:59 -05:00
More changes.
This commit is contained in:
parent
8829323a38
commit
f8a70f3842
131
umbra/behaviors.d/psu.js
Normal file
131
umbra/behaviors.d/psu.js
Normal file
@ -0,0 +1,131 @@
|
||||
var umbraAboveBelowOrOnScreen = function(e) {
|
||||
var eTop = e.getBoundingClientRect().top;
|
||||
if (eTop < window.scrollY) {
|
||||
return -1; // above
|
||||
} else if (eTop > window.scrollY + window.innerHeight) {
|
||||
return 1; // below
|
||||
} else {
|
||||
return 0; // on screen
|
||||
}
|
||||
}
|
||||
|
||||
var umbraSimpleScrollsAndClicksBehavior = {
|
||||
IDLE_TIMEOUT_SEC : 10,
|
||||
idleSince : null,
|
||||
alreadyClicked : {},
|
||||
|
||||
intervalFunc : function() {
|
||||
var clickedSomething = false;
|
||||
var somethingLeftBelow = false;
|
||||
var somethingLeftAbove = false;
|
||||
|
||||
var iframes = document.querySelectorAll("iframe");
|
||||
var documents = Array(iframes.length + 1);
|
||||
documents[0] = document;
|
||||
|
||||
for (var i = 0; i < iframes.length; i++) {
|
||||
documents[i+1] = iframes[i].contentWindow.document;
|
||||
}
|
||||
|
||||
for (var j = 0; j < documents.length; j++) {
|
||||
|
||||
var clickTargets = documents[j].querySelectorAll("a[id='load-more']");
|
||||
|
||||
if (umbraCheckAtEndOfScrollingContent(documents[j])) {
|
||||
return;
|
||||
}
|
||||
|
||||
for ( var i = 0; i < clickTargets.length; i++) {
|
||||
if (clickTargets[i].umbraClicked) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var where = umbraAboveBelowOrOnScreen(clickTargets[i]);
|
||||
|
||||
if (where == 0) {
|
||||
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 from clickTargets loop, but not from iframe loop
|
||||
} else if (where > 0) {
|
||||
somethingLeftBelow = true;
|
||||
} else if (where < 0) {
|
||||
somethingLeftAbove = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!clickedSomething) {
|
||||
if (somethingLeftAbove) {
|
||||
console.log("scrolling UP because everything on this screen has been clicked but we missed something above");
|
||||
window.scrollBy(0, -500);
|
||||
this.idleSince = null;
|
||||
} else if (somethingLeftBelow) {
|
||||
console.log("scrolling because everything on this screen has been clicked but there's more below document.body.clientHeight="
|
||||
+ document.body.clientHeight);
|
||||
window.scrollBy(0, 200);
|
||||
this.idleSince = null;
|
||||
} else if (window.scrollY + window.innerHeight < document.documentElement.scrollHeight) {
|
||||
console.log("scrolling because we're not to the bottom yet document.body.clientHeight="
|
||||
+ document.body.clientHeight);
|
||||
window.scrollBy(0, 200);
|
||||
this.idleSince = null;
|
||||
} else if (this.idleSince == null) {
|
||||
this.idleSince = Date.now();
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.idleSince) {
|
||||
this.idleSince = Date.now();
|
||||
}
|
||||
},
|
||||
|
||||
start : function() {
|
||||
var that = this;
|
||||
this.intervalId = setInterval(function() {
|
||||
that.intervalFunc()
|
||||
}, 250);
|
||||
},
|
||||
|
||||
isFinished : function() {
|
||||
if (this.idleSince != null) {
|
||||
var idleTimeMs = Date.now() - this.idleSince;
|
||||
if (idleTimeMs / 1000 > this.IDLE_TIMEOUT_SEC) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
var umbraCheckAtEndOfScrollingContent = function(document) {
|
||||
var elementToCheck = document.querySelector("a[id='load-more'][class='disabled']");
|
||||
|
||||
if (elementToCheck) {
|
||||
var computedStyle = window.getComputedStyle(elementToCheck);
|
||||
|
||||
if (computedStyle) {
|
||||
return computerStyle.visibility=='hidden';
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Called from outside of this script.
|
||||
var umbraBehaviorFinished = function() {
|
||||
return umbraSimpleScrollsAndClicksBehavior.isFinished()
|
||||
};
|
||||
|
||||
umbraSimpleScrollsAndClicksBehavior.start();
|
@ -21,14 +21,7 @@ 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;
|
||||
@ -40,23 +33,9 @@ var umbraSimpleScrollsAndClicksBehavior = {
|
||||
for (var j = 0; j < documents.length; j++) {
|
||||
|
||||
var clickTargets = documents[j].querySelectorAll(cssSelector);
|
||||
umbraEndConditionTarget = documents[j].querySelector(cssSelectorClickEndCondition);
|
||||
|
||||
if (umbraEndConditionTarget) {
|
||||
if (cssSelectorClickComputedStyleEndCondition != "") {
|
||||
if (umbraCheckSelectorEndCondition(cssSelectorClickComputedStyleEndCondition)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < clickTargets.length; i++) {
|
||||
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
|
||||
if (clickTargets[i].umbraClicked) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -128,12 +107,6 @@ var umbraSimpleScrollsAndClicksBehavior = {
|
||||
},
|
||||
};
|
||||
|
||||
var umbraCheckSelectorEndCondition = 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,13 +32,7 @@ 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:
|
||||
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"])
|
||||
behavior["script"] = simpleclicks_js_template.substitute(click_css_selector=behavior["click_css_selector"])
|
||||
|
||||
return Behavior._behaviors
|
||||
|
||||
|
@ -16,6 +16,10 @@ behaviors:
|
||||
url_regex: '^https?://(?:www\.)?vimeo\.com/.*$'
|
||||
behavior_js: vimeo.js
|
||||
request_idle_timeout_sec: 10
|
||||
-
|
||||
url_regex: '^https?://(?:www\.)?psu24.psu.edu/.*$'
|
||||
behavior_js: psu.js
|
||||
request_idle_timeout_sec: 10
|
||||
-
|
||||
url_regex: '^https?://(?:www\.)?instagram\.com/.*$'
|
||||
behavior_js: instagram.js
|
||||
@ -28,11 +32,6 @@ behaviors:
|
||||
url_regex: '^https?://(?:www\.)?usask.ca/.*$'
|
||||
click_css_selector: a[id='feature-next']
|
||||
request_idle_timeout_sec: 10
|
||||
# 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