Last active
February 6, 2025 15:14
-
-
Save isakb/f9652fd4d89e283aafd0c301d7ac3f07 to your computer and use it in GitHub Desktop.
Bulk download PDFs from ETrade
This file contains hidden or 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
| // For https://us.etrade.com/etx/sp/stockplan/#/myAccount/stockPlanConfirmations | |
| // NOTE! The ETrade website has been updated, this script no longer works, as of Feb 6, 2025. | |
| 0&&(async()=>{let $=new TextEncoder,e=$$("td[data-content=Confirmation] > a").map(($,e)=>({url:$.href,name:`file_${e+1}.pdf`})),f=async({url:$,name:e})=>{let f=await fetch($);if(!f.ok)throw Error(`Failed to fetch: ${$}`);let x=new Uint8Array(await f.arrayBuffer());return{name:e,fileData:x}},x=async e=>{let x=[],l=0,t=[],n=await Promise.all(e.map(f));for(let{name:h,fileData:a}of n){let i=$.encode(h),g=[80,75,3,4,20,0,0,0,0,0,0,0,0,0,...[,,,,].fill(0),255&a.length,a.length>>8&255,a.length>>16&255,a.length>>24&255,255&a.length,a.length>>8&255,a.length>>16&255,a.length>>24&255,255&i.length,i.length>>8&255,0,0];x.push(new Uint8Array(g)),x.push(i),x.push(a),t.push({offset:l,fileNameBytes:i,fileHeader:g,fileSize:a.length}),l+=g.length+i.length+a.length}let o=[],r=0;for(let{offset:p,fileNameBytes:c,fileHeader:s,fileSize:d}of t){let u=[80,75,1,2,20,0,20,0,...s.slice(6,30),0,0,0,0,0,0,0,0,0,0,255&p,p>>8&255,p>>16&255,p>>24&255];o.push(new Uint8Array(u)),o.push(c),r+=u.length+c.length}let w=[80,75,5,6,0,0,0,0,255&t.length,t.length>>8&255,255&t.length,t.length>>8&255,255&r,r>>8&255,r>>16&255,r>>24&255,255&l,l>>8&255,l>>16&255,l>>24&255,0,0];return x.push(...o),x.push(new Uint8Array(w)),new Blob(x,{type:"application/zip"})},l=await x(e),t=URL.createObjectURL(l),n=document.createElement("a");n.href=t,n.download="files.zip",document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(t),console.log("ZIP file downloaded successfully!")})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment