diff --git a/README.md b/README.md index 5efce0c..db98f40 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ A browser extension which parses competitive programming problems from various o | Le Quy Don Online Judge | ✔ | ✔ | | Library Checker | ✔ | | | LibreOJ | ✔ | ✔ | -| LightOJ | ✔ | | +| LightOJ | ✔ | ✔ | | LSYOI | ✔ | | | Luogu | ✔ | ✔ | | Mendo | ✔ | | diff --git a/src/parsers/contest/LightOJContestParser.ts b/src/parsers/contest/LightOJContestParser.ts new file mode 100644 index 0000000..246d3d5 --- /dev/null +++ b/src/parsers/contest/LightOJContestParser.ts @@ -0,0 +1,11 @@ +import { LightOJProblemParser } from '../problem/LightOJProblemParser'; +import { SimpleContestParser } from '../SimpleContestParser'; + +export class LightOJContestParser extends SimpleContestParser { + protected linkSelector = '.card-body a.page-meta'; + protected problemParser = new LightOJProblemParser(); + + public getMatchPatterns(): string[] { + return ['https://lightoj.com/contest/*/arena/']; + } +} diff --git a/src/parsers/parsers.ts b/src/parsers/parsers.ts index 29e9367..7a7d36b 100644 --- a/src/parsers/parsers.ts +++ b/src/parsers/parsers.ts @@ -27,6 +27,7 @@ import { KattisContestParser } from './contest/KattisContestParser'; import { KilonovaContestParser } from './contest/KilonovaContestParser'; import { LanqiaoContestParser } from './contest/LanqiaoContestParser'; import { LibreOJContestParser } from './contest/LibreOJContestParser'; +import { LightOJContestParser } from './contest/LightOJContestParser'; import { LuoguContestParser } from './contest/LuoguContestParser'; import { NBUTOnlineJudgeContestParser } from './contest/NBUTOnlineJudgeContestParser'; import { NOJContestParser } from './contest/NOJContestParser'; @@ -264,6 +265,7 @@ export const parsers: Parser[] = [ new LibreOJContestParser(), new LightOJProblemParser(), + new LightOJContestParser(), new LSYOIProblemParser(), diff --git a/src/parsers/problem/LightOJProblemParser.ts b/src/parsers/problem/LightOJProblemParser.ts index 5ebeca2..8a3773b 100644 --- a/src/parsers/problem/LightOJProblemParser.ts +++ b/src/parsers/problem/LightOJProblemParser.ts @@ -1,22 +1,22 @@ -import { Sendable } from '../../models/Sendable'; +import type { Sendable } from '../../models/Sendable'; import { TaskBuilder } from '../../models/TaskBuilder'; import { htmlToElement } from '../../utils/dom'; import { Parser } from '../Parser'; export class LightOJProblemParser extends Parser { public getMatchPatterns(): string[] { - return ['https://lightoj.com/problem/*']; + return ['https://lightoj.com/problem/*', 'https://lightoj.com/contest/*/arena/problem/*']; } public async parse(url: string, html: string): Promise { const elem = htmlToElement(html); const task = new TaskBuilder('LightOJ').setUrl(url); - task.setName(elem.querySelector('.title > p').textContent.trim()); + task.setName(elem.querySelector('.title').textContent.trim()); - const limitsStr = elem.querySelector('.limit-section').textContent.trim(); - task.setTimeLimit(parseFloat(/([0-9.]+) second/.exec(limitsStr)[1]) * 1000); - task.setMemoryLimit(parseInt(/(\d+) MB/.exec(limitsStr)[1], 10)); + const limitElems = elem.querySelectorAll('.tooltip-trigger > span'); + task.setTimeLimit(parseFloat(/([0-9.]+)/.exec(limitElems[0].textContent)[1]) * 1000); + task.setMemoryLimit(parseInt(/(\d+)/.exec(limitElems[1].textContent)[1], 10)); const blocks = elem.querySelectorAll('.sample-dataset-section .dataset-container'); for (let i = 0; i < blocks.length - 1; i += 2) {