-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosda_event_bot.js
More file actions
76 lines (60 loc) · 2.52 KB
/
osda_event_bot.js
File metadata and controls
76 lines (60 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(async () => {
// --- CONFIGURATION ---
const rawData = `
65010001
65010002
`;
// 'S' or 'H' only
const STATUS = 'S';
// Milliseconds
const DELAY = 500;
// --- SETUP ---
const ids = rawData.trim().split(/\s+/).filter(Boolean); // Clean & Filter
const form = document.querySelector('#addStaffModal form');
if (!form) return console.error("[ERROR] Target form '#addStaffModal form' not found.");
const { action: url, elements } = form;
const token = elements['_token']?.value;
if (!token) return console.error("[ERROR] CSRF token not found in the form.");
console.log(`[INFO] Starting batch process... Total: ${ids.length} (Status: ${STATUS})`);
console.time("Execution Time");
const failedList = [];
let successCount = 0;
// --- EXECUTION ---
for (const [index, id] of ids.entries()) {
const prefix = `[${index + 1}/${ids.length}] ${id}`;
try {
const res = await fetch(url, {
method: 'POST',
body: new URLSearchParams({ _token: token, student_id: id, status: STATUS }),
redirect: 'follow'
});
const doc = new DOMParser().parseFromString(await res.text(), 'text/html');
const errorNode = doc.querySelector('.alert-danger ul li');
if (errorNode) {
const reason = errorNode.textContent.trim();
console.warn(`[FAILED] ${prefix} - ${reason}`);
failedList.push({ id, reason });
} else {
console.log(`[OK] ${prefix}`);
successCount++;
}
} catch (error) {
console.error(`[ERROR] ${prefix} - Network/Fetch Failed`, error);
failedList.push({ id, reason: "Fetch Error" });
}
// Delay handling (skip on last item)
if (index < ids.length - 1) await new Promise(r => setTimeout(r, DELAY));
}
// --- SUMMARY ---
console.log("\n==================================");
console.log("[SUMMARY] Process Completed");
console.timeEnd("Execution Time");
console.log(`Total: ${ids.length} | Success: ${successCount} | Failed: ${failedList.length}`);
console.log("==================================\n");
if (failedList.length > 0) {
console.warn("[ACTION REQUIRED] Failed IDs to copy:");
console.log(failedList.map(f => f.id).join('\n'));
console.log("\n[FAILED DETAILS]");
console.table(failedList);
}
})();