Skip to content

Commit b0f6f7b

Browse files
committed
port cleanupGrades to the new api
1 parent dfef07e commit b0f6f7b

5 files changed

Lines changed: 119 additions & 93 deletions

File tree

src/patches/cleanupGrades/index.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { definePatch } from "@/utils/definePatch";
2+
import { waitForRender, waitForReplacement } from "@/utils/DomObservers";
3+
import { route } from "@/utils/route";
4+
5+
import css from "./style.css?inline";
6+
7+
async function hideEmptyColumns(signal: AbortSignal) {
8+
await waitForRender(
9+
() =>
10+
document.querySelector(
11+
".p-datatable-table .details-btn--appearance",
12+
),
13+
document.body,
14+
signal,
15+
);
16+
17+
const headers = document.querySelectorAll(".p-datatable-table th");
18+
19+
for (const [index] of headers.entries()) {
20+
const cells = [
21+
...document.querySelectorAll(
22+
"tbody tr td:nth-child(" + (index + 1) + ")",
23+
),
24+
];
25+
const check = cells.some((cell) => cell.textContent.trim().length > 0);
26+
27+
const columnCells = document.querySelectorAll<HTMLElement>(
28+
"tr th:nth-child("
29+
+ (index + 1)
30+
+ "), tr td:nth-child("
31+
+ (index + 1)
32+
+ ")",
33+
);
34+
for (const cell of columnCells) {
35+
cell.style.display = check ? "" : "none";
36+
}
37+
}
38+
}
39+
40+
async function prep(signal: AbortSignal) {
41+
if (window.innerWidth > 1024) {
42+
await waitForRender(
43+
() => document.querySelector(".MuiTabs-flexContainer > button"),
44+
document.body,
45+
signal,
46+
);
47+
48+
await hideEmptyColumns(signal);
49+
for (const tabButton of document.querySelectorAll(
50+
".MuiTabs-flexContainer > button",
51+
)) {
52+
tabButton.addEventListener(
53+
"click",
54+
async () => {
55+
await waitForReplacement(
56+
() =>
57+
document.querySelector(
58+
".p-datatable-table .details-btn--appearance",
59+
),
60+
document.body,
61+
signal,
62+
);
63+
await hideEmptyColumns(signal);
64+
},
65+
{ signal },
66+
);
67+
}
68+
} else {
69+
await waitForRender(
70+
() =>
71+
document.querySelector(
72+
".MuiAccordionDetails-root.accordion__full-width__content > .mobile__frame .grades__box",
73+
),
74+
document.body,
75+
signal,
76+
);
77+
const mobileFrames = document.querySelectorAll(
78+
".MuiAccordionDetails-root.accordion__full-width__content > .mobile__frame",
79+
);
80+
for (const semester of mobileFrames) {
81+
await waitForRender(
82+
() =>
83+
semester.querySelector(
84+
".MuiAccordionDetails-root .grades__box .info-row .info-text > span",
85+
),
86+
semester as HTMLElement,
87+
signal,
88+
);
89+
for (const infoRow of semester.querySelectorAll(".info-row")) {
90+
const textContent =
91+
infoRow
92+
.querySelector(".info-text > span")
93+
?.textContent.trim() ?? "";
94+
if (textContent === "" || textContent === "0") {
95+
infoRow.remove();
96+
}
97+
}
98+
}
99+
}
100+
}
101+
102+
export default definePatch({
103+
css,
104+
init: (_, signal) => prep(signal),
105+
meta: {
106+
description:
107+
"Hides subjects without any grades and columns without content.",
108+
id: "cleanup-grades",
109+
matches: [route("*/oceny")],
110+
name: "Cleanup grades table",
111+
},
112+
});
File renamed without changes.

src/patches/darkTheme/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { definePatch } from "@/utils/definePatch";
22
import { route } from "@/utils/route";
33

44
import colors from "./colors.css?inline";
5-
import eventHome from "./evHome.css?inline";
5+
import eduvulcanHome from "./evHome.css?inline";
66
import main from "./main.css?inline";
77

88
export default definePatch({
@@ -14,7 +14,7 @@ export default definePatch({
1414
"evHome-pureBlack",
1515
);
1616
},
17-
css: [main, eventHome, colors],
17+
css: [main, eduvulcanHome, colors],
1818
init(settings) {
1919
switch (settings.darkThemeEnabled) {
2020
case "auto": {
@@ -56,6 +56,7 @@ export default definePatch({
5656
matches: [route("*")],
5757
name: "Dark theme",
5858
runAt: "document_start",
59+
runStrategy: "once",
5960
settings: [
6061
{
6162
defaultValue: "auto",

src/patches/hideSubjectsWithNoGrades/finalGrades.js

Lines changed: 0 additions & 85 deletions
This file was deleted.

tests/unit/utils/SettingsManager.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import type { Meta } from "@/types/Meta.js";
55

66
import * as SettingsManager from "@/utils/SettingsManager.js";
77

8-
beforeEach(() => {
9-
beforeEach(async () => {
10-
fakeBrowser.reset();
11-
vi.resetModules();
12-
SettingsManager.resetCache();
13-
});
8+
beforeEach(async () => {
9+
fakeBrowser.reset();
10+
vi.resetModules();
11+
SettingsManager.resetCache();
1412
});
1513

1614
describe("onSettingsChange", () => {

0 commit comments

Comments
 (0)