Last active
March 17, 2020 13:27
-
-
Save danielsuo/faa9525a14eb920f585b9f037b37d315 to your computer and use it in GitHub Desktop.
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
/* | |
Bookmarklet to download image / movie from tadpoles | |
Sources: | |
https://gist.github.com/sfrdmn/8834747 by sfrdmn, unlicenced but I hope you won't sue me :3 | |
https://stackoverflow.com/a/49500465/2550406 by Leeroy, CC-BY-SA | |
*/ | |
;(function() { | |
// Probably should do some validation, but whatever | |
var images = [window.location.href + "?d=t"] | |
try { | |
images.forEach(function(img) { | |
downloadResource(img); | |
}) | |
} 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(); | |
} | |
// Current blob size limit is around 500MB for browsers | |
function downloadResource(url, filename) { | |
if (!filename) filename = url.split('\\').pop().split('/').pop(); | |
fetch(url, { | |
headers: new Headers({ | |
'Origin': location.origin | |
}), | |
mode: 'cors' | |
}) | |
.then(function(response) { return response.blob(); }) | |
.then(function(blob) { | |
var blobUrl = window.URL.createObjectURL(blob); | |
forceDownload(blobUrl, filename); | |
}) | |
.catch(function(e) { console.error(e) }); | |
} | |
}).call(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
javascript:void%20function(){(function(){function%20o(o,n){var%20c=document.createElement(%22a%22);c.download=n,c.href=o,c.click()}function%20n(n,c){c||(c=n.split(%22\%22).pop().split(%22/%22).pop()),fetch(n,{headers:new%20Headers({Origin:location.origin}),mode:%22cors%22}).then(function(o){return%20o.blob()}).then(function(n){var%20e=window.URL.createObjectURL(n);o(e,c)})%22catch%22}var%20c=[window.location.href+%22%3Fd=t%22];try{c.forEach(function(o){n(o)})}catch(e){alert(%22Download%20failed.%22),console.log(%22Download%20failed.%22,e)}}).call(window)}();