feat: add safe guards for themes

This commit is contained in:
AdenMGB committed 2026-11-04 15:00:39 +10:30
1 parent 49698b9dd3
commit ccd5c8b1a4
3 files changed
+99 -2

No files matched your search

@@ -0,0 +1,81 @@
/**
* Appended after custom theme CSS on SEQTA pages.
* Prevents community/home-baked theme rules from breaking course, assessment, and Engage UI.
*/
export const CUSTOM_THEME_PAGE_COMPAT_CSS = `
/* BetterSEQTA+ — custom theme compatibility (courses / assessments / Engage) */
body:has(#main > .course) #main::after,
body:has(#main > .assessments) #main::after,
body:has(.assessmentsWrapper) #main::after {
display: none !important;
content: none !important;
animation: none !important;
}
#main > .course,
#main > .course > .content,
#main > .assessments,
.assessmentsWrapper {
background: transparent !important;
}
#main > .course *,
#main > .assessments *,
.assessmentsWrapper *,
[class*="SelectedAssessment__SelectedAssessment___"],
[class*="SelectedAssessment__SelectedAssessment___"] *,
[class*="TabSet__TabSet___"],
[class*="TabSet__TabSet___"] * {
animation: none !important;
}
[class*="BasicPanel__BasicPanel___"] {
position: static !important;
overflow: visible !important;
box-shadow: none !important;
border-radius: inherit !important;
background: var(--background-primary) !important;
}
[class*="BasicPanel__BasicPanel___"]::before,
[class*="BasicPanel__BasicPanel___"]::after {
content: none !important;
display: none !important;
}
#main > .course .message,
#main > .course .thread,
#main > .assessments .message,
#main > .assessments .thread,
.assessmentsWrapper .message,
[class*="MessageList__"],
[class*="SelectedAssessment__SelectedAssessment___"] {
background: unset !important;
border: unset !important;
box-shadow: unset !important;
transform: none !important;
border-radius: inherit !important;
}
#main > .course .message::before,
#main > .course .thread::before,
#main > .assessments .message::before,
#main > .assessments .thread::before,
[class*="SelectedAssessment__SelectedAssessment___"]::before {
content: none !important;
display: none !important;
}
#content:has(#main > .course) #container,
#content:has(#main > .assessments) #container,
#content:has(.assessmentsWrapper) #container {
background-attachment: scroll !important;
}
body:has(#main > .course),
body:has(#main > .assessments),
body:has(.assessmentsWrapper) {
background-attachment: scroll !important;
}
`.trim();
@@ -0,0 +1,9 @@
import { CUSTOM_THEME_PAGE_COMPAT_CSS } from "@/seqta/utils/customThemePageCompatCss";
describe("custom theme page compat", () => {
it("includes assessment and course safeguards", () => {
expect(CUSTOM_THEME_PAGE_COMPAT_CSS).toContain("#main > .course");
expect(CUSTOM_THEME_PAGE_COMPAT_CSS).toContain("BasicPanel__BasicPanel___");
expect(CUSTOM_THEME_PAGE_COMPAT_CSS).toContain("assessmentsWrapper");
});
});
@@ -5,6 +5,7 @@
import patchScript from "@/seqta/utils/themeImagePagePatch.js?script&iife"; import patchScript from "@/seqta/utils/themeImagePagePatch.js?script&iife";
import { extensionPageScriptUrl } from "@/lib/extensionPageScriptUrl"; import { extensionPageScriptUrl } from "@/lib/extensionPageScriptUrl";
import { blobToBase64Data } from "@/seqta/utils/base64"; import { blobToBase64Data } from "@/seqta/utils/base64";
import { CUSTOM_THEME_PAGE_COMPAT_CSS } from "@/seqta/utils/customThemePageCompatCss";
const PAGE_PATCH_LOADER_ID = "bsplus-theme-image-page-patch-loader"; const PAGE_PATCH_LOADER_ID = "bsplus-theme-image-page-patch-loader";
const BRIDGE_ID = "bsplus-theme-image-bridge"; const BRIDGE_ID = "bsplus-theme-image-bridge";
@@ -59,6 +60,12 @@ function preserveCustomSidebarActive(css: string): string {
return css.replace(/\.active(?![\w-])/g, ":is(.active, .bsplus-active)"); return css.replace(/\.active(?![\w-])/g, ":is(.active, .bsplus-active)");
} }
function withPageCompatCss(css: string): string {
const trimmed = css.trim();
if (!trimmed) return CUSTOM_THEME_PAGE_COMPAT_CSS;
return `${trimmed}\n\n${CUSTOM_THEME_PAGE_COMPAT_CSS}`;
}
export async function syncThemeToPage(input: ThemePageSyncInput): Promise<void> { export async function syncThemeToPage(input: ThemePageSyncInput): Promise<void> {
if (input.clear) { if (input.clear) {
sendPayload({ clear: true }); sendPayload({ clear: true });
@@ -68,10 +75,10 @@ export async function syncThemeToPage(input: ThemePageSyncInput): Promise<void>
const payload: Record<string, unknown> = {}; const payload: Record<string, unknown> = {};
if (input.clearPreview) payload.clearPreview = true; if (input.clearPreview) payload.clearPreview = true;
if (input.customCss !== undefined) { if (input.customCss !== undefined) {
payload.customCss = preserveCustomSidebarActive(input.customCss); payload.customCss = withPageCompatCss(preserveCustomSidebarActive(input.customCss));
} }
if (input.previewCss !== undefined) { if (input.previewCss !== undefined) {
payload.previewCss = preserveCustomSidebarActive(input.previewCss); payload.previewCss = withPageCompatCss(preserveCustomSidebarActive(input.previewCss));
} }
if (input.images !== undefined) { if (input.images !== undefined) {
payload.images = await Promise.all( payload.images = await Promise.all(