mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
Update index.ts
This commit is contained in:
@@ -57,18 +57,9 @@ const assessmentsAveragePlugin: Plugin<typeof settings, weightingsStorage> = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasStuckProcessing) {
|
if (hasStuckProcessing) {
|
||||||
// Force update storage
|
|
||||||
api.storage.weightings = { ...api.storage.weightings };
|
api.storage.weightings = { ...api.storage.weightings };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expose globally for easy access in console: window.BetterSEQTAWeightings
|
|
||||||
(window as any).BetterSEQTAWeightings = api.storage.weightings;
|
|
||||||
|
|
||||||
// Keep it updated when weightings change
|
|
||||||
api.storage.onChange('weightings', (newWeightings) => {
|
|
||||||
(window as any).BetterSEQTAWeightings = newWeightings;
|
|
||||||
});
|
|
||||||
|
|
||||||
api.seqta.onMount(".assessmentsWrapper", async () => {
|
api.seqta.onMount(".assessmentsWrapper", async () => {
|
||||||
await waitForElm(
|
await waitForElm(
|
||||||
"#main > .assessmentsWrapper .assessments [class*='AssessmentItem__AssessmentItem___']",
|
"#main > .assessmentsWrapper .assessments [class*='AssessmentItem__AssessmentItem___']",
|
||||||
@@ -649,10 +640,7 @@ async function handleWeightings(mark: any, api: any) {
|
|||||||
// For Chrome, it uses extension context
|
// For Chrome, it uses extension context
|
||||||
text = await extractPDFText(pdfUrl);
|
text = await extractPDFText(pdfUrl);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// Handle CSP errors or other fetch issues
|
|
||||||
// Suppress Firefox blob URL CSP errors (they're warnings, not fatal)
|
|
||||||
if (isFirefox && (error?.message?.includes('blob') || error?.message?.includes('Security') || error?.message?.includes('CSP'))) {
|
if (isFirefox && (error?.message?.includes('blob') || error?.message?.includes('Security') || error?.message?.includes('CSP'))) {
|
||||||
// Try one more time with a longer delay in case PDF wasn't ready
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
try {
|
try {
|
||||||
text = await extractPDFText(pdfUrl);
|
text = await extractPDFText(pdfUrl);
|
||||||
@@ -664,17 +652,14 @@ async function handleWeightings(mark: any, api: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use regex to find the line "Assessment weight: X"
|
|
||||||
const match = text.match(/Assessment weight:\s*(\d+\.?\d*)/i);
|
const match = text.match(/Assessment weight:\s*(\d+\.?\d*)/i);
|
||||||
const weight = match ? match[1] : "N/A";
|
const weight = match ? match[1] : "N/A";
|
||||||
|
|
||||||
// Save it to storage
|
|
||||||
api.storage.weightings = {
|
api.storage.weightings = {
|
||||||
...api.storage.weightings,
|
...api.storage.weightings,
|
||||||
[assessmentID]: weight,
|
[assessmentID]: weight,
|
||||||
};
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// Catch any error and set to N/A instead of leaving as "processing"
|
|
||||||
api.storage.weightings = {
|
api.storage.weightings = {
|
||||||
...api.storage.weightings,
|
...api.storage.weightings,
|
||||||
[assessmentID]: "N/A",
|
[assessmentID]: "N/A",
|
||||||
|
|||||||
Reference in New Issue
Block a user