mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-05 19:24:39 +00:00
assessmentsAverage: Fix unmarked/upcoming assessment indexing and weight display
This commit is contained in:
@@ -7,7 +7,6 @@ import {
|
|||||||
import { type Plugin } from "@/plugins/core/types";
|
import { type Plugin } from "@/plugins/core/types";
|
||||||
import stringToHTML from "@/seqta/utils/stringToHTML";
|
import stringToHTML from "@/seqta/utils/stringToHTML";
|
||||||
import { waitForElm } from "@/seqta/utils/waitForElm";
|
import { waitForElm } from "@/seqta/utils/waitForElm";
|
||||||
import ReactFiber from "@/seqta/utils/ReactFiber.ts";
|
|
||||||
import {
|
import {
|
||||||
clearStuck,
|
clearStuck,
|
||||||
getClassByPattern,
|
getClassByPattern,
|
||||||
@@ -128,6 +127,22 @@ async function renderSubjectAverage(api: any) {
|
|||||||
sampleAssessmentItem,
|
sampleAssessmentItem,
|
||||||
"AssessmentItem__title___",
|
"AssessmentItem__title___",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const assessmentItems = Array.from(
|
||||||
|
assessmentsList.querySelectorAll(
|
||||||
|
`[class*='AssessmentItem__AssessmentItem___']`,
|
||||||
|
),
|
||||||
|
).filter(
|
||||||
|
(item) =>
|
||||||
|
!item
|
||||||
|
.querySelector(`[class*='AssessmentItem__title___']`)
|
||||||
|
?.textContent?.includes("Subject Average"),
|
||||||
|
);
|
||||||
|
|
||||||
|
const { weightedTotal, totalWeight, hasInaccurateWeighting, count } =
|
||||||
|
await processAssessments(api, assessmentItems);
|
||||||
|
if (!count || totalWeight === 0) return;
|
||||||
|
|
||||||
const thermoscoreElement = document.querySelector(
|
const thermoscoreElement = document.querySelector(
|
||||||
"[class*='Thermoscore__Thermoscore___']",
|
"[class*='Thermoscore__Thermoscore___']",
|
||||||
);
|
);
|
||||||
@@ -144,24 +159,7 @@ async function renderSubjectAverage(api: any) {
|
|||||||
thermoscoreElement,
|
thermoscoreElement,
|
||||||
"Thermoscore__text___",
|
"Thermoscore__text___",
|
||||||
);
|
);
|
||||||
const state = await ReactFiber.find(
|
|
||||||
"[class*='AssessmentList__items___']",
|
|
||||||
).getState();
|
|
||||||
const marks = state["marks"];
|
|
||||||
if (!marks || !marks.length) return;
|
|
||||||
const assessmentItems = Array.from(
|
|
||||||
assessmentsList.querySelectorAll(
|
|
||||||
`[class*='AssessmentItem__AssessmentItem___']`,
|
|
||||||
),
|
|
||||||
).filter(
|
|
||||||
(item) =>
|
|
||||||
!item
|
|
||||||
.querySelector(`[class*='AssessmentItem__title___']`)
|
|
||||||
?.textContent?.includes("Subject Average"),
|
|
||||||
);
|
|
||||||
const { weightedTotal, totalWeight, hasInaccurateWeighting, count } =
|
|
||||||
await processAssessments(api, assessmentItems);
|
|
||||||
if (!count || totalWeight === 0) return;
|
|
||||||
const avg = weightedTotal / totalWeight;
|
const avg = weightedTotal / totalWeight;
|
||||||
const rounded = Math.ceil(avg / 5) * 5;
|
const rounded = Math.ceil(avg / 5) * 5;
|
||||||
const numberToLetter = Object.entries(letterToNumber).reduce(
|
const numberToLetter = Object.entries(letterToNumber).reduce(
|
||||||
|
|||||||
@@ -82,10 +82,24 @@ function createWeightLabel(
|
|||||||
assessmentItem: Element,
|
assessmentItem: Element,
|
||||||
weighting: string | undefined,
|
weighting: string | undefined,
|
||||||
) {
|
) {
|
||||||
const statsContainer = assessmentItem.querySelector(
|
let statsContainer = assessmentItem.querySelector(
|
||||||
`[class*='AssessmentItem__stats___']`,
|
`[class*='AssessmentItem__stats___']`,
|
||||||
) as HTMLElement;
|
) as HTMLElement | null;
|
||||||
if (!statsContainer) return;
|
|
||||||
|
if (!statsContainer) {
|
||||||
|
const statsClass = getClassByPattern(document, "AssessmentItem__stats___");
|
||||||
|
statsContainer = document.createElement("div");
|
||||||
|
statsContainer.className = statsClass;
|
||||||
|
statsContainer.style.justifyContent = "flex-end";
|
||||||
|
const thermoscore = assessmentItem.querySelector(`[class*='Thermoscore__Thermoscore___']`);
|
||||||
|
if (thermoscore) {
|
||||||
|
thermoscore.insertAdjacentElement("afterend", statsContainer);
|
||||||
|
} else {
|
||||||
|
assessmentItem.appendChild(statsContainer);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
statsContainer.style.justifyContent = "space-between";
|
||||||
|
}
|
||||||
|
|
||||||
const displayText =
|
const displayText =
|
||||||
weighting && weighting !== "processing" && weighting !== "N/A"
|
weighting && weighting !== "processing" && weighting !== "N/A"
|
||||||
@@ -104,31 +118,42 @@ function createWeightLabel(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const label = statsContainer.querySelector(
|
statsContainer.style.display = "flex";
|
||||||
|
statsContainer.style.alignItems = "center";
|
||||||
|
statsContainer.style.width = "100%";
|
||||||
|
|
||||||
|
// Try to clone an existing label from the stats container first,
|
||||||
|
// fall back to building from scratch if none exists
|
||||||
|
const existingNativeLabel = statsContainer.querySelector(
|
||||||
`[class*='Label__Label___']`,
|
`[class*='Label__Label___']`,
|
||||||
) as HTMLElement;
|
) as HTMLElement | null;
|
||||||
|
|
||||||
if (!label) return;
|
const weightLabel = existingNativeLabel
|
||||||
|
? (existingNativeLabel.cloneNode(true) as HTMLElement)
|
||||||
|
: (() => {
|
||||||
|
const labelClass = getClassByPattern(document, "Label__Label___");
|
||||||
|
const innerTextClass = getClassByPattern(document, "Label__innerText___");
|
||||||
|
const el = document.createElement("label");
|
||||||
|
el.className = labelClass;
|
||||||
|
el.innerHTML = `<div class="${innerTextClass}">Weight</div>`;
|
||||||
|
return el;
|
||||||
|
})();
|
||||||
|
|
||||||
const weightLabel = label.cloneNode(true) as HTMLElement;
|
|
||||||
weightLabel.classList.add("betterseqta-weight-label");
|
weightLabel.classList.add("betterseqta-weight-label");
|
||||||
|
weightLabel.style.flex = "none";
|
||||||
|
weightLabel.style.width = "fit-content";
|
||||||
|
|
||||||
const innerTextDiv = weightLabel.querySelector(
|
const innerTextDiv = weightLabel.querySelector(`[class*='Label__innerText___']`);
|
||||||
`[class*='Label__innerText___']`,
|
|
||||||
);
|
|
||||||
if (innerTextDiv) innerTextDiv.textContent = "Weight";
|
if (innerTextDiv) innerTextDiv.textContent = "Weight";
|
||||||
|
|
||||||
const textNodes = Array.from(weightLabel.childNodes).filter(
|
const textNodes = Array.from(weightLabel.childNodes).filter(
|
||||||
(node) => node.nodeType === Node.TEXT_NODE,
|
(node) => node.nodeType === Node.TEXT_NODE,
|
||||||
);
|
);
|
||||||
if (textNodes.length) textNodes[0].textContent = displayText;
|
if (textNodes.length) {
|
||||||
statsContainer.style.display = "flex";
|
textNodes[0].textContent = displayText;
|
||||||
statsContainer.style.alignItems = "center";
|
} else {
|
||||||
statsContainer.style.justifyContent = "space-between";
|
weightLabel.appendChild(document.createTextNode(displayText));
|
||||||
statsContainer.style.width = "100%";
|
}
|
||||||
|
|
||||||
weightLabel.style.flex = "none";
|
|
||||||
weightLabel.style.width = "fit-content";
|
|
||||||
|
|
||||||
statsContainer.appendChild(weightLabel);
|
statsContainer.appendChild(weightLabel);
|
||||||
}
|
}
|
||||||
@@ -525,7 +550,11 @@ export async function parseAssessments(api: any) {
|
|||||||
"[class*='AssessmentList__items___']",
|
"[class*='AssessmentList__items___']",
|
||||||
).getState();
|
).getState();
|
||||||
|
|
||||||
const marks = state["marks"];
|
const marks = [
|
||||||
|
...(state["marks"] ?? []),
|
||||||
|
...(state["upcoming"] ?? []),
|
||||||
|
...(state["pending"] ?? []),
|
||||||
|
];
|
||||||
if (!marks) return;
|
if (!marks) return;
|
||||||
|
|
||||||
await Promise.all(marks.map((mark: any) => handleWeightings(mark, api)));
|
await Promise.all(marks.map((mark: any) => handleWeightings(mark, api)));
|
||||||
@@ -538,15 +567,6 @@ export async function processAssessments(api: any, assessmentItems: Element[]) {
|
|||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
for (const assessmentItem of assessmentItems) {
|
for (const assessmentItem of assessmentItems) {
|
||||||
const gradeElement = assessmentItem.querySelector(
|
|
||||||
`[class*='Thermoscore__text___']`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!gradeElement) continue;
|
|
||||||
|
|
||||||
const grade = parseGrade(gradeElement.textContent || "");
|
|
||||||
if (grade <= 0) continue;
|
|
||||||
|
|
||||||
const titleEl = assessmentItem.querySelector(
|
const titleEl = assessmentItem.querySelector(
|
||||||
`[class*='AssessmentItem__title___']`,
|
`[class*='AssessmentItem__title___']`,
|
||||||
);
|
);
|
||||||
@@ -566,6 +586,13 @@ export async function processAssessments(api: any, assessmentItems: Element[]) {
|
|||||||
|
|
||||||
createWeightLabel(assessmentItem, weighting);
|
createWeightLabel(assessmentItem, weighting);
|
||||||
|
|
||||||
|
const gradeElement = assessmentItem.querySelector(
|
||||||
|
`[class*='Thermoscore__text___']`,
|
||||||
|
);
|
||||||
|
if (!gradeElement) continue;
|
||||||
|
const grade = parseGrade(gradeElement.textContent || "");
|
||||||
|
if (grade <= 0) continue;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
weighting === null ||
|
weighting === null ||
|
||||||
weighting === undefined ||
|
weighting === undefined ||
|
||||||
|
|||||||
Reference in New Issue
Block a user