mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
fix: fix any type errors
This commit is contained in:
1 parent
bca273e8d4
commit
f2b6b734d0
61 files changed
+474
-280
No files matched your search
@@ -11,9 +11,9 @@ const shadowStyles = {
|
||||
export type ShadowStyleVariant = keyof typeof shadowStyles;
|
||||
|
||||
export default function renderSvelte(
|
||||
Component: Component<any>,
|
||||
Component: Component<Record<string, unknown>>,
|
||||
mountPoint: ShadowRoot | HTMLElement,
|
||||
props: Record<string, any> = {},
|
||||
props: Record<string, unknown> = {},
|
||||
shadowStyle: ShadowStyleVariant = "settings",
|
||||
) {
|
||||
if (mountPoint instanceof ShadowRoot || props.standalone === true) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { SettingsSectionId } from "./shared";
|
||||
|
||||
export const SECTION_LOADERS: Record<
|
||||
SettingsSectionId,
|
||||
() => Promise<{ default: Component<any> }>
|
||||
() => Promise<{ default: Component<Record<string, unknown>> }>
|
||||
> = {
|
||||
account: () => import("./sections/account.svelte"),
|
||||
general: () => import("./sections/generalOptions.svelte"),
|
||||
|
||||
@@ -4,6 +4,6 @@ export interface SettingsList {
|
||||
title: string;
|
||||
id: number;
|
||||
description: string;
|
||||
Component: Component<any>;
|
||||
Component: Component<Record<string, unknown>>;
|
||||
props?: Record<string, unknown>;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
activeSubjectsFromLearnPayload,
|
||||
assessmentBelongsToActiveSubjects,
|
||||
filterAssessmentsForActiveSubjects,
|
||||
type OverviewAssessment,
|
||||
type OverviewSubject,
|
||||
} from "./utils";
|
||||
|
||||
@@ -16,10 +17,15 @@ import { getMockAssessmentsData } from "@/seqta/ui/dev/hideSensitiveContent";
|
||||
import { isSeqtaEngageExperience } from "@/seqta/utils/isSeqtaEngage";
|
||||
import { getEngageAssessmentsData } from "./engageApi";
|
||||
|
||||
let cache: { time: number; engageAll?: boolean; studentId: number; data: any } | null = null;
|
||||
let cache: {
|
||||
time: number;
|
||||
engageAll?: boolean;
|
||||
studentId: number;
|
||||
data: Awaited<ReturnType<typeof getLearnAssessmentsData>>;
|
||||
} | null = null;
|
||||
const CACHE_MS = 10 * 60 * 1000;
|
||||
|
||||
async function fetchJSON(url: string, body: any) {
|
||||
async function fetchJSON(url: string, body: Record<string, unknown>) {
|
||||
const res = await fetch(`${location.origin}${url}`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
@@ -60,19 +66,22 @@ async function loadUpcoming(student: number) {
|
||||
return res.payload;
|
||||
}
|
||||
|
||||
function normalizeAssessmentDates(t: any, subject: OverviewSubject): any {
|
||||
function normalizeAssessmentDates(
|
||||
t: OverviewAssessment,
|
||||
subject: OverviewSubject,
|
||||
): OverviewAssessment {
|
||||
const normalized = { ...t };
|
||||
if (!normalized.due && (t.date || t.dueDate || t.created || t.submittedDate)) {
|
||||
normalized.due = t.date || t.dueDate || t.created || t.submittedDate;
|
||||
}
|
||||
if (!normalized.programmeID) normalized.programmeID = subject.programme;
|
||||
if (!normalized.metaclassID) normalized.metaclassID = subject.metaclass;
|
||||
if (!normalized.code && t.subject) normalized.code = t.subject;
|
||||
if (!normalized.code && typeof t.subject === "string") normalized.code = t.subject;
|
||||
return normalized;
|
||||
}
|
||||
|
||||
async function loadPast(student: number, subjects: OverviewSubject[]) {
|
||||
const map: Record<number, any> = {};
|
||||
const map: Record<number, OverviewAssessment> = {};
|
||||
await Promise.all(
|
||||
subjects.map(async (s) => {
|
||||
const res = await fetchJSON("/seqta/student/assessment/list/past?", {
|
||||
@@ -80,7 +89,7 @@ async function loadPast(student: number, subjects: OverviewSubject[]) {
|
||||
metaclass: s.metaclass,
|
||||
student,
|
||||
});
|
||||
const processAssessment = (t: any) => {
|
||||
const processAssessment = (t: OverviewAssessment) => {
|
||||
if (t && t.id) {
|
||||
const merged = {
|
||||
...t,
|
||||
@@ -102,7 +111,7 @@ async function loadPast(student: number, subjects: OverviewSubject[]) {
|
||||
return map;
|
||||
}
|
||||
|
||||
async function loadSubmissions(student: number, assessments: any[]) {
|
||||
async function loadSubmissions(student: number, assessments: OverviewAssessment[]) {
|
||||
const submissionMap: Record<number, boolean> = {};
|
||||
|
||||
await Promise.all(
|
||||
@@ -132,13 +141,13 @@ async function getLearnAssessmentsData(studentId: number) {
|
||||
loadUpcoming(studentId),
|
||||
]);
|
||||
const pastMap = await loadPast(studentId, subjects);
|
||||
const map: Record<number, any> = {};
|
||||
upcoming.forEach((a: any) => {
|
||||
const map: Record<number, OverviewAssessment> = {};
|
||||
upcoming.forEach((a: OverviewAssessment) => {
|
||||
if (assessmentBelongsToActiveSubjects(a, subjects)) {
|
||||
map[a.id] = { ...a };
|
||||
}
|
||||
});
|
||||
Object.values(pastMap).forEach((t: any) => {
|
||||
Object.values(pastMap).forEach((t: OverviewAssessment) => {
|
||||
if (!assessmentBelongsToActiveSubjects(t, subjects)) return;
|
||||
if (map[t.id]) Object.assign(map[t.id], t);
|
||||
else map[t.id] = t;
|
||||
@@ -147,7 +156,7 @@ async function getLearnAssessmentsData(studentId: number) {
|
||||
const allAssessments = filterAssessmentsForActiveSubjects(Object.values(map), subjects);
|
||||
const submissions = await loadSubmissions(studentId, allAssessments);
|
||||
|
||||
allAssessments.forEach((assessment: any) => {
|
||||
allAssessments.forEach((assessment: OverviewAssessment) => {
|
||||
assessment.submitted = submissions[assessment.id] || false;
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
activeSubjectsFromEngageChild,
|
||||
assessmentBelongsToActiveSubjects,
|
||||
filterAssessmentsForActiveSubjects,
|
||||
type OverviewAssessment,
|
||||
type OverviewSubject,
|
||||
} from "./utils";
|
||||
|
||||
@@ -87,19 +88,22 @@ async function loadEngageUpcoming(studentId: number) {
|
||||
return res.payload ?? [];
|
||||
}
|
||||
|
||||
function normalizeAssessmentDates(t: any, subject: OverviewSubject): any {
|
||||
function normalizeAssessmentDates(
|
||||
t: OverviewAssessment,
|
||||
subject: OverviewSubject,
|
||||
): OverviewAssessment {
|
||||
const normalized = { ...t };
|
||||
if (!normalized.due && (t.date || t.dueDate || t.created || t.submittedDate)) {
|
||||
normalized.due = t.date || t.dueDate || t.created || t.submittedDate;
|
||||
}
|
||||
if (!normalized.programmeID) normalized.programmeID = subject.programme;
|
||||
if (!normalized.metaclassID) normalized.metaclassID = subject.metaclass;
|
||||
if (!normalized.code && t.subject) normalized.code = t.subject;
|
||||
if (!normalized.code && typeof t.subject === "string") normalized.code = t.subject;
|
||||
return normalized;
|
||||
}
|
||||
|
||||
async function loadEngagePast(studentId: number, subjects: OverviewSubject[]) {
|
||||
const map: Record<number, any> = {};
|
||||
const map: Record<number, OverviewAssessment> = {};
|
||||
|
||||
await Promise.all(
|
||||
subjects.map(async (subject) => {
|
||||
@@ -109,7 +113,7 @@ async function loadEngagePast(studentId: number, subjects: OverviewSubject[]) {
|
||||
student: studentId,
|
||||
});
|
||||
|
||||
const processAssessment = (task: any) => {
|
||||
const processAssessment = (task: OverviewAssessment) => {
|
||||
if (task?.id) {
|
||||
const merged = {
|
||||
...task,
|
||||
@@ -133,7 +137,7 @@ async function loadEngagePast(studentId: number, subjects: OverviewSubject[]) {
|
||||
return map;
|
||||
}
|
||||
|
||||
async function loadEngageSubmissions(studentId: number, assessments: any[]) {
|
||||
async function loadEngageSubmissions(studentId: number, assessments: OverviewAssessment[]) {
|
||||
const submissionMap: Record<number, boolean> = {};
|
||||
|
||||
await Promise.all(
|
||||
@@ -158,7 +162,7 @@ async function loadEngageSubmissions(studentId: number, assessments: any[]) {
|
||||
return submissionMap;
|
||||
}
|
||||
|
||||
async function loadEngageAssessmentsForStudent(child: EngageChildPayload): Promise<any[]> {
|
||||
async function loadEngageAssessmentsForStudent(child: EngageChildPayload): Promise<OverviewAssessment[]> {
|
||||
const studentId = Number(child.id);
|
||||
const studentName = child.name ?? "Student";
|
||||
const subjects = subjectsFromChild(child);
|
||||
@@ -167,13 +171,13 @@ async function loadEngageAssessmentsForStudent(child: EngageChildPayload): Promi
|
||||
loadEngagePast(studentId, subjects),
|
||||
]);
|
||||
|
||||
const map: Record<number, any> = {};
|
||||
upcoming.forEach((assessment: any) => {
|
||||
const map: Record<number, OverviewAssessment> = {};
|
||||
upcoming.forEach((assessment: OverviewAssessment) => {
|
||||
if (assessmentBelongsToActiveSubjects(assessment, subjects)) {
|
||||
map[assessment.id] = { ...assessment };
|
||||
}
|
||||
});
|
||||
Object.values(pastMap).forEach((task: any) => {
|
||||
Object.values(pastMap).forEach((task: OverviewAssessment) => {
|
||||
if (!assessmentBelongsToActiveSubjects(task, subjects)) return;
|
||||
if (map[task.id]) Object.assign(map[task.id], task);
|
||||
else map[task.id] = task;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import renderSvelte from "@/interface/main";
|
||||
import { getAssessmentsData } from "./api";
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
import AssessmentsOverview from "./AssessmentsOverview.svelte";
|
||||
import SkeletonLoader from "./SkeletonLoader.svelte";
|
||||
import ErrorState from "./ErrorState.svelte";
|
||||
import { unmount } from "svelte";
|
||||
|
||||
let currentApp: any = null;
|
||||
let currentApp: ReturnType<typeof renderSvelte> | null = null;
|
||||
let themeObserver: MutationObserver | null = null;
|
||||
type ThemeSettingKey =
|
||||
| "selectedColor"
|
||||
@@ -111,7 +112,10 @@ function prepareContainer(container: HTMLElement) {
|
||||
watchOverviewTheme(container);
|
||||
}
|
||||
|
||||
export function renderGrid(container: HTMLElement, data: any) {
|
||||
export function renderGrid(
|
||||
container: HTMLElement,
|
||||
data: Awaited<ReturnType<typeof getAssessmentsData>>,
|
||||
) {
|
||||
if (currentApp) unmount(currentApp);
|
||||
prepareContainer(container);
|
||||
currentApp = renderSvelte(AssessmentsOverview, container, { data });
|
||||
|
||||
@@ -86,6 +86,7 @@ const globalSearchPlugin = defineLazyPlugin({
|
||||
});
|
||||
|
||||
const runGlobalSearch = globalSearchPlugin.run!;
|
||||
export type GlobalSearchApi = Parameters<typeof runGlobalSearch>[0];
|
||||
|
||||
globalSearchPlugin.run = async (api) => {
|
||||
if (isSeqtaEngageExperience() || isSeqtaLoginPage()) return () => {};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { HomeTimetableLesson } from "@/seqta/utils/loaders/homePageTypes";
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
import { loadHomePage } from "@/seqta/utils/loaders/LoadHomePage";
|
||||
import { waitForElm } from "@/seqta/utils/waitForElm";
|
||||
@@ -39,7 +40,7 @@ async function getCurrentLesson() {
|
||||
return null;
|
||||
}
|
||||
|
||||
const lessons = timetableData.payload.items.sort((a: any, b: any) =>
|
||||
const lessons = (timetableData.payload.items as HomeTimetableLesson[]).sort((a, b) =>
|
||||
a.from.localeCompare(b.from),
|
||||
);
|
||||
|
||||
@@ -69,7 +70,7 @@ async function getCurrentLesson() {
|
||||
}
|
||||
}
|
||||
|
||||
async function navigateToSpecificLesson(lesson: any) {
|
||||
async function navigateToSpecificLesson(lesson: HomeTimetableLesson) {
|
||||
try {
|
||||
await waitForElm(".course .navigator", true, 100, 100);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ const globalSearchPlugin: Pick<Plugin<GlobalSearchSettings>, "run"> = {
|
||||
"[Global Search] Extension updated — search index reset; the next indexing pass will repopulate.",
|
||||
);
|
||||
}
|
||||
} catch (error: any) {
|
||||
} catch (error: unknown) {
|
||||
const msg = error?.message ?? "";
|
||||
if (
|
||||
msg.includes("preload CSS") ||
|
||||
|
||||
@@ -4,12 +4,17 @@ import { warmUpVectorSearchOnInteraction } from "../search/vector/vectorSearch";
|
||||
import { formatHotkeyForDisplay, isValidHotkey } from "../utils/hotkeyUtils";
|
||||
import { waitForElm } from "@/seqta/utils/waitForElm";
|
||||
import { transparencyEnabled } from "@/seqta/utils/performanceMode";
|
||||
import renderSvelte from "@/interface/main";
|
||||
import type { GlobalSearchApi } from "../../lazy";
|
||||
import browser from "@/lib/browser";
|
||||
|
||||
type AppRef = {
|
||||
current: any;
|
||||
storageChangeHandler?: any;
|
||||
progressHandler?: any;
|
||||
current: ReturnType<typeof renderSvelte> | null;
|
||||
storageChangeHandler?: (
|
||||
changes: Record<string, browser.storage.StorageChange>,
|
||||
area: string,
|
||||
) => void;
|
||||
progressHandler?: ((event: Event) => void) | null;
|
||||
clearDoneFlashTimer?: () => void;
|
||||
clickHandler?: () => void;
|
||||
ownedTrigger?: boolean;
|
||||
@@ -75,7 +80,7 @@ function triggerParts(searchWrapper: HTMLElement) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function mountSearchBar(titleElement: Element, api: any, appRef: AppRef) {
|
||||
export async function mountSearchBar(titleElement: Element, api: GlobalSearchApi, appRef: AppRef) {
|
||||
const preRendered = await resolveTriggerWrapper(titleElement);
|
||||
if (preRendered?.dataset.bsplusSearchWired === "1") return;
|
||||
|
||||
@@ -246,7 +251,10 @@ export async function mountSearchBar(titleElement: Element, api: any, appRef: Ap
|
||||
}
|
||||
searchWrapper.dataset.bsplusSearchWired = "1";
|
||||
|
||||
const handleStorageChange = (changes: any, area: string) => {
|
||||
const handleStorageChange = (
|
||||
changes: Record<string, browser.storage.StorageChange>,
|
||||
area: string,
|
||||
) => {
|
||||
if (area !== "local" || !changes["plugin.global-search.settings"]) return;
|
||||
const next = changes["plugin.global-search.settings"].newValue as
|
||||
| { searchHotkey?: string }
|
||||
@@ -265,8 +273,9 @@ export async function mountSearchBar(titleElement: Element, api: any, appRef: Ap
|
||||
|
||||
const clickHandler = () => {
|
||||
warmUpVectorSearchOnInteraction();
|
||||
// @ts-ignore
|
||||
window.setCommandPalleteOpen(true);
|
||||
(window as Window & { setCommandPalleteOpen?: (open: boolean) => void }).setCommandPalleteOpen?.(
|
||||
true,
|
||||
);
|
||||
};
|
||||
searchButton.addEventListener("click", clickHandler);
|
||||
appRef.clickHandler = clickHandler;
|
||||
|
||||
@@ -27,7 +27,9 @@ interface AssessmentMetadata {
|
||||
author?: string;
|
||||
}
|
||||
|
||||
type ActionHandler<T = any> = (item: IndexItem & { metadata: T }) => void;
|
||||
type ActionHandler<T extends Record<string, unknown> = Record<string, unknown>> = (
|
||||
item: IndexItem & { metadata: T },
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* Navigate to a SEQTA SPA hash route in the most reliable way available.
|
||||
@@ -63,7 +65,7 @@ function navigateInCurrentSeqtaApp(routeWithLeadingSlash: string): void {
|
||||
*/
|
||||
const FALLBACK_ROUTE = "/dashboard";
|
||||
|
||||
export const actionMap: Record<string, ActionHandler<any>> = {
|
||||
export const actionMap: Record<string, ActionHandler<Record<string, unknown>>> = {
|
||||
message: (async (item: IndexItem & { metadata: MessageMetadata }) => {
|
||||
window.location.hash = `#?page=/messages`;
|
||||
|
||||
@@ -91,7 +93,7 @@ export const actionMap: Record<string, ActionHandler<any>> = {
|
||||
if (button) {
|
||||
(button as HTMLElement).click();
|
||||
}
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
assessment: (async (item: IndexItem & { metadata: AssessmentMetadata }) => {
|
||||
// Deep clone the entire item to avoid Firefox XrayWrapper issues
|
||||
@@ -123,8 +125,8 @@ export const actionMap: Record<string, ActionHandler<any>> = {
|
||||
// The metadata bag is intentionally typed loosely here because Firefox's
|
||||
// XrayWrapper occasionally surfaces extra/casing-variant keys we still
|
||||
// want to read defensively.
|
||||
const getMetadataValue = (key: string, altKey?: string): any => {
|
||||
const bag = metadata as unknown as Record<string, any>;
|
||||
const getMetadataValue = (key: string, altKey?: string): unknown => {
|
||||
const bag = metadata as Record<string, unknown>;
|
||||
try {
|
||||
const value = bag[key];
|
||||
if (value !== undefined && value !== null) {
|
||||
@@ -240,19 +242,19 @@ export const actionMap: Record<string, ActionHandler<any>> = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
subjectassessment: ((item: IndexItem) => {
|
||||
navigateToHashRoute(`/assessments/${item.metadata.programme}:${item.metadata.subjectId}`);
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
subjectcourse: ((item: IndexItem) => {
|
||||
navigateToHashRoute(`/courses/${item.metadata.programme}:${item.metadata.subjectId}`);
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
forum: ((item: IndexItem) => {
|
||||
navigateToHashRoute(`/forums/${item.metadata.forumId}`);
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
course: ((item: IndexItem) => {
|
||||
const programme = item.metadata?.programme;
|
||||
@@ -266,28 +268,28 @@ export const actionMap: Record<string, ActionHandler<any>> = {
|
||||
return;
|
||||
}
|
||||
navigateToHashRoute(FALLBACK_ROUTE);
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
notice: ((_item: IndexItem) => {
|
||||
notice: (() => {
|
||||
// SEQTA's notices route doesn't honour `&date=` from the hash, so just
|
||||
// open the listing.
|
||||
navigateToHashRoute("/notices");
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
document: ((_item: IndexItem) => {
|
||||
document: (() => {
|
||||
// We don't trigger downloads automatically: opening the documents page
|
||||
// gives users full SEQTA controls (preview, download, share) without
|
||||
// needing the JWT-stamped streaming URL we deliberately avoid storing.
|
||||
navigateToHashRoute("/documents");
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
folio: ((_item: IndexItem) => {
|
||||
folio: (() => {
|
||||
// SEQTA's folio SPA does not expose a per-id route; the previous
|
||||
// `?page=/folios/read?id=N` shape contained a literal `?` inside the
|
||||
// `page` query value and was unmatchable, which sent users to the
|
||||
// dashboard. Always land on the read view and let the user pick.
|
||||
navigateToHashRoute("/folios/read");
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
portal: ((item: IndexItem) => {
|
||||
// SEQTA renders portals via the in-app viewer at `?page=/portals/<uuid>`
|
||||
@@ -305,11 +307,11 @@ export const actionMap: Record<string, ActionHandler<any>> = {
|
||||
return;
|
||||
}
|
||||
navigateToHashRoute(FALLBACK_ROUTE);
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
report: ((_item: IndexItem) => {
|
||||
report: (() => {
|
||||
navigateToHashRoute("/reports");
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
goal: ((item: IndexItem) => {
|
||||
const year = item.metadata?.year;
|
||||
@@ -318,7 +320,7 @@ export const actionMap: Record<string, ActionHandler<any>> = {
|
||||
} else {
|
||||
navigateToHashRoute("/goals");
|
||||
}
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
|
||||
/**
|
||||
* Routes for passively-captured items.
|
||||
@@ -450,5 +452,5 @@ export const actionMap: Record<string, ActionHandler<any>> = {
|
||||
}
|
||||
|
||||
navigateToHashRoute(FALLBACK_ROUTE);
|
||||
}) as ActionHandler<any>,
|
||||
}) as ActionHandler<Record<string, unknown>>,
|
||||
};
|
||||
@@ -12,7 +12,7 @@ import { delay } from "@/seqta/utils/delay";
|
||||
* per-subject course crawls) from hammering SEQTA.
|
||||
*/
|
||||
|
||||
export interface SeqtaResponse<T = any> {
|
||||
export interface SeqtaResponse<T = unknown> {
|
||||
payload: T;
|
||||
status: string;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ function isTransientError(err: unknown): boolean {
|
||||
return false;
|
||||
}
|
||||
if (err instanceof TypeError) return true;
|
||||
if ((err as any)?.name === "AbortError") return false;
|
||||
if (err instanceof Error && err.name === "AbortError") return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ function isTransientError(err: unknown): boolean {
|
||||
* the SEQTA convention; jobs that need raw payloads can pass `path` but
|
||||
* call `seqtaFetch` directly via the underlying API if they need to).
|
||||
*/
|
||||
export async function seqtaFetchJson<T = any>(
|
||||
export async function seqtaFetchJson<T = unknown>(
|
||||
path: string,
|
||||
body: Record<string, unknown> | undefined = {},
|
||||
options: SeqtaFetchOptions = {},
|
||||
@@ -293,7 +293,7 @@ export async function seqtaFetchJson<T = any>(
|
||||
* Convenience helper: fetch and unwrap `.payload` directly. Returns `null`
|
||||
* on failure rather than throwing, so jobs can use the value optionally.
|
||||
*/
|
||||
export async function seqtaFetchPayload<T = any>(
|
||||
export async function seqtaFetchPayload<T = unknown>(
|
||||
path: string,
|
||||
body: Record<string, unknown> | undefined = {},
|
||||
options: SeqtaFetchOptions = {},
|
||||
|
||||
@@ -319,7 +319,7 @@ async function withObjectStore<T>(
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getAll(store: string): Promise<any[]> {
|
||||
export async function getAll(store: string): Promise<unknown[]> {
|
||||
try {
|
||||
return await withObjectStore(store, "readonly", async (s) => idbRequest(s.getAll()));
|
||||
} catch (error) {
|
||||
@@ -328,7 +328,7 @@ export async function getAll(store: string): Promise<any[]> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function get(store: string, key: string): Promise<any> {
|
||||
export async function get(store: string, key: string): Promise<unknown> {
|
||||
try {
|
||||
return await withObjectStore(store, "readonly", async (s) => idbRequest(s.get(key)));
|
||||
} catch (error) {
|
||||
@@ -337,7 +337,7 @@ export async function get(store: string, key: string): Promise<any> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function put(store: string, value: any, key?: string): Promise<void> {
|
||||
export async function put(store: string, value: unknown, key?: string): Promise<void> {
|
||||
try {
|
||||
await withObjectStore(store, "readwrite", async (s) => {
|
||||
await idbRequest(key ? s.put(value, key) : s.put(value));
|
||||
@@ -350,7 +350,7 @@ export async function put(store: string, value: any, key?: string): Promise<void
|
||||
|
||||
export async function applyStoreDiff(
|
||||
store: string,
|
||||
puts: Array<{ key: string; value: any }>,
|
||||
puts: Array<{ key: string; value: unknown }>,
|
||||
removeKeys: string[],
|
||||
): Promise<void> {
|
||||
if (puts.length === 0 && removeKeys.length === 0) return;
|
||||
@@ -371,7 +371,7 @@ export async function applyStoreDiff(
|
||||
function runStoreDiffTransaction(
|
||||
db: IDBDatabase,
|
||||
store: string,
|
||||
puts: Array<{ key: string; value: any }>,
|
||||
puts: Array<{ key: string; value: unknown }>,
|
||||
removeKeys: string[],
|
||||
): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -54,12 +54,12 @@ async function ensureSchemaCurrent(): Promise<void> {
|
||||
|
||||
export { ensureSchemaCurrent };
|
||||
|
||||
async function loadProgress<T = any>(jobId: string): Promise<T | undefined> {
|
||||
async function loadProgress<T = unknown>(jobId: string): Promise<T | undefined> {
|
||||
const rec = await get(META_STORE, `progress:${jobId}`);
|
||||
return rec?.progress as T | undefined;
|
||||
}
|
||||
|
||||
async function saveProgress<T = any>(jobId: string, progress: T): Promise<void> {
|
||||
async function saveProgress<T = unknown>(jobId: string, progress: T): Promise<void> {
|
||||
await put(META_STORE, { progress }, `progress:${jobId}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,12 @@ import type { IndexItem, Job } from "../types";
|
||||
import { verboseDebug } from "@/utils/verboseLog";
|
||||
import { delay } from "@/seqta/utils/delay";
|
||||
import { getUserInfo } from "@/seqta/utils/userInfo";
|
||||
const fetchJSON = async (url: string, body: any) => {
|
||||
import {
|
||||
type OverviewAssessment,
|
||||
type OverviewSubject,
|
||||
} from "@/plugins/built-in/assessmentsOverview/utils";
|
||||
|
||||
const fetchJSON = async (url: string, body: Record<string, unknown>) => {
|
||||
const res = await fetch(`${location.origin}${url}`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
@@ -28,15 +33,22 @@ const fetchUpcomingAssessments = async (student: number) => {
|
||||
const fetchSubjects = async () => {
|
||||
try {
|
||||
const res = await fetchJSON("/seqta/student/load/subjects?", {});
|
||||
return res.payload?.filter((s: any) => s.active === 1)?.flatMap((s: any) => s.subjects) || [];
|
||||
const payload = res.payload as Record<string, unknown>[] | undefined;
|
||||
return (
|
||||
payload
|
||||
?.filter((s) => s.active === 1)
|
||||
?.flatMap((s) =>
|
||||
Array.isArray(s.subjects) ? (s.subjects as OverviewSubject[]) : [],
|
||||
) ?? []
|
||||
);
|
||||
} catch (e) {
|
||||
console.error("[Assignments job] Failed to fetch subjects:", e);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const fetchPastAssessments = async (student: number, subjects: any[]) => {
|
||||
const map: Record<number, any> = {};
|
||||
const fetchPastAssessments = async (student: number, subjects: OverviewSubject[]) => {
|
||||
const map: Record<number, OverviewAssessment> = {};
|
||||
|
||||
await Promise.all(
|
||||
subjects.map(async (subject) => {
|
||||
@@ -48,15 +60,16 @@ const fetchPastAssessments = async (student: number, subjects: any[]) => {
|
||||
});
|
||||
|
||||
// Past assessments can come back in payload.tasks, payload.pending, or both.
|
||||
const processAssessment = (assessment: any) => {
|
||||
if (assessment && assessment.id) {
|
||||
map[assessment.id] = {
|
||||
const processAssessment = (assessment: OverviewAssessment) => {
|
||||
if (assessment && assessment.id != null) {
|
||||
const id = Number(assessment.id);
|
||||
map[id] = {
|
||||
...assessment,
|
||||
programme: assessment.programme || assessment.programmeID || subject.programme,
|
||||
programmeID: assessment.programmeID || assessment.programme || subject.programme,
|
||||
metaclass: assessment.metaclass || assessment.metaclassID || subject.metaclass,
|
||||
metaclassID: assessment.metaclassID || assessment.metaclass || subject.metaclass,
|
||||
};
|
||||
} as OverviewAssessment;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -137,15 +150,15 @@ export const assignmentsJob: Job = {
|
||||
verboseDebug(`[Assignments job] Fetched ${past.length} past assessments`);
|
||||
|
||||
const subjectLookup = new Map<string, { programme: number; metaclass: number }>();
|
||||
subjects.forEach((s: any) => {
|
||||
subjects.forEach((s: OverviewSubject) => {
|
||||
if (s.code && s.programme && s.metaclass) {
|
||||
subjectLookup.set(s.code, { programme: s.programme, metaclass: s.metaclass });
|
||||
}
|
||||
});
|
||||
|
||||
const allAssessments = new Map<number, any>();
|
||||
const allAssessments = new Map<number, OverviewAssessment>();
|
||||
|
||||
upcoming.forEach((a: any) => {
|
||||
upcoming.forEach((a: OverviewAssessment) => {
|
||||
if (a && a.id) {
|
||||
let programme = a.programmeID || a.programme;
|
||||
let metaclass = a.metaclassID || a.metaclass;
|
||||
@@ -169,7 +182,7 @@ export const assignmentsJob: Job = {
|
||||
}
|
||||
});
|
||||
|
||||
past.forEach((a: any) => {
|
||||
past.forEach((a: OverviewAssessment) => {
|
||||
if (a && a.id) {
|
||||
let programme = a.programmeID || a.programme;
|
||||
let metaclass = a.metaclassID || a.metaclass;
|
||||
|
||||
@@ -9,7 +9,7 @@ const fetchForums = async () => {
|
||||
});
|
||||
|
||||
return res.json() as Promise<{
|
||||
payload: { forums: any[] };
|
||||
payload: { forums: Record<string, unknown>[] };
|
||||
status: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { IndexItem, Job } from "../types";
|
||||
import type { IndexItem, Job, JobContext } from "../types";
|
||||
import { htmlToPlainText } from "../utils";
|
||||
import { delay } from "@/seqta/utils/delay";
|
||||
import { VectorWorkerManager } from "../worker/vectorWorkerManager";
|
||||
@@ -56,7 +56,7 @@ const fetchMessages = async (offset = 0, limit = 100) => {
|
||||
}),
|
||||
});
|
||||
return res.json() as Promise<{
|
||||
payload: { hasMore: boolean; messages: any[]; ts: string };
|
||||
payload: { hasMore: boolean; messages: Record<string, unknown>[]; ts: string };
|
||||
status: string;
|
||||
}>;
|
||||
};
|
||||
@@ -188,11 +188,11 @@ function checkCircuitBreaker(progress: MessagesProgress): boolean {
|
||||
}
|
||||
|
||||
async function processMessagesInParallel(
|
||||
messages: any[],
|
||||
messages: Record<string, unknown>[],
|
||||
existingIds: Set<string>,
|
||||
processedIdsSet: Set<string>,
|
||||
progress: MessagesProgress,
|
||||
ctx: any,
|
||||
ctx: JobContext,
|
||||
): Promise<{
|
||||
processedItems: IndexItem[];
|
||||
consecutiveExisting: number;
|
||||
|
||||
@@ -56,7 +56,8 @@ const fetchNoticesForDate = async (date: string): Promise<NoticeRecord[]> => {
|
||||
);
|
||||
if (!payload) return [];
|
||||
if (Array.isArray(payload)) return payload;
|
||||
if (Array.isArray((payload as any).notices)) return (payload as any).notices;
|
||||
const wrapped = payload as { notices?: NoticeRecord[] };
|
||||
if (Array.isArray(wrapped.notices)) return wrapped.notices;
|
||||
return [];
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { IndexItem, Job } from "../types";
|
||||
import type { IndexItem, Job, JobContext } from "../types";
|
||||
import { htmlToPlainText } from "../utils";
|
||||
import { fetchMessageContent } from "./messages";
|
||||
import { delay } from "@/seqta/utils/delay";
|
||||
@@ -40,6 +40,13 @@ interface AssessmentNotification {
|
||||
|
||||
type Notification = MessageNotification | AssessmentNotification;
|
||||
|
||||
type AssessmentTitleRef = { id?: number; title?: string };
|
||||
type AssessmentListPayload = {
|
||||
syllabus?: { assessments?: AssessmentTitleRef[] }[];
|
||||
pending?: AssessmentTitleRef[];
|
||||
tasks?: AssessmentTitleRef[];
|
||||
};
|
||||
|
||||
interface NotificationsProgress {
|
||||
lastTs: number;
|
||||
failedRequests: number;
|
||||
@@ -67,17 +74,17 @@ const fetchAssessmentName = async (
|
||||
programmeId: number,
|
||||
retryCount = 0,
|
||||
): Promise<string> => {
|
||||
const searchAssessment = (data: any): string | null => {
|
||||
const searchAssessment = (data: AssessmentListPayload): string | null => {
|
||||
for (const item of data.syllabus || []) {
|
||||
const found = (item.assessments || []).find((a: any) => a.id === assessmentId);
|
||||
if (found) return found.title;
|
||||
const found = (item.assessments || []).find((a) => a.id === assessmentId);
|
||||
if (found?.title) return found.title;
|
||||
}
|
||||
|
||||
const foundPending = (data.pending || []).find((a: any) => a.id === assessmentId);
|
||||
if (foundPending) return foundPending.title;
|
||||
const foundPending = (data.pending || []).find((a) => a.id === assessmentId);
|
||||
if (foundPending?.title) return foundPending.title;
|
||||
|
||||
const foundTask = (data.tasks || []).find((a: any) => a.id === assessmentId);
|
||||
if (foundTask) return foundTask.title;
|
||||
const foundTask = (data.tasks || []).find((a) => a.id === assessmentId);
|
||||
if (foundTask?.title) return foundTask.title;
|
||||
|
||||
return null;
|
||||
};
|
||||
@@ -125,8 +132,11 @@ const fetchAssessmentName = async (
|
||||
await delay(NOTIFICATIONS_RATE_LIMIT.baseDelay);
|
||||
|
||||
const upcomingPayload = await fetchAssessments("/seqta/student/assessment/list/upcoming");
|
||||
const foundUpcoming = (upcomingPayload || []).find((a: any) => a.id === assessmentId);
|
||||
if (foundUpcoming) return foundUpcoming.title;
|
||||
const upcomingList = Array.isArray(upcomingPayload)
|
||||
? (upcomingPayload as AssessmentTitleRef[])
|
||||
: [];
|
||||
const foundUpcoming = upcomingList.find((a) => a.id === assessmentId);
|
||||
if (foundUpcoming?.title) return foundUpcoming.title;
|
||||
|
||||
throw new Error(`Assessment with ID ${assessmentId} not found in past or upcoming.`);
|
||||
} catch (error) {
|
||||
@@ -387,7 +397,7 @@ export const notificationsJob: Job = {
|
||||
|
||||
async function processNotification(
|
||||
notif: Notification,
|
||||
ctx: any,
|
||||
ctx: JobContext,
|
||||
): Promise<{ success: boolean; item?: IndexItem }> {
|
||||
const id = notif.notificationID.toString();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { IndexItem } from "./types";
|
||||
import { getAll, put } from "./db";
|
||||
import { buildIndexItem, extractTextFromValue, pickId, pickTitle } from "./extract";
|
||||
import { asXhrWithBsplusMeta } from "@/seqta/utils/xhrBsplusMeta";
|
||||
import { verboseDebug } from "@/utils/verboseLog";
|
||||
import { isSensitiveSeqtaPath, normalizeSeqtaPath } from "./api";
|
||||
import { mergeDynamicItems } from "../utils/dynamicItems";
|
||||
@@ -515,7 +516,7 @@ export function installPassiveObserver(): void {
|
||||
};
|
||||
|
||||
// Best-effort XHR hook for the rare callers that bypass fetch.
|
||||
const ProtoXhr = (window as any).XMLHttpRequest?.prototype;
|
||||
const ProtoXhr = XMLHttpRequest.prototype;
|
||||
if (ProtoXhr) {
|
||||
const originalOpen = ProtoXhr.open;
|
||||
const originalSend = ProtoXhr.send;
|
||||
@@ -523,19 +524,20 @@ export function installPassiveObserver(): void {
|
||||
this: XMLHttpRequest,
|
||||
method: string,
|
||||
url: string,
|
||||
...rest: any[]
|
||||
...rest: unknown[]
|
||||
) {
|
||||
try {
|
||||
(this as any).__bsplusUrl = url;
|
||||
(this as any).__bsplusMethod = method;
|
||||
const xhr = asXhrWithBsplusMeta(this);
|
||||
xhr.__bsplusUrl = url;
|
||||
xhr.__bsplusMethod = method;
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
return originalOpen.call(this, method, url, ...rest);
|
||||
return originalOpen.apply(this, [method, url, ...rest] as Parameters<typeof originalOpen>);
|
||||
};
|
||||
ProtoXhr.send = function patchedSend(this: XMLHttpRequest, body?: any) {
|
||||
ProtoXhr.send = function patchedSend(this: XMLHttpRequest, body?: Document | XMLHttpRequestBodyInit | null) {
|
||||
try {
|
||||
const url = (this as any).__bsplusUrl as string | undefined;
|
||||
const url = asXhrWithBsplusMeta(this).__bsplusUrl;
|
||||
if (url && isSameOriginSeqtaUrl(url)) {
|
||||
const parsed = typeof body === "string" ? tryParseJson(body) : undefined;
|
||||
this.addEventListener("load", () => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { IndexItem } from "./types";
|
||||
import { jobs } from "./jobs";
|
||||
import { loadDynamicItems } from "../utils/dynamicItems";
|
||||
|
||||
export const renderComponentMap: Record<string, Component<any>> = {
|
||||
export const renderComponentMap: Record<string, Component<Record<string, unknown>>> = {
|
||||
assessment: AssessmentItem,
|
||||
message: AssessmentItem,
|
||||
forum: ForumItem,
|
||||
@@ -26,7 +26,7 @@ export const renderComponentMap: Record<string, Component<any>> = {
|
||||
passive: GenericItem,
|
||||
};
|
||||
|
||||
function resolveRenderComponent(item: IndexItem): Component<any> | undefined {
|
||||
function resolveRenderComponent(item: IndexItem): Component<Record<string, unknown>> | undefined {
|
||||
const jobDef =
|
||||
jobs[item.category] ||
|
||||
Object.values(jobs).find((j) => j.id === item.category) ||
|
||||
|
||||
@@ -6,10 +6,10 @@ export interface IndexItem {
|
||||
category: string;
|
||||
content: string;
|
||||
dateAdded: number;
|
||||
metadata: Record<string, any>;
|
||||
metadata: Record<string, unknown>;
|
||||
actionId: string;
|
||||
renderComponentId: string;
|
||||
renderComponent?: Component<any>;
|
||||
renderComponent?: Component<Record<string, unknown>>;
|
||||
}
|
||||
|
||||
export type Frequency =
|
||||
@@ -22,8 +22,8 @@ export interface JobContext {
|
||||
setStoredItems: (items: IndexItem[], storeId?: string) => Promise<void>;
|
||||
addItem: (item: IndexItem, storeId?: string) => Promise<void>;
|
||||
removeItem: (id: string, storeId?: string) => Promise<void>;
|
||||
getProgress: <T = any>() => Promise<T | undefined>;
|
||||
setProgress: <T = any>(progress: T) => Promise<void>;
|
||||
getProgress: <T = unknown>() => Promise<T | undefined>;
|
||||
setProgress: <T = unknown>(progress: T) => Promise<void>;
|
||||
/** Optional live status/progress while a long-running job is in flight. */
|
||||
reportJobProgress?: (detail: { processed: number; total: number; status?: string }) => void;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import browser from "@/lib/browser";
|
||||
export function isFirefox(): boolean {
|
||||
try {
|
||||
// Firefox-specific API
|
||||
if (typeof (browser.runtime as any).getBrowserInfo === "function") {
|
||||
if (typeof (browser.runtime as typeof browser.runtime & { getBrowserInfo?: () => unknown }).getBrowserInfo === "function") {
|
||||
return true;
|
||||
}
|
||||
// Fallback: check user agent
|
||||
|
||||
@@ -7,10 +7,10 @@ export interface DynamicContentItem {
|
||||
category: string;
|
||||
content: string;
|
||||
dateAdded: number;
|
||||
metadata: Record<string, any>;
|
||||
metadata: Record<string, unknown>;
|
||||
actionId: string;
|
||||
renderComponentId: string;
|
||||
renderComponent?: Component<any>;
|
||||
renderComponent?: Component<Record<string, unknown>>;
|
||||
}
|
||||
|
||||
let dynamicItems: IndexItem[] = [];
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
clearThemeCreatorLayout,
|
||||
} from "@/plugins/built-in/themes/themeCreatorLayout";
|
||||
|
||||
let themeCreatorSvelteApp: any = null;
|
||||
let themeCreatorSvelteApp: Parameters<typeof unmount>[0] | null = null;
|
||||
let currentWidthPx = 400;
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,9 +57,13 @@ function createSettingsAPI<T extends PluginSettings>(
|
||||
dispose: () => void;
|
||||
} {
|
||||
const storageKey = `plugin.${plugin.id}.settings`;
|
||||
const listeners = new Map<keyof T, Set<(value: any) => void>>();
|
||||
const listeners = new Map<keyof T, Set<(value: SettingValue<T[keyof T]>) => void>>();
|
||||
|
||||
const settingsWithMeta: any = {
|
||||
const settingsWithMeta: Record<string, unknown> & {
|
||||
onChange: SettingsAPI<T>["onChange"];
|
||||
offChange: SettingsAPI<T>["offChange"];
|
||||
loaded: Promise<void>;
|
||||
} = {
|
||||
onChange: <K extends keyof T>(key: K, callback: (value: SettingValue<T[K]>) => void) => {
|
||||
if (!listeners.has(key)) {
|
||||
listeners.set(key, new Set());
|
||||
@@ -87,7 +91,7 @@ function createSettingsAPI<T extends PluginSettings>(
|
||||
const loaded = (async () => {
|
||||
try {
|
||||
const allSettings = settingsState.getAll() as unknown as Record<string, unknown>;
|
||||
const storedSettings = allSettings[storageKey] as Partial<Record<keyof T, any>>;
|
||||
const storedSettings = allSettings[storageKey] as Partial<Record<keyof T, SettingValue<T[keyof T]>>>;
|
||||
if (storedSettings) {
|
||||
for (const key in storedSettings) {
|
||||
if (key in settingsWithMeta) {
|
||||
@@ -106,7 +110,7 @@ function createSettingsAPI<T extends PluginSettings>(
|
||||
const handleSettingsChange = (newValue: unknown) => {
|
||||
if (!newValue || typeof newValue !== "object") return;
|
||||
|
||||
const newSettings = newValue as Partial<Record<keyof T, any>>;
|
||||
const newSettings = newValue as Partial<Record<keyof T, SettingValue<T[keyof T]>>>;
|
||||
for (const key in newSettings) {
|
||||
const typedKey = key as keyof T;
|
||||
settingsWithMeta[typedKey] = newSettings[typedKey];
|
||||
@@ -130,7 +134,7 @@ function createSettingsAPI<T extends PluginSettings>(
|
||||
target[prop] = value;
|
||||
|
||||
// Reconstruct just the data keys for storage (excluding metadata methods)
|
||||
const dataToStore: any = {};
|
||||
const dataToStore: Record<string, unknown> = {};
|
||||
for (const key in plugin.settings) {
|
||||
dataToStore[key] = target[key];
|
||||
}
|
||||
@@ -154,15 +158,15 @@ function createSettingsAPI<T extends PluginSettings>(
|
||||
return { settings: proxy, dispose };
|
||||
}
|
||||
|
||||
function createStorageAPI<T = any>(
|
||||
function createStorageAPI<T extends Record<string, unknown> = Record<string, unknown>>(
|
||||
pluginId: string,
|
||||
): {
|
||||
storage: StorageAPI<T> & { [K in keyof T]: T[K] };
|
||||
dispose: () => void;
|
||||
} {
|
||||
const prefix = `plugin.${pluginId}.storage.`;
|
||||
const cache: Record<string, any> = {};
|
||||
const listeners = new Map<string, Set<(value: any) => void>>();
|
||||
const cache: Record<string, unknown> = {};
|
||||
const listeners = new Map<string, Set<(value: unknown) => void>>();
|
||||
|
||||
// Load all existing storage values for this plugin
|
||||
const loadStoragePromise = (async () => {
|
||||
@@ -222,7 +226,7 @@ function createStorageAPI<T = any>(
|
||||
|
||||
return target[prop];
|
||||
},
|
||||
set(target, prop: string, value: any) {
|
||||
set(target, prop: string, value: unknown) {
|
||||
if (["onChange", "offChange", "loaded"].includes(prop)) {
|
||||
return false;
|
||||
}
|
||||
@@ -244,7 +248,7 @@ function createEventsAPI(pluginId: string): EventsAPI {
|
||||
const prefix = `plugin.${pluginId}.`;
|
||||
const eventListeners = new Map<
|
||||
string,
|
||||
Set<{ callback: (...args: any[]) => void; listener: EventListener }>
|
||||
Set<{ callback: (...args: unknown[]) => void; listener: EventListener }>
|
||||
>();
|
||||
|
||||
return {
|
||||
@@ -278,7 +282,7 @@ function createEventsAPI(pluginId: string): EventsAPI {
|
||||
};
|
||||
}
|
||||
|
||||
export function createPluginAPI<T extends PluginSettings, S = any>(
|
||||
export function createPluginAPI<T extends PluginSettings, S extends Record<string, unknown> = Record<string, unknown>>(
|
||||
plugin: Plugin<T, S>,
|
||||
): PluginAPI<T, S> {
|
||||
const { settings, dispose: disposeSettings } = createSettingsAPI(plugin);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Plugin, PluginSettings } from "./types";
|
||||
import { verboseInfo } from "@/utils/verboseLog";
|
||||
|
||||
export interface LazyPlugin<T extends PluginSettings = PluginSettings, S = any> {
|
||||
export interface LazyPlugin<T extends PluginSettings = PluginSettings, S = unknown> {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
@@ -21,7 +21,7 @@ function isAssetLoadError(error: unknown): boolean {
|
||||
return ASSET_LOAD_ERRORS.some((token) => msg.includes(token));
|
||||
}
|
||||
|
||||
export function createLazyPlugin<T extends PluginSettings = PluginSettings, S = any>(
|
||||
export function createLazyPlugin<T extends PluginSettings = PluginSettings, S = unknown>(
|
||||
lazyPlugin: LazyPlugin<T, S>,
|
||||
): Plugin<T, S> {
|
||||
const { loader, ...meta } = lazyPlugin;
|
||||
@@ -51,7 +51,7 @@ export function createLazyPlugin<T extends PluginSettings = PluginSettings, S =
|
||||
};
|
||||
}
|
||||
|
||||
export function defineLazyPlugin<T extends PluginSettings = PluginSettings, S = any>(
|
||||
export function defineLazyPlugin<T extends PluginSettings = PluginSettings, S = unknown>(
|
||||
config: LazyPlugin<T, S>,
|
||||
): Plugin<T, S> {
|
||||
return createLazyPlugin(config);
|
||||
|
||||
+22
-15
@@ -5,6 +5,7 @@ import type {
|
||||
HotkeySetting,
|
||||
NumberSetting,
|
||||
Plugin,
|
||||
PluginSetting,
|
||||
PluginSettings,
|
||||
SelectSetting,
|
||||
StringSetting,
|
||||
@@ -22,10 +23,10 @@ import { isPluginAllowedInPerformanceMode } from "@/seqta/utils/performanceMode"
|
||||
|
||||
interface PluginSettingsStorage {
|
||||
enabled?: boolean;
|
||||
[key: string]: any;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface StorageChange<T = any> {
|
||||
interface StorageChange<T = unknown> {
|
||||
oldValue?: T;
|
||||
newValue?: T;
|
||||
}
|
||||
@@ -61,14 +62,14 @@ const PLUGIN_BOOT_ONLY_IDS = new Set(["error-page-kitten"]);
|
||||
*/
|
||||
export class PluginManager {
|
||||
private static instance: PluginManager;
|
||||
private plugins: Map<string, Plugin<any, any>> = new Map();
|
||||
private plugins: Map<string, Plugin> = new Map();
|
||||
private runningPlugins: Map<string, boolean> = new Map();
|
||||
private startingPlugins: Map<string, Promise<void>> = new Map();
|
||||
private pendingStops: Map<string, symbol> = new Map();
|
||||
private eventBacklog: Map<string, any[]> = new Map();
|
||||
private eventBacklog: Map<string, unknown[]> = new Map();
|
||||
private cleanupFunctions: Map<string, () => void> = new Map();
|
||||
private apiDisposers: Map<string, () => void> = new Map();
|
||||
private listeners: Map<string, Set<(...args: any[]) => void>> = new Map();
|
||||
private listeners: Map<string, Set<(...args: unknown[]) => void>> = new Map();
|
||||
private styleElements: Map<string, HTMLStyleElement> = new Map();
|
||||
|
||||
/**
|
||||
@@ -86,7 +87,7 @@ export class PluginManager {
|
||||
return PluginManager.instance;
|
||||
}
|
||||
|
||||
public dispatchPluginEvent(pluginId: string, event: string, args?: any) {
|
||||
public dispatchPluginEvent(pluginId: string, event: string, args?: unknown) {
|
||||
const fullEventName = `plugin.${pluginId}.${event}`;
|
||||
|
||||
// Dispatch plugin event if it's running otherwise queue it
|
||||
@@ -159,7 +160,7 @@ export class PluginManager {
|
||||
}
|
||||
|
||||
// Wait for both settings and storage to be loaded before starting the plugin
|
||||
await Promise.all([(api.settings as any).loaded, api.storage.loaded]);
|
||||
await Promise.all([api.settings.loaded, api.storage.loaded]);
|
||||
|
||||
if (!this.shouldStartPlugin(plugin)) {
|
||||
this.removePluginStyles(pluginId);
|
||||
@@ -312,21 +313,27 @@ export class PluginManager {
|
||||
trigger?: () => void | Promise<void>;
|
||||
})
|
||||
| (Omit<HotkeySetting, "type"> & { type: "hotkey"; id: string })
|
||||
| (Omit<ComponentSetting, "type"> & { type: "component"; id: string; component: any });
|
||||
| (Omit<ComponentSetting, "type"> & {
|
||||
type: "component";
|
||||
id: string;
|
||||
component: ComponentSetting["component"];
|
||||
});
|
||||
};
|
||||
// Actual type is more complex, see original code, but this gives the gist for the JSDoc.
|
||||
// Array<{ pluginId: string; name: string; description: string; beta?: boolean; settings: Record<string, ProcessedSetting>; disableToggle?: boolean; }>
|
||||
}> {
|
||||
return Array.from(this.plugins.entries()).map(([id, plugin]) => {
|
||||
const settingsEntries = Object.entries(plugin.settings).map(([key, setting]) => {
|
||||
const settingObj = setting as any;
|
||||
let result: any;
|
||||
const settingObj = setting as PluginSetting;
|
||||
let result: Record<string, unknown>;
|
||||
if (settingObj.type === "button" || settingObj.type === "component") {
|
||||
// For button or component, keep the functions
|
||||
result = { ...settingObj };
|
||||
result = { ...(settingObj as Record<string, unknown>) };
|
||||
} else {
|
||||
result = Object.fromEntries(
|
||||
Object.entries(settingObj).filter(([_, value]) => typeof value !== "function"),
|
||||
Object.entries(settingObj as Record<string, unknown>).filter(
|
||||
([, value]) => typeof value !== "function",
|
||||
),
|
||||
);
|
||||
}
|
||||
result.id = key;
|
||||
@@ -363,21 +370,21 @@ export class PluginManager {
|
||||
return this.runningPlugins.get(pluginId) || false;
|
||||
}
|
||||
|
||||
private emit(event: string, ...args: any[]): void {
|
||||
private emit(event: string, ...args: unknown[]): void {
|
||||
const listeners = this.listeners.get(event);
|
||||
if (listeners) {
|
||||
listeners.forEach((listener) => listener(...args));
|
||||
}
|
||||
}
|
||||
|
||||
public on(event: string, callback: (...args: any[]) => void): void {
|
||||
public on(event: string, callback: (...args: unknown[]) => void): void {
|
||||
if (!this.listeners.has(event)) {
|
||||
this.listeners.set(event, new Set());
|
||||
}
|
||||
this.listeners.get(event)!.add(callback);
|
||||
}
|
||||
|
||||
public off(event: string, callback: (...args: any[]) => void): void {
|
||||
public off(event: string, callback: (...args: unknown[]) => void): void {
|
||||
const listeners = this.listeners.get(event);
|
||||
if (listeners) {
|
||||
listeners.delete(callback);
|
||||
|
||||
@@ -59,13 +59,13 @@ export function hotkeySetting(options: Omit<HotkeySetting, "type">): HotkeySetti
|
||||
};
|
||||
}
|
||||
|
||||
export function defineSettings<TSettings extends Record<string, any>>(
|
||||
export function defineSettings<TSettings extends Record<string, import("./types").PluginSetting>>(
|
||||
settings: TSettings,
|
||||
): TSettings {
|
||||
return settings;
|
||||
}
|
||||
|
||||
export function Setting(settingDef: any): PropertyDecorator {
|
||||
export function Setting(settingDef: import("./types").PluginSetting): PropertyDecorator {
|
||||
return (target, propertyKey) => {
|
||||
const proto = target.constructor.prototype;
|
||||
if (!Object.hasOwn(proto, "settings")) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import ReactFiber from "@/seqta/utils/ReactFiber";
|
||||
|
||||
import type { Component } from "svelte";
|
||||
|
||||
export interface BooleanSetting {
|
||||
type: "boolean";
|
||||
default: boolean;
|
||||
@@ -52,7 +54,7 @@ export interface ComponentSetting {
|
||||
type: "component";
|
||||
title: string;
|
||||
description?: string;
|
||||
component: any;
|
||||
component: Component<Record<string, unknown>>;
|
||||
}
|
||||
|
||||
export type PluginSetting =
|
||||
@@ -103,7 +105,7 @@ export interface SEQTAAPI {
|
||||
};
|
||||
}
|
||||
|
||||
export interface StorageAPI<T = any> {
|
||||
export interface StorageAPI<T = unknown> {
|
||||
/**
|
||||
* Register a callback to be called when a storage value changes
|
||||
*/
|
||||
@@ -123,11 +125,11 @@ export type TypedStorageAPI<T> = StorageAPI<T> & {
|
||||
};
|
||||
|
||||
export interface EventsAPI {
|
||||
on: (event: string, callback: (...args: any[]) => void) => { unregister: () => void };
|
||||
emit: (event: string, ...args: any[]) => void;
|
||||
on: (event: string, callback: (...args: unknown[]) => void) => { unregister: () => void };
|
||||
emit: (event: string, ...args: unknown[]) => void;
|
||||
}
|
||||
|
||||
export interface PluginAPI<T extends PluginSettings, S = any> {
|
||||
export interface PluginAPI<T extends PluginSettings, S = unknown> {
|
||||
seqta: SEQTAAPI;
|
||||
settings: SettingsAPI<T>;
|
||||
storage: TypedStorageAPI<S>;
|
||||
@@ -137,7 +139,7 @@ export interface PluginAPI<T extends PluginSettings, S = any> {
|
||||
|
||||
export type PluginRunResult = void | (() => void);
|
||||
|
||||
export interface Plugin<T extends PluginSettings = PluginSettings, S = any> {
|
||||
export interface Plugin<T extends PluginSettings = PluginSettings, S = unknown> {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { getCkeditorGlobal } from "@/seqta/utils/ckeditorGlobal";
|
||||
import { GetThresholdOfColor } from "@/seqta/ui/colors/getThresholdColour";
|
||||
import { waitForElm } from "@/seqta/utils/waitForElm";
|
||||
import { delay } from "@/seqta/utils/delay";
|
||||
@@ -590,11 +591,11 @@ export function tryLoad() {
|
||||
finishLoad();
|
||||
});
|
||||
|
||||
waitForElm("[data-key=welcome]").then((elm: any) => {
|
||||
waitForElm("[data-key=welcome]").then((elm: Element) => {
|
||||
elm.classList.remove("active");
|
||||
});
|
||||
|
||||
waitForElm(".code", true, 50).then((elm: any) => {
|
||||
waitForElm(".code", true, 50).then((elm: Element) => {
|
||||
if (!elm.innerText.includes("BetterSEQTA")) LoadPageElements();
|
||||
});
|
||||
|
||||
@@ -820,7 +821,7 @@ export function init() {
|
||||
iframe.focus();
|
||||
return;
|
||||
}
|
||||
const ckeditor = (window as any).CKEDITOR;
|
||||
const ckeditor = getCkeditorGlobal();
|
||||
if (ckeditor?.instances?.editor1) {
|
||||
try {
|
||||
ckeditor.instances.editor1.focus();
|
||||
|
||||
@@ -66,7 +66,7 @@ export async function AddBetterSEQTAElements() {
|
||||
const menuList = menu.firstChild as HTMLElement;
|
||||
|
||||
if (!checkRemoteFeature("page.home").hide) {
|
||||
createHomeButton(fragment, menuList);
|
||||
createHomeButton(fragment);
|
||||
}
|
||||
if (!checkRemoteFeature("page.news").hide) {
|
||||
createNewsButton(fragment, menu);
|
||||
@@ -99,7 +99,15 @@ export async function AddBetterSEQTAElements() {
|
||||
attachNotificationsPanelAnimation();
|
||||
}
|
||||
|
||||
function createHomeButton(fragment: DocumentFragment, _: HTMLElement) {
|
||||
type StudentPerson = {
|
||||
firstname?: string;
|
||||
surname?: string;
|
||||
house?: string;
|
||||
year?: string | number;
|
||||
house_colour?: string;
|
||||
};
|
||||
|
||||
function createHomeButton(fragment: DocumentFragment) {
|
||||
const container = document.getElementById("content")!;
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("titlebar");
|
||||
@@ -127,7 +135,10 @@ async function handleUserInfoAndStudentData() {
|
||||
|
||||
updateUserInfo(userInfo);
|
||||
ensureTitlebarFounderBadgeMounted();
|
||||
await updateStudentInfo((await studentResponse.json()).payload, userInfo);
|
||||
await updateStudentInfo(
|
||||
(await studentResponse.json()).payload as StudentPerson[],
|
||||
userInfo,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("[BetterSEQTA+] Failed to handle user info and student data:", error);
|
||||
}
|
||||
@@ -190,9 +201,12 @@ function updateUserInfo(info: {
|
||||
.appendChild(document.getElementsByClassName("logout")[0]);
|
||||
}
|
||||
|
||||
async function updateStudentInfo(students: any, info: Awaited<ReturnType<typeof getUserInfo>>) {
|
||||
async function updateStudentInfo(
|
||||
students: StudentPerson[],
|
||||
info: Awaited<ReturnType<typeof getUserInfo>>,
|
||||
) {
|
||||
const index = students.findIndex(
|
||||
(person: any) =>
|
||||
(person) =>
|
||||
person.firstname == info.userDesc.split(" ")[0] &&
|
||||
person.surname == info.userDesc.split(" ")[1],
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Color from "color";
|
||||
|
||||
function adjustLuminance(color: any, lum: any) {
|
||||
function adjustLuminance(color: string, lum: number) {
|
||||
let adjustedColor = Color(color.toLowerCase());
|
||||
const rgbObj = adjustedColor.rgb().object();
|
||||
|
||||
@@ -13,7 +13,7 @@ function adjustLuminance(color: any, lum: any) {
|
||||
return adjustedColor.string();
|
||||
}
|
||||
|
||||
export default function ColorLuminance(color: any, lum = 0) {
|
||||
export default function ColorLuminance(color: string, lum = 0) {
|
||||
if (color == "" || color == null) {
|
||||
// light cyan blue
|
||||
return "#00bfff";
|
||||
|
||||
@@ -18,9 +18,9 @@ const LOGO_STYLE_ID = "bsplus-logo-style";
|
||||
let colorTransitionRafId: number | null = null;
|
||||
let lastInterpolatedHex: string | null = null;
|
||||
|
||||
const setCSSVar = (varName: any, value: any) =>
|
||||
const setCSSVar = (varName: string, value: string) =>
|
||||
document.documentElement.style.setProperty(varName, value);
|
||||
const applyProperties = (props: any) =>
|
||||
const applyProperties = (props: Record<string, string>) =>
|
||||
Object.entries(props).forEach(([key, value]) => setCSSVar(key, value));
|
||||
|
||||
function easeInOutCubic(t: number): number {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Color from "color";
|
||||
export function GetThresholdOfColor(color: any) {
|
||||
export function GetThresholdOfColor(color: string) {
|
||||
if (!color) return 0;
|
||||
// Case-insensitive regular expression for matching RGBA colors
|
||||
const rgbaRegex = /rgba?\(([^)]+)\)/gi;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Color from "color";
|
||||
|
||||
export function lightenAndPaleColor(inputColor: any, lightenFactor = 0.75, paleFactor = 0.55) {
|
||||
export function lightenAndPaleColor(inputColor: string, lightenFactor = 0.75, paleFactor = 0.55) {
|
||||
if (!inputColor) return;
|
||||
|
||||
if (inputColor.includes("gradient")) {
|
||||
@@ -28,11 +28,11 @@ export function lightenAndPaleColor(inputColor: any, lightenFactor = 0.75, paleF
|
||||
return result;
|
||||
}
|
||||
// Utility function to average an array of Color objects
|
||||
function averageColors(colors: any) {
|
||||
function averageColors(colors: ReturnType<typeof Color>[]) {
|
||||
let avgR = 0,
|
||||
avgG = 0,
|
||||
avgB = 0;
|
||||
colors.forEach((color: any) => {
|
||||
colors.forEach((color) => {
|
||||
avgR += color.red();
|
||||
avgG += color.green();
|
||||
avgB += color.blue();
|
||||
@@ -40,7 +40,7 @@ function averageColors(colors: any) {
|
||||
return Color.rgb(avgR / colors.length, avgG / colors.length, avgB / colors.length);
|
||||
}
|
||||
// Main function to find a matching color for a CSS gradient
|
||||
function findMatchingColor(cssGradient: any) {
|
||||
function findMatchingColor(cssGradient: string) {
|
||||
try {
|
||||
// Step 1: Parse the gradient to extract color stops (case-insensitive)
|
||||
const regex =
|
||||
@@ -52,20 +52,20 @@ function findMatchingColor(cssGradient: any) {
|
||||
}
|
||||
|
||||
// Normalize and trim the color stops
|
||||
const normalizedColorStops = colorStops.map((color: any) =>
|
||||
const normalizedColorStops = colorStops.map((color: string) =>
|
||||
color.toLowerCase().replace(/\s+/g, ""),
|
||||
);
|
||||
|
||||
// Convert the color stops to Color objects
|
||||
const colorObjects = normalizedColorStops.map((color: any) => Color(color));
|
||||
const colorObjects = normalizedColorStops.map((color) => Color(color));
|
||||
|
||||
// Step 2: Average the color stops
|
||||
const baseColor = averageColors(colorObjects);
|
||||
|
||||
// Step 4: Return the matching color in HEX format
|
||||
return baseColor.hex();
|
||||
} catch (err: any) {
|
||||
console.error(`Error: ${err.message}`);
|
||||
} catch (err: unknown) {
|
||||
console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import debounce from "@/seqta/utils/debounce";
|
||||
|
||||
interface ElementConfig {
|
||||
selector: string;
|
||||
action: (element: Element) => void;
|
||||
@@ -20,18 +22,6 @@ const MOCK_DAY_ATTR = "data-bsp-mock-day";
|
||||
/** Skip MutationObserver-driven reprocessing while we inject the home mock (avoids feedback loops) */
|
||||
let suppressMockMutations = false;
|
||||
|
||||
function debounce(func: Function, wait: number): Function {
|
||||
let timeout: NodeJS.Timeout;
|
||||
return function executedFunction(...args: any[]) {
|
||||
const later = () => {
|
||||
clearTimeout(timeout);
|
||||
func(...args);
|
||||
};
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
};
|
||||
}
|
||||
|
||||
function getRandomElement(array: string[]): string {
|
||||
return array[Math.floor(Math.random() * array.length)];
|
||||
}
|
||||
@@ -861,7 +851,7 @@ export function getMockAssessmentsData() {
|
||||
if (i >= 10) due.setFullYear(currentYear - 1);
|
||||
|
||||
const types = ["Assignment", "Test", "Exam", "Project", "Presentation", "Report"];
|
||||
const assessment: any = {
|
||||
const assessment: Record<string, unknown> = {
|
||||
id: i + 1,
|
||||
title: mockData.assessmentTitles[i % mockData.assessmentTitles.length],
|
||||
code: subj.code,
|
||||
@@ -889,7 +879,7 @@ export function getMockAssessmentsData() {
|
||||
const debouncedProcessElements = debounce(processNewElements, 1);
|
||||
|
||||
function processNewElements() {
|
||||
Object.entries(contentConfig).forEach(([_, config]) => {
|
||||
for (const config of Object.values(contentConfig)) {
|
||||
const { selector, action, alwaysRun, neverMarkProcessed } = config;
|
||||
const elements = document.querySelectorAll(selector);
|
||||
elements.forEach((element: Element) => {
|
||||
@@ -900,7 +890,7 @@ function processNewElements() {
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let observer: MutationObserver | null = null;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CreateElement } from "@/seqta/utils/createEnable/CreateElement";
|
||||
|
||||
export function FilterUpcomingAssessments(subjectoptions: any) {
|
||||
export function FilterUpcomingAssessments(subjectoptions: Record<string, boolean>) {
|
||||
for (const item in subjectoptions) {
|
||||
const subjectdivs = document.querySelectorAll(`[data-subject="${item}"]`);
|
||||
|
||||
@@ -44,7 +44,7 @@ export function FilterUpcomingAssessments(subjectoptions: any) {
|
||||
}
|
||||
}
|
||||
|
||||
function AddPlaceHolderToParent(parent: any, numberofassessments: any) {
|
||||
function AddPlaceHolderToParent(parent: HTMLElement, numberofassessments: number) {
|
||||
const textcontainer = CreateElement("div", "upcoming-blank");
|
||||
const textblank = CreateElement("p", "upcoming-hiddenassessment");
|
||||
let s = "";
|
||||
|
||||
@@ -30,7 +30,10 @@ class ReactFiber {
|
||||
return event.source === window && event.origin === this.getTargetOrigin();
|
||||
}
|
||||
|
||||
private async sendMessage(action: string, payload: any = {}): Promise<any> {
|
||||
private async sendMessage(
|
||||
action: string,
|
||||
payload: Record<string, unknown> = {},
|
||||
): Promise<unknown> {
|
||||
return new Promise((resolve, _) => {
|
||||
const messageId = this.messageIdCounter++;
|
||||
const message = {
|
||||
@@ -60,7 +63,7 @@ class ReactFiber {
|
||||
});
|
||||
}
|
||||
|
||||
async getState(key?: string | string[]): Promise<any> {
|
||||
async getState(key?: string | string[]): Promise<unknown> {
|
||||
return this.sendMessage("getState", {
|
||||
key,
|
||||
});
|
||||
@@ -75,13 +78,13 @@ class ReactFiber {
|
||||
return this;
|
||||
}
|
||||
|
||||
async getProps(propName?: string): Promise<any> {
|
||||
async getProps(propName?: string): Promise<unknown> {
|
||||
return this.sendMessage("getProp", {
|
||||
propName,
|
||||
});
|
||||
}
|
||||
|
||||
async setProp(propName: string, value: any): Promise<ReactFiber> {
|
||||
async setProp(propName: string, value: unknown): Promise<ReactFiber> {
|
||||
await this.sendMessage("setProp", {
|
||||
propName,
|
||||
value,
|
||||
|
||||
@@ -39,7 +39,8 @@ async function getSubjectCode(programme: number, metaclass: number): Promise<str
|
||||
const subjects = semester?.subjects;
|
||||
if (!Array.isArray(subjects)) continue;
|
||||
const subject = subjects.find(
|
||||
(s: any) => s && Number(s.programme) === programme && Number(s.metaclass) === metaclass,
|
||||
(s: { programme?: unknown; metaclass?: unknown; code?: string }) =>
|
||||
s && Number(s.programme) === programme && Number(s.metaclass) === metaclass,
|
||||
);
|
||||
if (subject?.code) return subject.code;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import ShortcutLinks from "@/seqta/content/links.json";
|
||||
import stringToHTML from "../stringToHTML";
|
||||
import type { Shortcut } from "@/types/storage";
|
||||
|
||||
export function addShortcuts(shortcuts: any) {
|
||||
export function addShortcuts(shortcuts: Shortcut[]) {
|
||||
for (let i = 0; i < shortcuts.length; i++) {
|
||||
const currentShortcut = shortcuts[i];
|
||||
|
||||
@@ -23,7 +24,7 @@ export function addShortcuts(shortcuts: any) {
|
||||
}
|
||||
}
|
||||
|
||||
function createNewShortcut(link: any, icon: any, viewBox: any, title: any) {
|
||||
function createNewShortcut(link: string, icon: string, viewBox: string, title: string) {
|
||||
// Creates the stucture and element information for each seperate shortcut
|
||||
const container = document.getElementById("shortcuts");
|
||||
if (!container) return;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export function getCkeditorGlobal(): unknown {
|
||||
return (window as Window & { CKEDITOR?: unknown }).CKEDITOR;
|
||||
}
|
||||
@@ -10,7 +10,7 @@ function isSafeShortcutHref(url: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
export function CreateCustomShortcutDiv(element: any) {
|
||||
export function CreateCustomShortcutDiv(element: HTMLElement) {
|
||||
const container = document.getElementById("shortcuts");
|
||||
if (!container) return;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export function CreateElement(
|
||||
type: string,
|
||||
class_?: any,
|
||||
id?: any,
|
||||
class_?: string,
|
||||
id?: string,
|
||||
innerText?: string,
|
||||
innerHTML?: string,
|
||||
style?: string,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default function debounce<T extends (...args: any[]) => void>(
|
||||
export default function debounce<T extends (...args: unknown[]) => void>(
|
||||
fn: T,
|
||||
delay: number,
|
||||
): (...args: Parameters<T>) => void {
|
||||
|
||||
@@ -15,9 +15,13 @@ const handleNotificationClick = async (target: HTMLElement) => {
|
||||
const buttonId = notificationItem.getAttribute("data-id");
|
||||
if (!buttonId) return;
|
||||
|
||||
const matchingNotification = notificationList.items.find(
|
||||
(item: any) => item.notificationID === parseInt(buttonId),
|
||||
);
|
||||
type NotificationListItem = {
|
||||
notificationID?: number;
|
||||
message?: { messageID?: number };
|
||||
};
|
||||
const matchingNotification = (
|
||||
notificationList.items as NotificationListItem[]
|
||||
).find((item) => item.notificationID === parseInt(buttonId, 10));
|
||||
|
||||
if (!matchingNotification?.message?.messageID) return;
|
||||
|
||||
|
||||
@@ -19,12 +19,29 @@ function getThemeManager(): Promise<ThemeManager> {
|
||||
return themeManagerPromise;
|
||||
}
|
||||
|
||||
type SendResponse = (response?: unknown) => void;
|
||||
|
||||
type ThemeMessageBody = Record<string, unknown> & {
|
||||
themeID?: string;
|
||||
id?: string;
|
||||
enableTheme?: boolean;
|
||||
};
|
||||
|
||||
type ContentScriptMessage = {
|
||||
info?: string;
|
||||
save?: boolean;
|
||||
body?: ThemeMessageBody;
|
||||
};
|
||||
|
||||
export class MessageHandler {
|
||||
constructor() {
|
||||
// @ts-ignore
|
||||
browser.runtime.onMessage.addListener(this.routeMessage.bind(this));
|
||||
}
|
||||
routeMessage(request: any, _sender: any, sendResponse: any) {
|
||||
routeMessage(
|
||||
request: ContentScriptMessage,
|
||||
_sender: chrome.runtime.MessageSender,
|
||||
sendResponse: SendResponse,
|
||||
) {
|
||||
console.debug("Message received:", request);
|
||||
|
||||
switch (request.info) {
|
||||
@@ -42,8 +59,8 @@ export class MessageHandler {
|
||||
...request.body,
|
||||
userEdited: true,
|
||||
});
|
||||
if (request.body.enableTheme) {
|
||||
await themeManager.setTheme(request.body.id);
|
||||
if (request.body?.enableTheme) {
|
||||
await themeManager.setTheme(request.body.id as string);
|
||||
}
|
||||
sendResponse({ status: "success" });
|
||||
sendThemeUpdate();
|
||||
@@ -59,7 +76,7 @@ export class MessageHandler {
|
||||
|
||||
case "GetTheme":
|
||||
void getThemeManager().then((themeManager) => {
|
||||
themeManager.getTheme(request.body.themeID).then((theme) => {
|
||||
themeManager.getTheme(request.body!.themeID as string).then((theme) => {
|
||||
sendResponse(theme);
|
||||
});
|
||||
});
|
||||
@@ -67,7 +84,7 @@ export class MessageHandler {
|
||||
|
||||
case "SetTheme":
|
||||
void getThemeManager().then((themeManager) => {
|
||||
themeManager.setTheme(request.body.themeID).then(() => {
|
||||
themeManager.setTheme(request.body!.themeID as string).then(() => {
|
||||
sendResponse({ status: "success" });
|
||||
});
|
||||
});
|
||||
@@ -83,7 +100,7 @@ export class MessageHandler {
|
||||
|
||||
case "DeleteTheme":
|
||||
void getThemeManager().then((themeManager) => {
|
||||
themeManager.deleteTheme(request.body.themeID).then(() => {
|
||||
themeManager.deleteTheme(request.body!.themeID as string).then(() => {
|
||||
sendResponse({ status: "success" });
|
||||
});
|
||||
});
|
||||
@@ -100,7 +117,7 @@ export class MessageHandler {
|
||||
case "OpenThemeCreator": {
|
||||
const themeID = request?.body?.themeID;
|
||||
void import("@/plugins/built-in/themes/ThemeCreator").then(({ OpenThemeCreator }) => {
|
||||
void OpenThemeCreator(themeID ? themeID : "");
|
||||
void OpenThemeCreator(themeID ? String(themeID) : "");
|
||||
});
|
||||
closeExtensionPopup();
|
||||
sendResponse({ status: "success" });
|
||||
@@ -109,7 +126,7 @@ export class MessageHandler {
|
||||
|
||||
case "ShareTheme":
|
||||
void getThemeManager().then((themeManager) => {
|
||||
themeManager.shareTheme(request.body.themeID).then((id) => {
|
||||
themeManager.shareTheme(request.body!.themeID as string).then((id) => {
|
||||
sendResponse({ status: "success", id });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ describe("master extension setting", () => {
|
||||
"persists %s and queued preferences before reloading SEQTA tabs",
|
||||
async (enabled) => {
|
||||
jest.useFakeTimers();
|
||||
let browser: any;
|
||||
let browser: typeof import("@/lib/browser").default;
|
||||
let settings: typeof import("./SettingsState");
|
||||
jest.isolateModules(() => {
|
||||
browser = require("@/lib/browser").default;
|
||||
|
||||
@@ -82,8 +82,8 @@ function storageChangeIsNoop(oldValue: unknown, newValue: unknown): boolean {
|
||||
return JSON.stringify(oldValue) === JSON.stringify(newValue);
|
||||
}
|
||||
|
||||
type ChangeListener = (newValue: any, oldValue: any) => void;
|
||||
type GlobalChangeListener = (newValue: any, oldValue: any, key: string) => void;
|
||||
type ChangeListener = (newValue: unknown, oldValue: unknown) => void;
|
||||
type GlobalChangeListener = (newValue: unknown, oldValue: unknown, key: string) => void;
|
||||
|
||||
class StorageManager {
|
||||
private static instance: StorageManager;
|
||||
@@ -105,8 +105,8 @@ class StorageManager {
|
||||
|
||||
const handler: ProxyHandler<StorageManager> = {
|
||||
get: (target, prop: keyof SettingsState | "register" | "initialize") => {
|
||||
if (prop in target) {
|
||||
return (target as any)[prop];
|
||||
if (typeof prop === "string" && prop in target) {
|
||||
return Reflect.get(target, prop);
|
||||
}
|
||||
if (typeof prop === "string" && isExcludedSettingsKey(prop)) {
|
||||
return undefined;
|
||||
|
||||
@@ -27,6 +27,15 @@ import {
|
||||
applyPageFeatureGateEarly,
|
||||
injectPageFeatureBanner,
|
||||
} from "@/seqta/utils/remoteConfig/runtime";
|
||||
import type {
|
||||
ActiveSubjectLike,
|
||||
DateSortable,
|
||||
HomeLessonAssessmentLink,
|
||||
HomeTimetableLesson,
|
||||
HomeUpcomingAssessment,
|
||||
SeqtaColourPref,
|
||||
UpcomingDateBucket,
|
||||
} from "@/seqta/utils/loaders/homePageTypes";
|
||||
|
||||
let lessonInterval: ReturnType<typeof setInterval> | null = null;
|
||||
let homeTeardown: (() => void) | null = null;
|
||||
@@ -291,7 +300,7 @@ async function GetActiveClasses() {
|
||||
}
|
||||
}
|
||||
|
||||
function comparedate(obj1: any, obj2: any) {
|
||||
function comparedate(obj1: DateSortable, obj2: DateSortable) {
|
||||
const d1 = new Date(obj1.due || obj1.date || 0).getTime();
|
||||
const d2 = new Date(obj2.due || obj2.date || 0).getTime();
|
||||
return d1 - d2;
|
||||
@@ -301,7 +310,7 @@ function startOfDay(date: Date): Date {
|
||||
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
||||
}
|
||||
|
||||
async function callHomeTimetable(date: string, change?: any) {
|
||||
async function callHomeTimetable(date: string, change?: boolean) {
|
||||
const { id: student } = await getUserInfo();
|
||||
const response = await fetch(`${location.origin}/seqta/student/load/timetable?`, {
|
||||
method: "POST",
|
||||
@@ -319,7 +328,7 @@ async function callHomeTimetable(date: string, change?: any) {
|
||||
|
||||
if (serverResponse.payload.items.length > 0) {
|
||||
if (DayContainer.innerText || change) {
|
||||
const lessonArray: Array<any> = [...serverResponse.payload.items].sort((a, b) =>
|
||||
const lessonArray: HomeTimetableLesson[] = [...serverResponse.payload.items].sort((a, b) =>
|
||||
a.from.localeCompare(b.from),
|
||||
);
|
||||
|
||||
@@ -329,7 +338,7 @@ async function callHomeTimetable(date: string, change?: any) {
|
||||
lessonArray[i].type == "tutorial"
|
||||
? `timetable.tutor.${lessonArray[i].tutorID}`
|
||||
: `timetable.subject.colour.${lessonArray[i].code}`;
|
||||
const subject = colours.find((element: any) => element.name === subjectname);
|
||||
const subject = colours.find((element: SeqtaColourPref) => element.name === subjectname);
|
||||
|
||||
if (!subject) {
|
||||
lessonArray[i].colour = "--item-colour: #8e8e8e;";
|
||||
@@ -385,7 +394,7 @@ async function callHomeTimetable(date: string, change?: any) {
|
||||
}
|
||||
}
|
||||
|
||||
function CheckCurrentLessonAll(lessons: any) {
|
||||
function CheckCurrentLessonAll(lessons: HomeTimetableLesson[]) {
|
||||
clearLessonInterval();
|
||||
lessonInterval = setInterval(() => {
|
||||
for (let i = 0; i < lessons.length; i++) {
|
||||
@@ -394,7 +403,7 @@ function CheckCurrentLessonAll(lessons: any) {
|
||||
}, 60000);
|
||||
}
|
||||
|
||||
async function CheckCurrentLesson(lesson: any, num: number) {
|
||||
async function CheckCurrentLesson(lesson: HomeTimetableLesson, num: number) {
|
||||
const { from: startTime, until: endTime, code, description, room, staff } = lesson;
|
||||
const currentDate = new Date();
|
||||
|
||||
@@ -443,7 +452,7 @@ async function CheckCurrentLesson(lesson: any, num: number) {
|
||||
}
|
||||
}
|
||||
|
||||
function makeLessonDiv(lesson: any, num: number) {
|
||||
function makeLessonDiv(lesson: HomeTimetableLesson, num: number) {
|
||||
const {
|
||||
code,
|
||||
colour,
|
||||
@@ -484,7 +493,7 @@ function makeLessonDiv(lesson: any, num: number) {
|
||||
if (assessments && assessments.length > 0) {
|
||||
const assessmentString = assessments
|
||||
.map(
|
||||
(element: any) =>
|
||||
(element: HomeLessonAssessmentLink) =>
|
||||
`<p onclick="location.href = '${buildAssessmentURL(programmeID, metaID, element.id)}';">${element.title}</p>`,
|
||||
)
|
||||
.join("");
|
||||
@@ -506,18 +515,25 @@ function makeLessonDiv(lesson: any, num: number) {
|
||||
return element;
|
||||
}
|
||||
|
||||
function buildAssessmentURL(programmeID: any, metaID: any, itemID = "") {
|
||||
function buildAssessmentURL(
|
||||
programmeID: number | undefined,
|
||||
metaID: number | undefined,
|
||||
itemID: number | string = "",
|
||||
) {
|
||||
const base = "../#?page=/assessments/";
|
||||
return itemID
|
||||
? `${base}${programmeID}:${metaID}&item=${itemID}`
|
||||
: `${base}${programmeID}:${metaID}`;
|
||||
}
|
||||
|
||||
function CheckUnmarkedAttendance(lessonattendance: any) {
|
||||
function CheckUnmarkedAttendance(lessonattendance: { label?: string } | null | undefined) {
|
||||
return lessonattendance ? lessonattendance.label : " ";
|
||||
}
|
||||
|
||||
function applyHomeUpcomingLimits(assessments: any[], activeSubjects: any[]) {
|
||||
function applyHomeUpcomingLimits(
|
||||
assessments: HomeUpcomingAssessment[],
|
||||
activeSubjects: ActiveSubjectLike[],
|
||||
) {
|
||||
const maxSubjects = settingsState.homeUpcomingSubjectsMax ?? 5;
|
||||
const maxPerSubject = settingsState.homeUpcomingAssessmentsPerSubjectMax ?? 0;
|
||||
|
||||
@@ -526,7 +542,7 @@ function applyHomeUpcomingLimits(assessments: any[], activeSubjects: any[]) {
|
||||
assessments[i].filterCode = subject?.code ?? assessments[i].code;
|
||||
}
|
||||
|
||||
const bySubject = new Map<string, any[]>();
|
||||
const bySubject = new Map<string, HomeUpcomingAssessment[]>();
|
||||
const subjectOrder: string[] = [];
|
||||
|
||||
for (const assessment of assessments) {
|
||||
@@ -550,7 +566,7 @@ function applyHomeUpcomingLimits(assessments: any[], activeSubjects: any[]) {
|
||||
const subjectLimit = maxSubjects > 0 ? maxSubjects : subjectOrder.length;
|
||||
const allowedSubjects = subjectOrder.slice(0, subjectLimit);
|
||||
|
||||
const limited: any[] = [];
|
||||
const limited: HomeUpcomingAssessment[] = [];
|
||||
for (const code of allowedSubjects) {
|
||||
const items = bySubject.get(code)!;
|
||||
const perSubjectLimit = maxPerSubject > 0 ? maxPerSubject : items.length;
|
||||
@@ -562,10 +578,13 @@ function applyHomeUpcomingLimits(assessments: any[], activeSubjects: any[]) {
|
||||
assessments.splice(0, assessments.length, ...limited);
|
||||
}
|
||||
|
||||
async function CreateUpcomingSection(assessments: any, activeSubjects: any) {
|
||||
async function CreateUpcomingSection(
|
||||
assessments: HomeUpcomingAssessment[],
|
||||
activeSubjects: ActiveSubjectLike[],
|
||||
) {
|
||||
const { id: student } = await getUserInfo();
|
||||
const upcomingitemcontainer = document.querySelector("#upcoming-items");
|
||||
const upcomingDates = {};
|
||||
const upcomingDates: Record<string, UpcomingDateBucket> = {};
|
||||
const Today = new Date();
|
||||
|
||||
if (!(settingsState.homeUpcomingIncludePast ?? true)) {
|
||||
@@ -584,7 +603,7 @@ async function CreateUpcomingSection(assessments: any, activeSubjects: any) {
|
||||
|
||||
for (let i = 0; i < assessments.length; i++) {
|
||||
const subject = colours.find(
|
||||
(element: any) => element.name === `timetable.subject.colour.${assessments[i].code}`,
|
||||
(element: SeqtaColourPref) => element.name === `timetable.subject.colour.${assessments[i].code}`,
|
||||
);
|
||||
if (!subject) {
|
||||
assessments[i].colour = "--item-colour: #8e8e8e;";
|
||||
@@ -596,7 +615,7 @@ async function CreateUpcomingSection(assessments: any, activeSubjects: any) {
|
||||
const filterSubjects = subjectsWithUpcomingAssessments(assessments, activeSubjects).map(
|
||||
(subject) => {
|
||||
const colour = colours.find(
|
||||
(c: any) => c.name === `timetable.subject.colour.${subject.code}`,
|
||||
(c: SeqtaColourPref) => c.name === `timetable.subject.colour.${subject.code}`,
|
||||
);
|
||||
return { code: subject.code, colour: `--item-colour: ${colour?.value ?? "#8e8e8e"};` };
|
||||
},
|
||||
@@ -605,28 +624,24 @@ async function CreateUpcomingSection(assessments: any, activeSubjects: any) {
|
||||
CreateFilters(filterSubjects);
|
||||
|
||||
for (let i = 0; i < assessments.length; i++) {
|
||||
const element: any = assessments[i];
|
||||
if (!upcomingDates[element.due as keyof typeof upcomingDates]) {
|
||||
const dateObj: any = {
|
||||
div: CreateElement("div", "upcoming-date-container"),
|
||||
const element = assessments[i];
|
||||
if (!upcomingDates[element.due]) {
|
||||
const dateObj: UpcomingDateBucket = {
|
||||
div: CreateElement("div", "upcoming-date-container") as HTMLElement,
|
||||
assessments: [],
|
||||
};
|
||||
(upcomingDates[element.due as keyof typeof upcomingDates] as any) = dateObj;
|
||||
}
|
||||
const assessmentDateDiv = upcomingDates[element.due as keyof typeof upcomingDates];
|
||||
if (assessmentDateDiv) {
|
||||
(assessmentDateDiv as any).assessments.push(element);
|
||||
upcomingDates[element.due] = dateObj;
|
||||
}
|
||||
const assessmentDateDiv = upcomingDates[element.due];
|
||||
assessmentDateDiv.assessments.push(element);
|
||||
}
|
||||
|
||||
for (const date in upcomingDates) {
|
||||
const assessmentdue = new Date(
|
||||
(upcomingDates[date as keyof typeof upcomingDates] as any).assessments[0].due,
|
||||
);
|
||||
const assessmentdue = new Date(upcomingDates[date].assessments[0].due);
|
||||
const specialcase = CheckSpecialDay(Today, assessmentdue);
|
||||
const assessmentDate = createAssessmentDateDiv(
|
||||
date,
|
||||
upcomingDates[date as keyof typeof upcomingDates],
|
||||
upcomingDates[date],
|
||||
student,
|
||||
specialcase,
|
||||
);
|
||||
@@ -648,7 +663,12 @@ async function CreateUpcomingSection(assessments: any, activeSubjects: any) {
|
||||
}
|
||||
}
|
||||
|
||||
function createAssessmentDateDiv(date: string, value: any, student: number, datecase?: any) {
|
||||
function createAssessmentDateDiv(
|
||||
date: string,
|
||||
value: UpcomingDateBucket,
|
||||
student: number,
|
||||
datecase?: string,
|
||||
) {
|
||||
const options: Intl.DateTimeFormatOptions = {
|
||||
weekday: "long",
|
||||
month: "long",
|
||||
@@ -799,7 +819,7 @@ function CreateFilters(subjects: { code: string; colour: string }[]) {
|
||||
settingsState.subjectfilters = filteroptions;
|
||||
}
|
||||
|
||||
function CreateSubjectFilter(subjectcode: any, itemcolour: string, checked: any) {
|
||||
function CreateSubjectFilter(subjectcode: string, itemcolour: string, checked: boolean) {
|
||||
const label = CreateElement("label", "upcoming-checkbox-container");
|
||||
label.innerText = subjectcode;
|
||||
const input = CreateElement("input") as HTMLInputElement;
|
||||
|
||||
@@ -47,7 +47,7 @@ export function isDateInCachedWeek(date: Date, weekFrom: string, weekUntil: stri
|
||||
return isInWeekRange(toISODate(date), weekFrom, weekUntil);
|
||||
}
|
||||
|
||||
async function postParentTimetable(body: object): Promise<any> {
|
||||
async function postParentTimetable(body: object): Promise<unknown> {
|
||||
const res = await fetch(`${location.origin}${TIMETABLE_URL}`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json; charset=utf-8" },
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import type { OverviewSubject } from "@/plugins/built-in/assessmentsOverview/utils";
|
||||
|
||||
/** SEQTA user pref row from load/prefs (subject/tutor colours). */
|
||||
export type SeqtaColourPref = {
|
||||
name: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
export type HomeLessonAssessmentLink = {
|
||||
id: number | string;
|
||||
title: string;
|
||||
};
|
||||
|
||||
export type HomeTimetableLesson = {
|
||||
type: string;
|
||||
code: string;
|
||||
from: string;
|
||||
until: string;
|
||||
tutorID?: number | string;
|
||||
description?: string;
|
||||
staff?: string;
|
||||
room?: string;
|
||||
programmeID?: number;
|
||||
metaID?: number;
|
||||
assessments?: HomeLessonAssessmentLink[];
|
||||
attendance?: { label?: string } | null;
|
||||
colour?: string;
|
||||
invert?: boolean;
|
||||
attendanceTitle?: string;
|
||||
};
|
||||
|
||||
export type HomeUpcomingAssessment = {
|
||||
id: number | string;
|
||||
due: string;
|
||||
code: string;
|
||||
title: string;
|
||||
subject: string;
|
||||
programmeID: number;
|
||||
metaclassID: number;
|
||||
filterCode?: string;
|
||||
colour?: string;
|
||||
};
|
||||
|
||||
export type UpcomingDateBucket = {
|
||||
div: HTMLElement;
|
||||
assessments: HomeUpcomingAssessment[];
|
||||
};
|
||||
|
||||
export type DateSortable = { due?: string; date?: string };
|
||||
|
||||
export type ActiveSubjectLike = OverviewSubject;
|
||||
@@ -126,7 +126,15 @@ export function appendNoticeEmptyState(container: HTMLElement, message: string)
|
||||
container.append(emptyState);
|
||||
}
|
||||
|
||||
function createNoticeElement(notice: any, colour: string | undefined): Node {
|
||||
type NoticeRecord = {
|
||||
title: string;
|
||||
staff: string;
|
||||
contents: string;
|
||||
label_title?: string;
|
||||
colour?: unknown;
|
||||
};
|
||||
|
||||
function createNoticeElement(notice: NoticeRecord, colour: string | undefined): Node {
|
||||
const htmlContent = noticeCardHtml(notice, colour, noticePreview(notice.contents), {
|
||||
wrapperStyle:
|
||||
"position: relative; background: var(--background-primary); cursor: pointer; transition: all 0.3s ease; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); border: 1px solid rgba(255, 255, 255, 0.1);",
|
||||
@@ -138,7 +146,7 @@ function createNoticeElement(notice: any, colour: string | undefined): Node {
|
||||
}
|
||||
|
||||
export function openNoticeModal(
|
||||
notice: any,
|
||||
notice: NoticeRecord,
|
||||
colour: string | undefined,
|
||||
sourceElement: HTMLElement,
|
||||
) {
|
||||
@@ -294,7 +302,9 @@ export function renderNoticesIntoContainer(
|
||||
const fragment = document.createDocumentFragment();
|
||||
for (const notice of notices) {
|
||||
if (settingsState.mockNotices || noticeMatchesLabelFilter(notice, labelTokens)) {
|
||||
fragment.appendChild(createNoticeElement(notice, processNoticeColor(notice.colour)));
|
||||
fragment.appendChild(
|
||||
createNoticeElement(notice as NoticeRecord, processNoticeColor(notice.colour)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ function syncDefaultMenuOrder(menu: HTMLElement) {
|
||||
if (settingsState.defaultmenuorder.length === 0) {
|
||||
settingsState.defaultmenuorder = Array.from(childnodes).map(
|
||||
(element) => (element as HTMLElement).dataset.key,
|
||||
);
|
||||
) as string[];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -253,8 +253,8 @@ function saveNewOrder(sortable: Sortable) {
|
||||
settingsState.menuorder = sortable.toArray();
|
||||
}
|
||||
|
||||
function cloneAttributes(target: any, source: any) {
|
||||
[...source.attributes].forEach((attr) => {
|
||||
target.setAttribute(attr.nodeName, attr.nodeValue);
|
||||
});
|
||||
function cloneAttributes(target: Element, source: Element) {
|
||||
for (const attr of source.attributes) {
|
||||
target.setAttribute(attr.name, attr.value);
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ export async function closePopup() {
|
||||
}
|
||||
|
||||
if (fullMotionEffectsEnabled()) {
|
||||
await (motionAnimate as any)(
|
||||
await motionAnimate(
|
||||
[popup, background],
|
||||
{ opacity: [1, 0], scale: [1, 0.95] },
|
||||
{ duration: 0.25, easing: [0.22, 0.03, 0.26, 1] },
|
||||
@@ -177,7 +177,7 @@ export function openPopup({
|
||||
|
||||
if (settingsState.animations) {
|
||||
if (fullMotionEffectsEnabled()) {
|
||||
(motionAnimate as any)(
|
||||
motionAnimate(
|
||||
[container, background],
|
||||
{ scale: [0, 1] },
|
||||
{ type: "spring", stiffness: 220, damping: 18 },
|
||||
@@ -189,7 +189,7 @@ export function openPopup({
|
||||
? document.querySelectorAll(animateSelector)
|
||||
: animateSelector;
|
||||
|
||||
(motionAnimate as any)(
|
||||
motionAnimate(
|
||||
targets!,
|
||||
{ opacity: [0, 1], y: [10, 0] },
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ export function renderShortcuts() {
|
||||
|
||||
try {
|
||||
addShortcuts(settingsState.shortcuts || []);
|
||||
} catch (err: any) {
|
||||
} catch (err: unknown) {
|
||||
console.error("[BetterSEQTA+] Error adding built-in shortcuts:", err?.message || err);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export function renderShortcuts() {
|
||||
for (const element of custom) {
|
||||
try {
|
||||
CreateCustomShortcutDiv(element);
|
||||
} catch (err: any) {
|
||||
} catch (err: unknown) {
|
||||
console.error(
|
||||
"[BetterSEQTA+] Error adding custom shortcut:",
|
||||
element?.name,
|
||||
|
||||
@@ -135,12 +135,12 @@ export async function observeMenuItemPosition() {
|
||||
const node = element as HTMLElement;
|
||||
|
||||
if (!isTopLevelSidebarItem(node)) return;
|
||||
if ((element as any)[processedSymbol]) return;
|
||||
if ((element as Element & Record<symbol, boolean>)[processedSymbol]) return;
|
||||
|
||||
if (!isMenuOptionsOpen()) {
|
||||
processMenuItemNode(node);
|
||||
ChangeMenuItemPositions(settingsState.menuorder);
|
||||
(element as any)[processedSymbol] = true;
|
||||
(element as Element & Record<symbol, boolean>)[processedSymbol] = true;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
+12
-11
@@ -1,5 +1,14 @@
|
||||
let cachedUserInfo: any = null;
|
||||
let userInfoFetchPromise: Promise<any> | null = null;
|
||||
export type SeqtaUserInfo = {
|
||||
id?: number;
|
||||
student?: number;
|
||||
personUUID?: string;
|
||||
type?: string;
|
||||
userDesc?: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
let cachedUserInfo: SeqtaUserInfo | null = null;
|
||||
let userInfoFetchPromise: Promise<SeqtaUserInfo> | null = null;
|
||||
|
||||
function invalidateCachedUserInfo(): void {
|
||||
cachedUserInfo = null;
|
||||
@@ -52,7 +61,7 @@ export async function getUserInfo(options?: { validateSession?: boolean }) {
|
||||
invalidateCachedUserInfo();
|
||||
}
|
||||
|
||||
cachedUserInfo = payload;
|
||||
cachedUserInfo = payload as SeqtaUserInfo;
|
||||
return cachedUserInfo;
|
||||
} catch (error) {
|
||||
console.error("[BetterSEQTA+] Failed to get user info:", error);
|
||||
@@ -72,14 +81,6 @@ export async function getUserInfo(options?: { validateSession?: boolean }) {
|
||||
return userInfoFetchPromise;
|
||||
}
|
||||
|
||||
export type SeqtaUserInfo = {
|
||||
id?: number;
|
||||
student?: number;
|
||||
personUUID?: string;
|
||||
type?: string;
|
||||
userDesc?: string;
|
||||
};
|
||||
|
||||
export async function tryGetUserInfo(): Promise<SeqtaUserInfo | undefined> {
|
||||
return (await getUserInfo().catch(() => undefined)) ?? undefined;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/** Patched onto XHR instances by global-search passive indexing. */
|
||||
export type XhrWithBsplusMeta = XMLHttpRequest & {
|
||||
__bsplusUrl?: string;
|
||||
__bsplusMethod?: string;
|
||||
};
|
||||
|
||||
export function asXhrWithBsplusMeta(xhr: XMLHttpRequest): XhrWithBsplusMeta {
|
||||
return xhr as XhrWithBsplusMeta;
|
||||
}
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
declare module "canvas-confetti" {
|
||||
const confetti: any;
|
||||
const confetti: (options?: Record<string, unknown>) => Promise<void> | null;
|
||||
export default confetti;
|
||||
}
|
||||
@@ -2,7 +2,7 @@ export type SettingsState = {
|
||||
DarkMode: boolean;
|
||||
selectedTheme: string;
|
||||
customshortcuts: CustomShortcut[];
|
||||
defaultmenuorder: any[];
|
||||
defaultmenuorder: string[];
|
||||
lessonalert: boolean;
|
||||
menuitems: {
|
||||
assessments: ToggleItem;
|
||||
@@ -24,14 +24,14 @@ export type SettingsState = {
|
||||
welcome: ToggleItem;
|
||||
[key: string]: ToggleItem;
|
||||
};
|
||||
menuorder: any[];
|
||||
menuorder: string[];
|
||||
onoff: boolean;
|
||||
/** Last popup size explicitly selected with the expand/collapse control. */
|
||||
settingsPopupExpanded?: boolean;
|
||||
selectedColor: string;
|
||||
originalSelectedColor: string;
|
||||
shortcuts: Shortcut[];
|
||||
subjectfilters: Record<string, any>;
|
||||
subjectfilters: Record<string, boolean>;
|
||||
transparencyEffects: boolean;
|
||||
justupdated?: boolean;
|
||||
privacyStatementShown?: boolean;
|
||||
|
||||
Reference in new issue
Block a user