Skip to content

Commit

Permalink
feat(vjudge): support fork contests from qoj
Browse files Browse the repository at this point in the history
  • Loading branch information
memset0 committed Jul 22, 2024
1 parent 6de0113 commit 38b936d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Dict } from './utils/type';
import Module from './types/module';
import Feature from './types/feature';
import ModuleVjudge from './modules/vjudge/main';
import ModuleQOJ from './modules/qoj/main';
import ModuleCodeforces from './modules/codeforces/main';

export default class App {
Expand Down Expand Up @@ -42,3 +43,4 @@ export default class App {
export const app = new App();
app.register(new ModuleVjudge(app));
app.register(new ModuleCodeforces(app));
app.register(new ModuleQOJ(app));
12 changes: 12 additions & 0 deletions src/modules/qoj/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import config from '../../config'
import App from '../../app'
import Module from "../../types/module"

export default class ModuleQOJ extends Module {
run() {
}

constructor(app: App) {
super(app, 'qoj', config.match.qoj)
}
}
24 changes: 24 additions & 0 deletions src/modules/vjudge/features/ForkContest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@ export default class ForkContest extends Feature {
this.on('/gym/<id>', (args) => { setup('gym', args.id); })
this.on('/contest/<id>', (args) => { setup('contest', args.id); })
});

this.plugin('qoj', function (this: Feature) {
this.on('/contest/<id>', () => {
const $nav = document.getElementsByClassName('nav-tabs')[0];
$nav.appendChild(htmlToElement(`<li class="nav-item"><a href="#" class="nav-link" id="cpa-copy-pid">Copy Problem IDs (VJ)</a></li>`));
$nav.appendChild(htmlToElement(`<li class="nav-item"><a href="#" class="nav-link" id="cpa-fork-contest">Fork Contest (VJ)</a></li>`));

function getProblems(): Array<VjudgeProblem> {
const problems: Array<VjudgeProblem> = [];
for (const $problemLink of document.querySelectorAll('.table-responsive')[0].querySelectorAll('table>tbody a')) {
const href = $problemLink.attributes.getNamedItem('href')!.value;
const id = href.split('/').at(-1)!;
problems.push({ oj: 'QOJ', id });
}
return problems;
}
function getContestTitle(): string {
return document.querySelector('.uoj-content .text-center h1')!.innerHTML.trim();
}

document.getElementById('cpa-copy-pid')!.onclick = async () => copyPid(getProblems());
document.getElementById('cpa-fork-contest')!.onclick = async () => forkContest(getProblems(), getContestTitle());
});
});
}

constructor(module: Module, name: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/query-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function generateQueryString(records: Dict<string>): string {
export function parseCPAData(query: string): any {
const records = parseQueryString(query);
if (!records.cpa) { return null; }
const json = atob(records.cpa);
const json = decodeURI(atob(records.cpa));
let data: any = null;
try {
data = JSON.parse(json);
Expand All @@ -44,5 +44,5 @@ export function parseCPAData(query: string): any {

export function generateCPAData(data: any): string {
const json = JSON.stringify(data);
return generateQueryString({ cpa: btoa(json) });
return generateQueryString({ cpa: btoa(encodeURI(json)) });
}

0 comments on commit 38b936d

Please sign in to comment.