Skip to content

Commit

Permalink
chore: change formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
memset0 committed Jul 22, 2024
1 parent 823e0c0 commit e4f6ad7
Show file tree
Hide file tree
Showing 16 changed files with 388 additions and 373 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnType": true
},
}
54 changes: 27 additions & 27 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ import ModuleQOJ from './modules/qoj/main';
import ModuleVjudge from './modules/vjudge/main';

export default class App {
modules: Dict<Module>;
_queuedPlugins: Dict<Array<{ feature: Feature; func: () => void }>>;
modules: Dict<Module>;
_queuedPlugins: Dict<Array<{ feature: Feature; func: () => void }>>;

log(...args: any[]) {
return console.log('[CPAssistant.js]', ...args);
}
log(...args: any[]) {
return console.log('[CPAssistant.js]', ...args);
}

apply() {
for (const name in this.modules) {
const module = this.modules[name];
if (module.match.includes(location.host)) {
module.apply();
break;
}
}
}
apply() {
for (const name in this.modules) {
const module = this.modules[name];
if (module.match.includes(location.host)) {
module.apply();
break;
}
}
}

register(module: Module) {
this.modules[module.name] = module;
if (module.name in this._queuedPlugins) {
for (const queuedPlugin of this._queuedPlugins[module.name]) {
const { feature, func } = queuedPlugin;
feature.plugin(module.name, func);
}
}
}
register(module: Module) {
this.modules[module.name] = module;
if (module.name in this._queuedPlugins) {
for (const queuedPlugin of this._queuedPlugins[module.name]) {
const { feature, func } = queuedPlugin;
feature.plugin(module.name, func);
}
}
}

constructor() {
this._queuedPlugins = {};
constructor() {
this._queuedPlugins = {};

this.modules = {};
}
this.modules = {};
}
}

export const app = new App();
Expand Down
58 changes: 29 additions & 29 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { Dict } from './utils/type'
import { Dict } from './utils/type';

const config: Dict<any> = {
match: {
codeforces: [
'codeforces.com',
'codeforc.es',
],
hdu: [
'acm.hdu.edu.cn',
],
qoj: [
'qoj.ac',
'pjudge.ac',
],
vjudge: [
'vjudge.net',
'vjudge.net.cn',
'cn.vjudge.net',
'vjudge.z180.cn',
],
},
}
match: {
codeforces: [
'codeforces.com', //
'codeforc.es',
],
hdu: [
'acm.hdu.edu.cn', //
],
qoj: [
'qoj.ac', //
'pjudge.ac',
],
vjudge: [
'vjudge.net', //
'vjudge.net.cn',
'cn.vjudge.net',
'vjudge.z180.cn',
],
},
};

config.matches = []
config.matches = [];
for (const module in config.match) {
for (const domain of config.match[module]) {
config.matches.push(`http://${domain}`)
config.matches.push(`https://${domain}`)
config.matches.push(`http://${domain}/*`)
config.matches.push(`https://${domain}/*`)
}
for (const domain of config.match[module]) {
config.matches.push(`http://${domain}`);
config.matches.push(`https://${domain}`);
config.matches.push(`http://${domain}/*`);
config.matches.push(`https://${domain}/*`);
}
}

export default config
export default config;
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { app } from './app';

app.apply();
app.apply();
17 changes: 8 additions & 9 deletions src/modules/codeforces/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import config from '../../config'
import App from '../../app'
import Module from "../../types/module"
import config from '../../config';
import App from '../../app';
import Module from '../../types/module';

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

constructor(app: App) {
super(app, 'codeforces', config.match.codeforces)
}
}
constructor(app: App) {
super(app, 'codeforces', config.match.codeforces);
}
}
17 changes: 8 additions & 9 deletions src/modules/hdu/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import config from '../../config'
import App from '../../app'
import Module from "../../types/module"
import config from '../../config';
import App from '../../app';
import Module from '../../types/module';

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

constructor(app: App) {
super(app, 'hdu', config.match.hdu)
}
}
constructor(app: App) {
super(app, 'hdu', config.match.hdu);
}
}
17 changes: 8 additions & 9 deletions src/modules/qoj/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import config from '../../config'
import App from '../../app'
import Module from "../../types/module"
import config from '../../config';
import App from '../../app';
import Module from '../../types/module';

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

constructor(app: App) {
super(app, 'qoj', config.match.qoj)
}
}
constructor(app: App) {
super(app, 'qoj', config.match.qoj);
}
}
28 changes: 14 additions & 14 deletions src/modules/vjudge/features/AcceptedCounter.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import Feature from "../../../types/feature";
import Feature from '../../../types/feature';

export default class AcceptedCounter extends Feature {
run() {
this.on('/user/*', () => {
(document.getElementsByClassName('toggle-detail')[0] as HTMLElement).onclick = () => {
for (const $tr of document.querySelectorAll('#probRecords tbody tr:not(#templ)')) {
let ojName = ($tr.children[0] as HTMLElement).innerText.trim();
let acceptedNum = $tr.children[1].children.length || 0;
let attemptedNum = $tr.children[2].children.length || 0;
$tr.children[0].innerHTML = `
run() {
this.on('/user/*', () => {
(document.getElementsByClassName('toggle-detail')[0] as HTMLElement).onclick = () => {
for (const $tr of document.querySelectorAll('#probRecords tbody tr:not(#templ)')) {
let ojName = ($tr.children[0] as HTMLElement).innerText.trim();
let acceptedNum = $tr.children[1].children.length || 0;
let attemptedNum = $tr.children[2].children.length || 0;
$tr.children[0].innerHTML = `
${ojName}
<br>
<span style="color: #999">
${acceptedNum} / ${acceptedNum + attemptedNum}
</span>
`;
console.log(ojName, acceptedNum, attemptedNum);
}
}
});
}
console.log(ojName, acceptedNum, attemptedNum);
}
};
});
}
}
Loading

0 comments on commit e4f6ad7

Please sign in to comment.