var sleepInterval = 2200; var sleep = 0; function finda(txt) { let finds = Array.from(document.querySelectorAll("a")).filter((el) => el.textContent.includes(txt) ); console.log(txt + ": " + finds.length); return finds; } function downloada(txt) { finda(txt).forEach((el, i, arr) => { console.log(`Downloading ${txt}...`, el.href); const link = document.createElement("a"); link.href = el.href; link.target = "_blank"; link.download = ""; link.click(); }); } finda("Rechnung").forEach((e, i, arr) => { setTimeout(() => { e.click(); console.log(i, e); if (i === arr.length - 1) { setTimeout(() => downloada("Rechnung 1"), 1000); setTimeout(() => downloada("Rechnung 2"), 2000); setTimeout(() => downloada("Rechnung 3"), 3000); setTimeout(() => downloada("Rechnung 4"), 4000); setTimeout(() => downloada("Rechnung 5"), 5000); } }, sleep); sleep += sleepInterval; });