From e0f5f503fe88daaba7526a2b92683eeeea187315 Mon Sep 17 00:00:00 2001 From: Barbara Miller Date: Mon, 20 Nov 2017 17:17:44 -0800 Subject: [PATCH 1/2] minor edits --- brozzler/behaviors.yaml | 8 +++++++- .../{umbraBehavior.js => umbraBehavior.js.j2} | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) rename brozzler/js-templates/{umbraBehavior.js => umbraBehavior.js.j2} (94%) diff --git a/brozzler/behaviors.yaml b/brozzler/behaviors.yaml index 40230ae..f95e330 100644 --- a/brozzler/behaviors.yaml +++ b/brozzler/behaviors.yaml @@ -39,7 +39,7 @@ request_idle_timeout_sec: 10 - url_regex: '^https?://(?:www\.)?pm\.gc\.ca/.*$' - behavior_js_template: classUmbraBehavior.js.j2 + behavior_js_template: umbraBehavior.js.j2 default_parameters: actions: - selector: div.teaser, li.pager__item a @@ -64,6 +64,12 @@ click_css_selector: img.img-responsive click_until_hard_timeout: False request_idle_timeout_sec: 10 +- # acalog https://webarchive.jira.com/browse/ARI-5517 + url_regex: '^https?://(?:www\.)?thejewishnews.com/.*$' + behavior_js_template: umbraBehavior.js.j2 + default_parameters: + actions: + - selector: a#get_more - # acalog https://webarchive.jira.com/browse/ARI-3775 url_regex: '^https?://.*[?&]catoid=[^?]*$' behavior_js_template: simpleclicks.js.j2 diff --git a/brozzler/js-templates/umbraBehavior.js b/brozzler/js-templates/umbraBehavior.js.j2 similarity index 94% rename from brozzler/js-templates/umbraBehavior.js rename to brozzler/js-templates/umbraBehavior.js.j2 index 27ede05..0ebc5dc 100644 --- a/brozzler/js-templates/umbraBehavior.js +++ b/brozzler/js-templates/umbraBehavior.js.j2 @@ -1,5 +1,5 @@ /* - * brozzler/js-templates/classUmbrabehavior.js.j2 - an umbra/brozzler behavior class + * brozzler/js-templates/umbrabehavior.js.j2 - an umbra/brozzler behavior class * * Copyright (C) 2017 Internet Archive * @@ -25,7 +25,7 @@ class UmbraBehavior { this.alreadyDone = []; this.idleSince = null; this.intervalId = null; - this.intervalTimeMs = 250; + this.intervalTimeMs = 1000; this.state = null; // currently unused this.index = 0; } @@ -127,7 +127,6 @@ class UmbraBehavior { console.log("ready for next action"); this.index += 1; this.idleSince = null; - return; } } } @@ -186,7 +185,8 @@ class UmbraBehavior { var umbraBehavior = new UmbraBehavior( {{actions|json}} ); -// var umbraBehavior = new UmbraBehavior( [{'selector': 'div.teaser, li.pager__item a'}] ); +//var umbraBehavior = new UmbraBehavior( [{'selector': 'div.teaser, li.pager__item a'}] ); // pm.gc.ca/eng/news/statements +//var umbraBehavior = new UmbraBehavior( [{'selector': 'a#get_more'}] ); // www.thejewishnews.com/arts-life/ multi iframes, error! // Called from outside of this script. var umbraBehaviorFinished = function() { From 371bd7df7ebfb9b0ee06b74ee11b0f6d39e84912 Mon Sep 17 00:00:00 2001 From: Barbara Miller Date: Mon, 27 Nov 2017 16:14:53 -0800 Subject: [PATCH 2/2] add simplerIntervalFunc... --- brozzler/js-templates/umbraBehavior.js.j2 | 91 ++++++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/brozzler/js-templates/umbraBehavior.js.j2 b/brozzler/js-templates/umbraBehavior.js.j2 index 0ebc5dc..7da1c47 100644 --- a/brozzler/js-templates/umbraBehavior.js.j2 +++ b/brozzler/js-templates/umbraBehavior.js.j2 @@ -131,6 +131,93 @@ class UmbraBehavior { } } + simplerIntervalFunc() { + var k = this.index; + var selector = this.actions[k].selector; + var action = this.actions[k].do ? this.actions[k].do : 'click'; + var closeSelector = this.actions[k].closeSelector ? this.actions[k].closeSelector : null; + + // var limit = this.actions[k].limit ? this.actions[k].limit : 0; + // if (limit && !(this.actions[k].alreadyDone)) { + // this.actions[k].alreadyDone = []; + // } + + // if (limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= limit) { + // continue; + // } + + var didSomething = false; + var somethingLeftBelow = false; + var somethingLeftAbove = false; + + if (closeSelector) { + var closeTargets = document.querySelectorAll(closeSelector); + if ((closeTargets.length > 0) && + (this.alreadyDone.indexOf(closeTargets[0]) === -1) && + (this.isVisible(closeTargets[0]))) { + console.log('closing'); + doTarget(closeTargets[0], 'click'); + } + } + + var doTargets = document.querySelectorAll(selector); + var doTargetsLength = doTargets.length; + for ( var i = 0; i < doTargetsLength; i++) { + if (this.alreadyDone.indexOf(doTargets[i]) > -1) { + continue; + } + if (!this.isVisible(doTargets[i])) { + continue; + } + // if using limits... + // if (limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= limit) { + // break; + // } + + var where = this.aboveBelowOrOnScreen(doTargets[i]); + if (where == 0) { + this.doTarget(doTargets[i], action); + // if using limits... + // if (this.actions[k].alreadyDone) { + // this.actions[k].alreadyDone.push(doTargets[i]); + // } + didSomething = true; + break; // break from doTargets loop + } else if (where > 0) { + somethingLeftBelow = true; + } else if (where < 0) { + somethingLeftAbove = true; + } + } + if (!didSomething) { + if (somethingLeftAbove) { + // console.log("scrolling up"); + window.scrollBy(0, -500); + this.idleSince = null; + } else if (somethingLeftBelow) { + // console.log("scrolling"); 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"); + window.scrollBy(0, 200); + this.idleSince = null; + } else if (this.idleSince == null) { + this.idleSince = Date.now(); + } + } + if (!this.idleSince) { + this.idleSince = Date.now(); + } else { + var idleTimeMs = Date.now() - this.idleSince; + if ((idleTimeMs / 1000) > (this.IDLE_TIMEOUT_SEC - 1) && (this.index < (this.actions.length - 1))) { + console.log("ready for next action"); + this.index += 1; + this.idleSince = null; + } + } + } + aboveBelowOrOnScreen(elem) { var eTop = elem.getBoundingClientRect().top; if (eTop < window.scrollY) { @@ -167,7 +254,7 @@ class UmbraBehavior { start() { var that = this; this.intervalId = setInterval(function() { - that.simpleIntervalFunc() + that.simplerIntervalFunc() }, this.intervalTimeMs); } @@ -185,7 +272,7 @@ class UmbraBehavior { var umbraBehavior = new UmbraBehavior( {{actions|json}} ); -//var umbraBehavior = new UmbraBehavior( [{'selector': 'div.teaser, li.pager__item a'}] ); // pm.gc.ca/eng/news/statements +//var umbraBehavior = new UmbraBehavior( [{'selector': 'div.teaser, li.pager__item a'}] ); // pm.gc.ca/eng/news //var umbraBehavior = new UmbraBehavior( [{'selector': 'a#get_more'}] ); // www.thejewishnews.com/arts-life/ multi iframes, error! // Called from outside of this script.