Merge pull request #103 from internetarchive/ARI-5671

instagram updates
This commit is contained in:
Noah Levitt 2018-03-23 14:18:04 -07:00 committed by GitHub
commit a1af18230c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 130 deletions

View File

@ -21,6 +21,16 @@
url_regex: '^https?://(?:www\.)?facebook\.com/.*$' url_regex: '^https?://(?:www\.)?facebook\.com/.*$'
behavior_js_template: facebook.js behavior_js_template: facebook.js
request_idle_timeout_sec: 30 request_idle_timeout_sec: 30
-
url_regex: '^https?://(?:www\.)?instagram\.com/.*$'
behavior_js_template: umbraBehavior.js.j2
default_parameters:
actions:
- selector: a.coreSpriteDismissLarge
- selector: div._mck9w a
firstMatchOnly: true
- selector: a.coreSpriteRightPaginationArrow
repeatSameElement: true
- -
url_regex: '^https?://americaspresidents\.si\.edu/gallery.*$' url_regex: '^https?://americaspresidents\.si\.edu/gallery.*$'
behavior_js_template: umbraBehavior.js.j2 behavior_js_template: umbraBehavior.js.j2
@ -43,10 +53,6 @@
url_regex: '^https?://(?:www\.)?psu24.psu.edu/.*$' url_regex: '^https?://(?:www\.)?psu24.psu.edu/.*$'
behavior_js_template: psu24.js behavior_js_template: psu24.js
request_idle_timeout_sec: 10 request_idle_timeout_sec: 10
-
url_regex: '^https?://(?:www\.)?instagram\.com/.*$'
behavior_js_template: instagram.js
request_idle_timeout_sec: 10
- -
url_regex: '^https?://(?:www\.)?pm\.gc\.ca/.*$' url_regex: '^https?://(?:www\.)?pm\.gc\.ca/.*$'
behavior_js_template: umbraBehavior.js.j2 behavior_js_template: umbraBehavior.js.j2

View File

@ -1,124 +0,0 @@
/*
* brozzler/behaviors.d/flickr.js - behavior for instagram
*
* 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 umbraInstagramBehavior = {
IDLE_TIMEOUT_SEC: 20,
idleSince: null,
state: "loading-thumbs",
imageCount: null,
bigImagesLoaded: 0,
currentBigImage: null,
previousBigImage: null,
intervalFunc: function() {
if (this.state === "loading-thumbs") {
var signUpButton = document.querySelectorAll("span._lilm5");
if (signUpButton.length > 0) {
console.log("clicking sign up button");
signUpButton[0].click();
this.idleSince = null;
return;
}
if (window.scrollY + window.innerHeight < document.documentElement.scrollHeight) {
window.scrollBy(0, 200);
this.idleSince = null;
return;
}
var moreButtons = document.querySelectorAll("a._1cr2e._epyes");
if (moreButtons.length > 0) {
console.log("clicking load more button");
moreButtons[0].click();
this.idleSince = null;
return;
}
if (this.idleSince === null) {
console.log("nothing to do at the moment, might be waiting for something to load, setting this.idleSince=Date.now()");
this.idleSince = Date.now();
return;
} else {
if ((Date.now() - this.idleSince) > 9000) {
console.log("finished loading-thumbs, it appears we have reached the bottom");
this.state = "clicking-first-thumb";
this.idleSince = null;
}
return;
}
}
if (this.state === "clicking-first-thumb") {
var images = document.querySelectorAll("div._si7dy");
if (images && images !== "undefined") {
this.imageCount = images.length;
if (images.length > 0) {
console.log("clicking first thumbnail");
images[0].click();
this.idleSince = null;
this.state = "waiting-big-image";
this.bigImagesLoaded++;
return;
}
}
console.log("no big images to load?");
this.idleSince = Date.now();
return;
}
if (this.state === "waiting-big-image") {
if(this.bigImagesLoaded < this.imageCount) {
var rightArrow = document.querySelectorAll(".coreSpriteRightPaginationArrow");
if (rightArrow.length > 0) {
// console.log("clicking right arrow");
rightArrow[0].click();
this.idleSince = null;
this.bigImagesLoaded++;
}
} else {
console.log("looks like we're done, we've loaded all " + this.bigImagesLoaded + " of " + this.imageCount + " big images");
this.state = "finished";
this.idleSince = Date.now();
}
return;
}
},
start: function() {
var that = this;
this.intervalId = setInterval(function(){ that.intervalFunc(); }, 300);
},
isFinished: function() {
if (this.idleSince !== null) {
var idleTimeMs = Date.now() - this.idleSince;
if (idleTimeMs / 1000 > this.IDLE_TIMEOUT_SEC) {
clearInterval(this.intervalId);
return true;
}
}
return false;
}
};
// Called from outside of this script.
var umbraBehaviorFinished = function() { return umbraInstagramBehavior.isFinished(); };
umbraInstagramBehavior.start();

View File

@ -104,7 +104,7 @@ class UmbraBehavior {
} else { } else {
var idleTimeMs = Date.now() - this.idleSince; var idleTimeMs = Date.now() - this.idleSince;
if ((idleTimeMs / 1000) > (this.IDLE_TIMEOUT_SEC - 1) && (this.index < (this.actions.length - 1))) { if ((idleTimeMs / 1000) > (this.IDLE_TIMEOUT_SEC - 1) && (this.index < (this.actions.length - 1))) {
console.log("ready for next action"); // untested! console.log("ready for next action");
this.index += 1; this.index += 1;
this.idleSince = null; this.idleSince = null;
window.scroll(0,0); window.scroll(0,0);
@ -124,7 +124,7 @@ class UmbraBehavior {
} }
isVisible(elem) { isVisible(elem) {
return !!(elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length); return elem && !!(elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length);
} }
doTarget(target, action) { doTarget(target, action) {