Skip to content

Commit

Permalink
add leetCode parser
Browse files Browse the repository at this point in the history
  • Loading branch information
KorigamiK committed May 21, 2022
1 parent fe19eea commit 9e1f85b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ dist/

# NPM (Yarn is used)
.package-lock.json
.cph
2 changes: 2 additions & 0 deletions src/parsers/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { HrbustOnlineJudgeProblemParser } from './problem/HrbustOnlineJudgeProbl
import { HydroProblemParser } from './problem/HydroProblemParser';
import { JutgeProblemParser } from './problem/JutgeProblemParser';
import { KattisProblemParser } from './problem/KattisProblemParser';
import { LeetCodeProblemParser } from './problem/LeetCodeProblemParser';
import { LibraryCheckerProblemParser } from './problem/LibraryCheckerProblemParser';
import { LibreOJProblemParser } from './problem/LibreOJProblemParser';
import { LightOJProblemParser } from './problem/LightOJProblemParser';
Expand Down Expand Up @@ -262,4 +263,5 @@ export const parsers: Parser[] = [

new YukicoderProblemParser(),
new YukicoderContestParser(),
new LeetCodeProblemParser(),
];
20 changes: 20 additions & 0 deletions src/parsers/problem/LeetCodeProblemParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Sendable } from '../../models/Sendable';
import { TaskBuilder } from '../../models/TaskBuilder';
import { htmlToElement } from '../../utils/dom';
import { Parser } from '../Parser';

export class LeetCodeProblemParser extends Parser {
public getMatchPatterns(): string[] {
return ['https://leetcode.com/problems/*', 'https://leetcode.com/contests/*/problems/*'];
}

public async parse(url: string, html: string): Promise<Sendable> {
console.log('My script engaged!');
const elem = htmlToElement(html);
const task = new TaskBuilder('HackerEarth').setUrl(url);
const titleElement = elem.querySelector('[data-cy="question-title"]');
task.setName(titleElement ? titleElement.textContent.trim() : 'LeetCodeProblem');
task.setCategory(elem.querySelector('[diff]').textContent.trim());
return task.build();
}
}

0 comments on commit 9e1f85b

Please sign in to comment.