mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-08-10 15:30:18 -04:00
multiclicks behavior
This commit is contained in:
parent
21891476c4
commit
e2345c7eef
2 changed files with 111 additions and 0 deletions
105
brozzler/behaviors.d/multiclicks.js.template
Normal file
105
brozzler/behaviors.d/multiclicks.js.template
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* brozzler/behaviors.d/multiclicks.js.template - click on each of several elements
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014-2016 Internet Archive
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 umbraState = {'idleSince':null};
|
||||||
|
var umbraAlreadyClicked = {};
|
||||||
|
|
||||||
|
var umbraIntervalFunc = function() {
|
||||||
|
var clickedSomething = false;
|
||||||
|
var somethingLeftBelow = false;
|
||||||
|
var somethingLeftAbove = false;
|
||||||
|
var cssSelector = "${css_selector}";
|
||||||
|
|
||||||
|
var clickTargets = document.querySelectorAll(cssSelector);
|
||||||
|
|
||||||
|
for (var i = 0; i < clickTargets.length; i++) {
|
||||||
|
targetID = clickTargets[i].id;
|
||||||
|
if (targetID === "") {
|
||||||
|
targetID = location.host + "-" + i;
|
||||||
|
}
|
||||||
|
if (!(targetID in umbraAlreadyClicked)) {
|
||||||
|
var where = umbraAboveBelowOrOnScreen(clickTargets[i]);
|
||||||
|
if (where === 0) {
|
||||||
|
var mouseOverEvent = document.createEvent('Events');
|
||||||
|
mouseOverEvent.initEvent("mouseover", true, false);
|
||||||
|
clickTargets[i].dispatchEvent(mouseOverEvent);
|
||||||
|
clickTargets[i].click();
|
||||||
|
clickedSomething = true;
|
||||||
|
umbraState.idleSince = null;
|
||||||
|
umbraAlreadyClicked[targetID] = true;
|
||||||
|
break; //break from clickTargets 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);
|
||||||
|
umbraState.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);
|
||||||
|
umbraState.idleSince = null;
|
||||||
|
} else if (window.scrollY + window.innerHeight < document.documentElement.scrollHeight) {
|
||||||
|
window.scrollBy(0, 200);
|
||||||
|
umbraState.idleSince = null;
|
||||||
|
} else if (umbraState.idleSince == null) {
|
||||||
|
umbraState.idleSince = Date.now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (umbraState.idleSince == null) {
|
||||||
|
umbraState.idleSince = Date.now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we haven't had anything to do (scrolled, clicked, etc) in this amount of
|
||||||
|
// time, then we consider ourselves finished with the page.
|
||||||
|
var UMBRA_USER_ACTION_IDLE_TIMEOUT_SEC = 12;
|
||||||
|
|
||||||
|
// Called from outside of this script.
|
||||||
|
var umbraBehaviorFinished = function() {
|
||||||
|
if (umbraState.idleSince != null) {
|
||||||
|
var idleTimeMs = Date.now() - umbraState.idleSince;
|
||||||
|
if (idleTimeMs / 1000 > UMBRA_USER_ACTION_IDLE_TIMEOUT_SEC) {
|
||||||
|
clearInterval(umbraIntervalId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var umbraIntervalId = setInterval(umbraIntervalFunc, 5000);
|
|
@ -45,6 +45,12 @@ behaviors:
|
||||||
url_regex: '^https?://(?:www\.)?instagram\.com/.*$'
|
url_regex: '^https?://(?:www\.)?instagram\.com/.*$'
|
||||||
behavior_js: instagram.js
|
behavior_js: instagram.js
|
||||||
request_idle_timeout_sec: 10
|
request_idle_timeout_sec: 10
|
||||||
|
- # ARI-4838 racineco.com document viewers
|
||||||
|
url_regex: '^https?://(?:www\.)?racineco\.com/.*$'
|
||||||
|
behavior_js_template: multiclicks.js.template
|
||||||
|
default_parameters:
|
||||||
|
css_selector: img[id^='NavtwocolUserControl11_NavMeeting_item']
|
||||||
|
request_idle_timeout_sec: 10
|
||||||
-
|
-
|
||||||
url_regex: '^https?://(?:www\.)?brooklynmuseum\.org/exhibitions/.*$'
|
url_regex: '^https?://(?:www\.)?brooklynmuseum\.org/exhibitions/.*$'
|
||||||
behavior_js_template: simpleclicks.js.template
|
behavior_js_template: simpleclicks.js.template
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue