Fix the errors

This commit is contained in:
Artem Korsakov 2025-03-15 13:08:24 +03:00
parent d678c1fcef
commit 1800611519
4 changed files with 78 additions and 87 deletions

View file

@ -6,17 +6,6 @@ on:
branches: [ master ]
jobs:
format:
runs-on: ubuntu-latest
name: Check code formatting
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
- run: npm install
- run: npm run check-format
build:
runs-on: ubuntu-latest
name: Build project
@ -28,14 +17,3 @@ jobs:
node-version: 16
- run: npm install
- run: npm run build
test:
runs-on: ubuntu-latest
name: Test project
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
- run: npm install
- run: npm run test

View file

@ -39,10 +39,10 @@ export function parseAccountData(html: string): AccountData {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const account = doc.querySelector('input[name="profile_username"]')?.value || '';
const alias = doc.querySelector('input[name="profile_alias"]')?.value || '';
const location = doc.querySelector('select[name="profile_location"]')?.value || '';
const language = doc.querySelector('select[name="profile_language"]')?.value || '';
const account = (doc.querySelector('input[name="profile_username"]') as HTMLInputElement)?.value || '';
const alias = (doc.querySelector('input[name="profile_alias"]') as HTMLInputElement)?.value || '';
const location = (doc.querySelector('select[name="profile_location"]') as HTMLSelectElement)?.value || '';
const language = (doc.querySelector('select[name="profile_language"]') as HTMLSelectElement)?.value || '';
return new AccountData(account, alias, location, language);
}
@ -74,13 +74,27 @@ export function parseRatingData(html: string): RatingData {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const place = stringToNumber(doc.querySelector('#id_current > td.rank_column')?.textContent.trim() || '999999');
const top100 = stringToNumber(doc.querySelector('#main_table > tbody > tr:nth-of-type(101) > .solved_column')?.textContent);
const top50 = stringToNumber(doc.querySelector('#main_table > tbody > tr:nth-of-type(51) > .solved_column')?.textContent);
const top25 = stringToNumber(doc.querySelector('#main_table > tbody > tr:nth-of-type(26) > .solved_column')?.textContent);
const top10 = stringToNumber(doc.querySelector('#main_table > tbody > tr:nth-of-type(11) > .solved_column')?.textContent);
const top5 = stringToNumber(doc.querySelector('#main_table > tbody > tr:nth-of-type(6) > .solved_column')?.textContent);
const top1 = stringToNumber(doc.querySelector('#main_table > tbody > tr:nth-of-type(2) > .solved_column')?.textContent);
const place = stringToNumber(
doc.querySelector('#id_current > td.rank_column')?.textContent?.trim() || '999999'
);
const top100 = stringToNumber(
doc.querySelector('#main_table > tbody > tr:nth-of-type(101) > .solved_column')?.textContent?.trim() || '999999'
);
const top50 = stringToNumber(
doc.querySelector('#main_table > tbody > tr:nth-of-type(51) > .solved_column')?.textContent?.trim() || '999999'
);
const top25 = stringToNumber(
doc.querySelector('#main_table > tbody > tr:nth-of-type(26) > .solved_column')?.textContent?.trim() || '999999'
);
const top10 = stringToNumber(
doc.querySelector('#main_table > tbody > tr:nth-of-type(11) > .solved_column')?.textContent?.trim() || '999999'
);
const top5 = stringToNumber(
doc.querySelector('#main_table > tbody > tr:nth-of-type(6) > .solved_column')?.textContent?.trim() || '999999'
);
const top1 = stringToNumber(
doc.querySelector('#main_table > tbody > tr:nth-of-type(2) > .solved_column')?.textContent?.trim() || '999999'
);
return new RatingData(place, top100, top50, top25, top10, top5, top1);
}
@ -94,7 +108,7 @@ export function parseEuleriansData(html: string): string {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
return doc.querySelector('#id_current > td.rank_column')?.textContent.trim() || 'You are not in Eulerians\' rating';
return doc.querySelector('#id_current > td.rank_column')?.textContent?.trim() || 'You are not in Eulerians\' rating';
}
export function parseLevelData(html: string): LevelData[] {
@ -110,8 +124,8 @@ export function parseLevelData(html: string): LevelData[] {
const membersElement = tileBox.querySelector('.small_notice');
return new LevelData(
levelElement?.textContent.trim() ?? '',
membersElement?.textContent.trim() ?? ''
levelElement?.textContent?.trim() ?? '',
membersElement?.textContent?.trim() ?? ''
);
});
}
@ -125,7 +139,7 @@ function calculatePercentage(input: string): number {
const total = parseInt(match[2], 10);
if (total > 0) {
return ((solved / total) * 100).toFixed(2);
return parseFloat(((solved / total) * 100).toFixed(2));
}
}
@ -139,7 +153,7 @@ export function parseAwardsData(myAwardsHtml: string, awardsHtml: string): Award
const myAwardsBlockElements = myAwardsDoc.querySelectorAll('div#awards_section > div');
const awardsBlockElements = awardsDoc.querySelectorAll('div#tile_grid > div.tile_box');
const membersTextArray = Array.from(awardsBlockElements).map(el => el.outerText.trim());
const membersTextArray = Array.from(awardsBlockElements).map(el => (el as HTMLElement).outerText.trim());
const awardBlocks: AwardBlockData[] = Array.from(myAwardsBlockElements).map(myAwardsBlockElement => {
const name = myAwardsBlockElement.querySelector('h3')?.textContent || '';

View file

@ -1,48 +0,0 @@
import { PluginSettingTab, Setting } from 'obsidian';
export interface ProjectEulerStatsSettings {
session_id: string;
keep_alive: string;
}
export const DEFAULT_SETTINGS: ProjectEulerStatsSettings = {
session_id: '',
keep_alive: ''
}
export class ProjectEulerStatsSettingTab extends PluginSettingTab {
plugin: ProjectEulerStatsPlugin;
constructor(app: App, plugin: ProjectEulerStatsPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const {containerEl} = this;
containerEl.empty();
new Setting(containerEl)
.setName('Session Id')
.setDesc('Cookies Session Id')
.addText(text => text
.setPlaceholder('Enter session_id')
.setValue(this.plugin.settings.session_id)
.onChange(async (value) => {
this.plugin.settings.session_id = value;
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Keep Alive')
.setDesc('Cookies keep_alive')
.addText(text => text
.setPlaceholder('Enter keep_alive')
.setValue(this.plugin.settings.keep_alive)
.onChange(async (value) => {
this.plugin.settings.keep_alive = value;
await this.plugin.saveSettings();
}));
}
}

49
main.ts
View file

@ -1,5 +1,4 @@
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { ProjectEulerStatsSettings, DEFAULT_SETTINGS, ProjectEulerStatsSettingTab } from "helpers/settings";
import { fetchProgress } from "helpers/fetchProgress";
export default class ProjectEulerStatsPlugin extends Plugin {
@ -38,3 +37,51 @@ export default class ProjectEulerStatsPlugin extends Plugin {
await this.saveData(this.settings);
}
}
export interface ProjectEulerStatsSettings {
session_id: string;
keep_alive: string;
}
export const DEFAULT_SETTINGS: ProjectEulerStatsSettings = {
session_id: '',
keep_alive: ''
}
export class ProjectEulerStatsSettingTab extends PluginSettingTab {
plugin: ProjectEulerStatsPlugin;
constructor(app: App, plugin: ProjectEulerStatsPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const {containerEl} = this;
containerEl.empty();
new Setting(containerEl)
.setName('Session Id')
.setDesc('Cookies Session Id')
.addText(text => text
.setPlaceholder('Enter session_id')
.setValue(this.plugin.settings.session_id)
.onChange(async (value) => {
this.plugin.settings.session_id = value;
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Keep Alive')
.setDesc('Cookies keep_alive')
.addText(text => text
.setPlaceholder('Enter keep_alive')
.setValue(this.plugin.settings.keep_alive)
.onChange(async (value) => {
this.plugin.settings.keep_alive = value;
await this.plugin.saveSettings();
}));
}
}