Created
July 16, 2019 02:02
-
-
Save SabinT/1e1dd6303a75ffbd57ac2ec4ae904244 to your computer and use it in GitHub Desktop.
Download Cascade STP bike pictures in one shot from download page after purchase (medium/full)
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
function download(url, name) { | |
fetch(url) | |
.then(resp => resp.blob()) | |
.then(blob => { | |
const url = window.URL.createObjectURL(blob); | |
const a = document.createElement('a'); | |
a.style.display = 'none'; | |
a.href = url; | |
a.download = name; | |
document.body.appendChild(a); | |
a.click(); | |
window.URL.revokeObjectURL(url); | |
}) | |
.catch(() => alert('Something went wrong.')); | |
} | |
var a = Array.from(document.getElementsByTagName("a")); | |
var full = a.filter(function(x) { return x.innerText == "Full-Sized"; }); | |
medium = a.filter(function(x) { return x.innerText == "Medium"; }) | |
full.map(x => download(x.href, "full" + x.href.substring(x.href.lastIndexOf('/') + 1) + ".jpg")) | |
medium.map(x => download(x.href, "medium" + x.href.substring(x.href.lastIndexOf('/') + 1) + ".jpg")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment