diff --git a/umbra/behaviors.d/instagram.js b/umbra/behaviors.d/instagram.js index 995786f..8955fbc 100644 --- a/umbra/behaviors.d/instagram.js +++ b/umbra/behaviors.d/instagram.js @@ -4,12 +4,13 @@ // var umbraInstagramBehavior = { - IDLE_TIMEOUT_SEC: 10, + IDLE_TIMEOUT_SEC: 20, idleSince: null, state: "loading-thumbs", imageCount: null, bigImagesLoaded: 0, - latestBigImage: null, + currentBigImage: null, + previousBigImage: null, intervalFunc: function() { if (this.state === "loading-thumbs") { @@ -31,15 +32,18 @@ var umbraInstagramBehavior = { 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 > 3000) { - console.log("finished loading-thumbs, it appears we have reached the bottom"); - this.state = "clicking-first-thumb"; - this.idleSince = null; - return; - } else { - // console.log("still might be waiting for something to load..."); - return; - } + } else { + var doneButtons = document.querySelectorAll(".PhotoGridMoreButton.pgmbDisabled"); + if (Date.now() - this.idleSince > 9000 || (doneButtons.length > 0 && doneButtons[0].innerText === "All items loaded") ) { + console.log("finished loading-thumbs, it appears we have reached the bottom"); + this.state = "clicking-first-thumb"; + this.idleSince = null; + return; + } else { + // console.log("still might be waiting for something to load..."); + return; + } + } } if (this.state === "clicking-first-thumb") { @@ -61,26 +65,38 @@ var umbraInstagramBehavior = { } if (this.state === "waiting-big-image") { - var imageFrame = document.querySelectorAll("div.Modal div.Item div.iMedia div.Image"); - if (imageFrame.length > 0) { - var bigImage = new Image(); - bigImage.src = imageFrame[0].getAttribute("src"); - // console.log("bigImage.naturalWidth=" + bigImage.naturalWidth + " bigImage.src=" + bigImage.src); - if (bigImage.src !== this.latestBigImage && bigImage.naturalWidth !== 0) { - console.log("next big image appears loaded, will click right arrow next time"); - this.state = "click-next-big-image"; - this.latestBigImage = bigImage.src; - this.bigImagesLoaded++; - this.idleSince = null; + if(this.currentBigImage == null) { + var imageFrame = document.querySelectorAll("div.Modal div.Item div.iMedia div.Image"); + if (imageFrame.length > 0 && imageFrame[0].getAttribute("src") !== this.previousBigImage ) { + this.currentBigImage = new Image(); + this.currentBigImage.src = imageFrame[0].getAttribute("src"); + //console.log("this.currentBigImage.naturalWidth=" + this.currentBigImage.naturalWidth + " this.currentBigImage.src=" + this.currentBigImage.src); return; - } - } - if (this.bigImagesLoaded >= this.imageCount) { - console.log("looks like we're done, we've loaded all " + this.bigImagesLoaded + " of " + this.imageCount + " big images"); - this.state = "finished"; + } else if(this.idleSince == null ) { + console.log("waiting for image frame to load"); + this.idleSince = Date.now(); + return; + } + } else if (this.currentBigImage.src !== this.previousBigImage && this.currentBigImage.naturalWidth !== 0) { + console.log("next big image appears loaded, will click right arrow next time"); + this.state = "click-next-big-image"; + this.previousBigImage = this.currentBigImage.src; + this.currentBigImage = null; + this.bigImagesLoaded++; + this.idleSince = null; + + if (this.bigImagesLoaded >= this.imageCount) { + 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; + } else if(this.idleSince == null) { + console.log("Waiting for big image to load"); this.idleSince = Date.now(); + return; } - return; + } if (this.state === "click-next-big-image") {