-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmarklet.js
1 lines (1 loc) · 2.81 KB
/
bookmarklet.js
1
javascript:(function(){function p(a){l.push(a);setTimeout(function(){l.shift()},5E3);d.innerText=l.join("\n");d.style.opacity=5}function s(){d.style.opacity-=0.01;0>d.style.opacity&&(l=[]);setTimeout(s,10)}function e(a,c,b){a[c+0]=b&255;a[c+1]=b>>>8&255;a[c+2]=b>>>16&255;a[c+3]=b>>>24}function q(){this.local=[];this.central=[];this.n=this.centralSize=this.localSize=0}function f(a,c){for(var b=0;b<c.length;b++)if(null!==c[b]&&a[b]!==c[b])return!1;return!0}var d=document.createElement("div");document.body.appendChild(d); d.style.cssText="bottom:30px;background-color:#333333aa;color:#fff;padding:30px;z-index:1;position:fixed";d.innerText="Hello,\nWorld!";var l=[];s();for(var t=new Uint32Array(256),m=0;256>m;m++)for(var k=m,u=0;8>u;u++)k=k&1?k>>>1^3988292384:k>>>1,t[m]=k;q.prototype.add=function(a,c){c=(new TextEncoder).encode(c);for(var b=this.local,v=this.central,h=new Uint8Array(30),d=new Uint8Array(46),g=4294967295,f=0;f<a.length;f++)g=t[(g^a[f])&255]^g>>>8;g^=4294967295;h.set([80,75,3,4,10]);e(h,14,g);e(h,18,a.length); e(h,22,a.length);e(h,26,c.length);b.push(h);b.push(c);b.push(a);d.set([80,75,1,2,63,0,10]);e(d,16,g);e(d,20,a.length);e(d,24,a.length);e(d,28,c.length);d[38]=32;e(d,42,this.localSize);v.push(d);v.push(c);this.localSize+=30+c.length+a.length;this.centralSize+=46+c.length;this.n++};q.prototype.toBytes=function(){var a=0,c=new Uint8Array(this.localSize+this.centralSize+22),b=new Uint8Array(22);b.set([80,75,5,6]);e(b,8,this.n);e(b,10,this.n);e(b,12,this.centralSize);e(b,16,this.localSize);this.local.forEach(function(b){c.set(b, a);a+=b.length});this.central.forEach(function(b){c.set(b,a);a+=b.length});c.set(b,a);return c};var y="jpg jpeg gif svg webp png".split(" "),r=new q,n=Array.from(document.getElementsByTagName("img")).map(function(a){return a.src}).filter(function(a){return void 0!==a}).filter(function(a){return!a.startsWith("data:")}),n=n.concat(Array.from(document.getElementsByTagName("a")).map(function(a){return a.href}).filter(function(a){return 0<=y.indexOf(a.toLowerCase().split(".").pop())})),w="download-"+(new Date).toISOString().replaceAll(":", "-").replace("T","-").split(".")[0],x=0;n.forEach(function(a,c){var b=new XMLHttpRequest;b.url=a;b.responseType="arraybuffer";b.open("GET",a);b.onloadend=function(a){x++;p("Downloading "+b.url);a=new Uint8Array(a.target.response);var c=w+"/"+(r.n+1+"").padStart(5,"0")+"."+(f(a,[82,73,70,70,null,null,null,null,87,69,66,80])?"webp":f(a,[71,73,70,56])?"gif":f(a,[137,80,78,71,13,10,26,10])?"png":f(a,[255,216,255])?"jpg":f(a,[60,115,118,103])?"svg":"unknown");0===a.length?p("Failed to download "+b.url): r.add(a,c);x===n.length&&(a=document.createElement("a"),c=new Blob([r.toBytes()],{type:"application/zip"}),c=URL.createObjectURL(c),a.href=c,a.download=w+".zip",document.body.appendChild(a),a.style="display: none",a.click(),a.remove(),p("Done."))};b.send()})})();