Skip to content

Instantly share code, notes, and snippets.

@Skhmt
Last active April 29, 2024 21:17
Show Gist options
  • Save Skhmt/f2279a04c2b1d39a369fe9a6cb366245 to your computer and use it in GitHub Desktop.
Save Skhmt/f2279a04c2b1d39a369fe9a6cb366245 to your computer and use it in GitHub Desktop.
Bookmarklet to download all images of a given class
javascript: (function () {
document.querySelectorAll('.BRpageimage').forEach(i => {
const url = new URL(i.src);
const filename = url.searchParams.get('file').split('/').pop().replace('.jp2','.jpg');
url.searchParams.set('scale', 1);
dl(url.href, filename);
});
function dl(url, filename) {
function blob2B64(blob, callback) {
const reader = new FileReader();
reader.onloadend = function () {
callback(reader.result);
};
reader.readAsDataURL(blob);
}
const req = new XMLHttpRequest();
req.open('GET', `https://api.allorigins.win/raw?url=${encodeURIComponent(url)}`);
req.responseType = 'blob';
req.onload = event => {
const blob = req.response;
blob2B64(blob, b64 => {
const a = document.createElement('a');
document.body.appendChild(a);
a.download = filename;
a.href = b64;
a.click();
});
};
req.send();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment