Created
April 13, 2021 23:44
-
-
Save him229/6503072df33c9af39b1c1215d7e60e07 to your computer and use it in GitHub Desktop.
Zillow Listing Image Downloader
This file contains hidden or 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 script = document.createElement('script'); | |
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"; | |
script.onload = () => { | |
$ = jQuery.noConflict(); | |
// can't map since there isn't a list, so just push as we find more. | |
const imageList = []; | |
// while there is a next button | |
while ($('div.zsg-icon-expando-right').length || $('div.zsg-icon-reload').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); | |
} | |
// Last image, break out of loop | |
if ($('div.zsg-icon-reload').length) { | |
break; | |
} | |
// go to the next slide | |
$('div.zsg-icon-expando-right').click(); | |
} | |
const delay = ms => new Promise(res => setTimeout(res, ms)); // promise delay | |
// get all image blobs in parallel first before downloading for proper batching | |
Promise.all(imageList.map(i => fetch(i))).then(responses => | |
Promise.all(responses.map(res => res.blob())) | |
).then(async (blobs) => { | |
for (let i = 0; i < blobs.length; i++) { | |
if (i % 10 === 0) { | |
console.log('1 sec delay...'); | |
await delay(1000); | |
} | |
let a = document.createElement('a'); | |
a.style = "display: none"; | |
console.log(i); | |
let url = window.URL.createObjectURL(blobs[i]); | |
a.href = url; | |
a.download = i + ''; | |
document.body.appendChild(a); | |
a.click(); | |
setTimeout(() => { | |
window.URL.revokeObjectURL(url); | |
}, 100); | |
} | |
}); | |
}; | |
document.getElementsByTagName('head')[0].appendChild(script); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment