59 lines
1.7 KiB
Markdown
59 lines
1.7 KiB
Markdown
---
|
|
created: 2026-08-06T15:15:00
|
|
tags:
|
|
- claude
|
|
- script
|
|
updated: 2026-08-06T15:16:00
|
|
---
|
|
|
|
```
|
|
(async function () {
|
|
const sessionId = "f27f0fa3-e115-4efe-a5a1-ca22bfc283b3";
|
|
const baseUrl = "/kyuidocuments/Home/GetDocument?sessionId=" + sessionId + "&docId=";
|
|
|
|
const allBoxes = Array.from(document.getElementsByClassName('doc-checkbox'));
|
|
const checked = allBoxes.filter(cb => cb.checked);
|
|
|
|
if (checked.length === 0) {
|
|
alert("No documents are checked. Check the boxes you want first, then re-run.");
|
|
return;
|
|
}
|
|
|
|
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
const sanitize = s => s.replace(/[\\/:*?"<>|]/g, "_");
|
|
|
|
console.log(`Starting download of ${checked.length} document(s)...`);
|
|
|
|
for (let i = 0; i < checked.length; i++) {
|
|
const cb = checked[i];
|
|
const docName = cb.getAttribute('data-doc-name');
|
|
const docId = cb.getAttribute('data-doc-id');
|
|
|
|
try {
|
|
const res = await fetch(baseUrl + docId, { credentials: 'include' });
|
|
const result = await res.json();
|
|
|
|
const a = document.createElement('a');
|
|
a.href = "data:application/pdf;base64," + result.content;
|
|
a.download = sanitize(docName + "-" + docId) + ".pdf";
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
|
|
console.log(`[${i + 1}/${checked.length}] Downloaded: ${a.download}`);
|
|
} catch (err) {
|
|
console.error(`[${i + 1}/${checked.length}] FAILED docId ${docId}:`, err);
|
|
}
|
|
|
|
await sleep(400);
|
|
|
|
if ((i + 1) % 5 === 0 && (i + 1) < checked.length) {
|
|
const nextPage = Math.floor(i / 5) + 2;
|
|
if (typeof displayTable === 'function') displayTable(nextPage);
|
|
await sleep(300);
|
|
}
|
|
}
|
|
|
|
alert(`Done. Downloaded ${checked.length} document(s).`);
|
|
})();
|
|
``` |