diff --git a/umbra/behaviors.d/simpleclicks.js.in b/umbra/behaviors.d/simpleclicks.js.in index d97bac5..bc5d8ac 100644 --- a/umbra/behaviors.d/simpleclicks.js.in +++ b/umbra/behaviors.d/simpleclicks.js.in @@ -1,41 +1,58 @@ var umbraSimpleClicksBehavior = { - IDLE_TIMEOUT_SEC: 10, - idleSince: null, - alreadyClicked: {}, + IDLE_TIMEOUT_SEC: 10, + idleSince: null, + alreadyClicked: {}, - intervalFunc: function() { - var clickTargets = document.querySelectorAll("${click_css_selector}"); + intervalFunc: function() { + 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 i = 0; i < clickTargets.length; i++) { - var key = clickTargets[i].outerHTML; - if (!this.alreadyClicked[key]) { - console.log("clicking on " + key); - clickTargets[i].click(); - this.alreadyClicked[key] = true; - this.idleSince = null; - return; - } - } + for (var j = 0; j < documents.length; j++) { + var clickTargets = documents[j].querySelectorAll("${click_css_selector}"); + for (var i = 0; i < clickTargets.length; i++) { + var key = clickTargets[i].outerHTML; + if (!this.alreadyClicked[key]) { + console.log("clicking on " + key); - if (!this.idleSince) { - this.idleSince = Date.now(); - } - }, + // 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); - start: function() { - var that = this; - this.intervalId = setInterval(function(){ that.intervalFunc() }, 250); - }, + clickTargets[i].click(); + this.alreadyClicked[key] = true; + this.idleSince = null; + return; + } + } + } - isFinished: function() { - if (this.idleSince != null) { - var idleTimeMs = Date.now() - this.idleSince; - if (idleTimeMs / 1000 > this.IDLE_TIMEOUT_SEC) { - return true; - } - } - return false; - }, + 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; + }, }; // Called from outside of this script. diff --git a/umbra/behaviors.yaml b/umbra/behaviors.yaml index 687cc1b..14f88b3 100644 --- a/umbra/behaviors.yaml +++ b/umbra/behaviors.yaml @@ -28,6 +28,17 @@ 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'] + - # https://webarchive.jira.com/browse/AITFIVE-451 + url_regex: '^https?://(?:www\.)?soundcloud.com/.*$' + click_css_selector: button.sc-button-play, button.playButton + request_idle_timeout_sec: 10 + - # https://webarchive.jira.com/browse/AITFIVE-463 + url_regex: '^https?://(?:www\.)?christophercerrone.com/.*$' + click_css_selector: button.playButton.medium + request_idle_timeout_sec: 10 - # default fallback brhavior url_regex: '^.*$' request_idle_timeout_sec: 10