Skip to content

Instantly share code, notes, and snippets.

@NavaneethVijay
Created November 15, 2022 12:04
Show Gist options
  • Save NavaneethVijay/02b11807757e441d6199a82e595e0232 to your computer and use it in GitHub Desktop.
Save NavaneethVijay/02b11807757e441d6199a82e595e0232 to your computer and use it in GitHub Desktop.
async function fetchImages(url, name){
await fetch(url).then( async(res) => {
const blob = await res.blob();
const newBlob = new Blob([blob]);
const blobUrl = window.URL.createObjectURL(newBlob);
const link = document.createElement('a');
link.href = blobUrl;
link.setAttribute('download', name);
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
// clean up Url
window.URL.revokeObjectURL(blobUrl);
})
}
let categories = jQuery(".sub-category").slice(140, 147);
Array.prototype.forEach.call(categories, async (cat) => {
let srcimage = jQuery(cat).find('img').attr('src');
let brandText = jQuery(cat).find('h4 strong').text();
let renamed = brandText.replace(/\s/g, '-');
await fetchImages(srcimage, renamed+".jpg")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment