Skip to content

Instantly share code, notes, and snippets.

@jonfk
jonfk / bookmarklet_image_dwl.js
Last active October 26, 2022 18:20 — forked from lucidBrot/bookmarklet_image_dwl.js
Bookmarklet to download some images on a page
// as one-liner for bookmarklet
javascript:;(function(){var images=document.querySelector('#background.player').children;try{for (let img of images) {downloadResource(img.src)}}catch(e){alert("Download failed.");console.log('Download failed.',e)}function forceDownload(blob,filename){var a=document.createElement('a');a.download=filename;a.href=blob;a.click()}function downloadResource(url,filename){if(!filename)filename=url.split('\\').pop().split('/').pop();fetch(url,{headers:new Headers({'Origin':location.origin}),mode:'cors'}).then(response=>response.blob()).then(blob=>{let blobUrl=window.URL.createObjectURL(blob);forceDownload(blobUrl,filename)}).catch(e=>console.error(e))}}).call(window);