-
Notifications
You must be signed in to change notification settings - Fork 1
/
uoj.mjs
49 lines (47 loc) · 1.46 KB
/
uoj.mjs
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
import { day, getPage } from "./tool.mjs";
async function _get(username, onlineJudgeUrl, onlineJudgeName) {
let get = async (page) => {
let content = await getPage({
url: `${onlineJudgeUrl}/submissions?submitter=${username}&min_score=100&max_score=100&page=${page}`,
method: 'GET',
});
content = content.substr(content.indexOf('<tbody>'));
return content;
};
let check = (content, page) => {
return !content.includes('<td colspan="233">无</td>') && (page == 1 || content.includes(`page=${page}\"`));
}
let list = [];
for (let page = 1, content; check(content = await get(page), page); page++) {
let paused = false;
for (; content.includes('<a href="/problem/'); ) {
let p = content.indexOf('<small>') + '<small>'.length;
let q = content.indexOf('<\/small>', p);
if (new Date(content.substr(p, q - p)).getTime() < day) {
paused = true;
break;
}
let s = content.indexOf('">#', content.indexOf('<a href="/problem/')) + '">#'.length;
let t = content.indexOf('</a>', s);
let problem = content.substr(s, t - s);
let id = problem.match(/[0-9]*/).toString();
let name = problem.substr(id.length + 2);
list.push(`[${onlineJudgeName} ${id}] ${name}`);
content = content.substr(q);
}
if (paused) {
break;
}
}
return list;
}
async function _uoj(username) {
return _get(username, 'https://uoj.ac', 'UOJ');
}
async function _bzoj(username) {
return _get(username, 'https://darkbzoj.tk', 'BZOJ');
}
export {
_uoj,
_bzoj,
}