Skip to content

Commit

Permalink
Merge pull request #503 from touhidurrr/lightoj-contest-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jmerle authored Oct 14, 2024
2 parents 46c1ffa + c31e673 commit 03298cf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 || |
Expand Down
11 changes: 11 additions & 0 deletions src/parsers/contest/LightOJContestParser.ts
Original file line number Diff line number Diff line change
@@ -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/'];
}
}
2 changes: 2 additions & 0 deletions src/parsers/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -264,6 +265,7 @@ export const parsers: Parser[] = [
new LibreOJContestParser(),

new LightOJProblemParser(),
new LightOJContestParser(),

new LSYOIProblemParser(),

Expand Down
12 changes: 6 additions & 6 deletions src/parsers/problem/LightOJProblemParser.ts
Original file line number Diff line number Diff line change
@@ -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<Sendable> {
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) {
Expand Down

0 comments on commit 03298cf

Please sign in to comment.