Last active
August 2, 2021 18:35
-
-
Save TheLandolorien/d390f770c9c520d67698a72ad570fd59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jq = document.createElement('script'); | |
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"; | |
document.getElementsByTagName('head')[0].appendChild(jq); | |
$ = jQuery.noConflict(); | |
const delay = ms => new Promise(res => setTimeout(res, ms)); | |
var startingIndex = 0; | |
var delayInSeconds = 2; | |
var imageList = []; | |
// while there is a next button | |
while($('div.zsg-icon-expando-right').length) { | |
const srcs = $('.hdp-photo-gallery-lightbox-content .hdp-gallery-image-content:visible source[type="image/jpeg"]').attr('srcset').split(' '); | |
const src = srcs[srcs.length - 2]; | |
// just in case... let make sure the src is not already in the list. | |
if (imageList.indexOf(src) === -1) { | |
imageList.push(src); | |
} | |
// go to the next slide | |
$('div.zsg-icon-expando-right').click(); | |
} | |
var download = () => { | |
Promise.all(imageList.map(i => fetch(i))) | |
.then(responses => Promise.all(responses.map(res => res.blob()))) | |
.then(async (blobs) => { | |
for (let i = startingIndex; i < blobs.length; i++) { | |
if (i % 10 === 0) { | |
console.log(delayInSeconds + ' sec delay...'); | |
await delay(delayInSeconds * 1000); | |
} | |
var a = document.createElement('a'); | |
a.style = "display: none"; | |
var filename = (i + '').padStart(2, '0'); | |
console.log(`Downloading ${filename}.jpg`); | |
var url = window.URL.createObjectURL(blobs[i]); | |
a.href = url; | |
a.download = filename; | |
document.body.appendChild(a); | |
a.click(); | |
setTimeout(() => { | |
window.URL.revokeObjectURL(url); | |
}, 100); | |
} | |
}); | |
return; | |
}; | |
download(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment