Skip to content

Instantly share code, notes, and snippets.

@da8
Last active April 23, 2024 12:30
Show Gist options
  • Save da8/2d791309f5acf1e299205f85e9314e95 to your computer and use it in GitHub Desktop.
Save da8/2d791309f5acf1e299205f85e9314e95 to your computer and use it in GitHub Desktop.
console.clear();
function saveData(blob, fileName)
{
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
}
var urls = document.querySelectorAll('a.icon-menu');
console.log('element count a.icon-menu: ' + urls.length);
for (url in urls) {
console.log (urls[url].href);
var xhr = new XMLHttpRequest();
xhr.open("GET", urls[url].href);
xhr.responseType = "blob";
xhr.onload = function () {
var fileName = xhr.getResponseHeader('Content-Disposition').split("filename=")[1];
saveData(this.response, fileName);
};
xhr.send();
}
console.log('done.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment