feat: fix TOS look and make correct API

This commit is contained in:
AdenMGB committed 2026-10-29 09:54:19 +10:30
1 parent fea017bbd7
commit efa4f8b85c
6 files changed
+229 -142

No files matched your search

+175
View File
@@ -4315,6 +4315,181 @@ div.day-empty {
-webkit-backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
} }
} }
/* Terms of service — compact whatsnew shell (theme vars, light + dark) */
#whatsnewbk.bsplus-tos-overlay {
.whatsnewContainer.bsplus-tos-container {
position: relative !important;
width: min(34em, calc(100vw - 1.75rem)) !important;
height: auto !important;
max-height: min(32rem, calc(100vh - 2rem)) !important;
margin: auto !important;
padding: 0 0 1rem !important;
display: flex !important;
flex-direction: column !important;
overflow: hidden !important;
background: var(--background-primary) !important;
color: var(--text-primary) !important;
border-radius: 20px !important;
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28) !important;
}
.bsplus-tos-header {
margin: 20px 20px 0.5rem !important;
width: calc(100% - 40px) !important;
height: auto !important;
min-height: unset !important;
flex-shrink: 0;
}
.bsplus-tos-header h1 {
margin: 0 !important;
font-size: 1.75rem !important;
font-weight: 700 !important;
line-height: 1.15 !important;
color: var(--text-primary) !important;
}
.bsplus-tos-header p {
margin: 0.35rem 0 0 !important;
font-size: 1rem !important;
font-weight: 400 !important;
line-height: 1.4 !important;
color: var(--text-primary) !important;
opacity: 0.88;
}
.bsplus-tos-body {
display: flex !important;
flex-direction: column !important;
gap: 0.75rem !important;
width: 90% !important;
margin: 0 auto !important;
min-height: 0 !important;
flex: 1 1 auto !important;
overflow: hidden !important;
font-size: 1.05rem !important;
line-height: 1.6 !important;
}
.bsplus-tos-intro {
margin: 0 !important;
flex-shrink: 0;
text-align: center;
font-size: 1rem !important;
line-height: 1.5 !important;
color: var(--text-primary) !important;
}
.bsplus-tos-scroll {
flex: 1 1 auto;
min-height: 7rem;
overflow-x: hidden;
overflow-y: auto;
padding: 0.65rem 0.75rem;
text-align: left;
font-size: 1.05rem !important;
line-height: 1.6 !important;
color: var(--text-primary) !important;
border-radius: 12px;
border: 1px solid color-mix(in srgb, var(--text-primary) 14%, transparent);
background: color-mix(in srgb, var(--text-primary) 5%, var(--background-primary));
}
.bsplus-tos-scroll h3,
.bsplus-tos-scroll h4 {
margin: 1rem 0 0.4rem;
font-size: 1.15em !important;
font-weight: 600 !important;
line-height: 1.35 !important;
color: var(--text-primary) !important;
}
.bsplus-tos-scroll h3:first-child,
.bsplus-tos-scroll h4:first-child,
.bsplus-tos-scroll p:first-child {
margin-top: 0;
}
.bsplus-tos-scroll p {
margin: 0 0 1ex;
font-size: inherit !important;
color: var(--text-primary) !important;
}
.bsplus-tos-scroll ul,
.bsplus-tos-scroll ol {
margin: 0 0 1ex;
padding-left: 1.25rem;
}
.bsplus-tos-scroll li {
margin: 0.15rem 0;
}
.bsplus-tos-scroll a {
color: inherit;
text-decoration: underline;
text-underline-offset: 2px;
}
.bsplus-tos-actions {
display: flex;
flex-direction: column;
gap: 0.55rem;
flex-shrink: 0;
padding-top: 0.1rem;
padding-bottom: 0.15rem;
}
.bsplus-tos-btn {
width: 100%;
min-height: 2.65rem;
padding: 0.65rem 1rem;
border: none;
border-radius: 12px;
font-size: 0.95rem;
font-weight: 600;
font-family: inherit;
cursor: pointer;
transition: all 0.2s ease-in-out;
}
.bsplus-tos-btn:focus {
outline: none;
}
.bsplus-tos-btn:focus-visible {
box-shadow:
0 0 0 2px var(--background-primary),
0 0 0 4px color-mix(in srgb, var(--text-primary) 45%, transparent);
}
.bsplus-tos-btn--primary {
background: var(--text-primary);
color: var(--background-primary);
}
.bsplus-tos-btn--primary:hover:not(:disabled) {
filter: brightness(1.08);
transform: scale(1.02);
}
.bsplus-tos-btn--secondary {
background: color-mix(in srgb, var(--text-primary) 10%, var(--background-primary));
color: var(--text-primary);
border: 1px solid color-mix(in srgb, var(--text-primary) 16%, transparent);
}
.bsplus-tos-btn--secondary:hover:not(:disabled) {
background: color-mix(in srgb, var(--text-primary) 14%, var(--background-primary));
transform: scale(1.02);
}
.bsplus-tos-btn:active:not(:disabled) {
transform: scale(0.98);
}
}
.whatsnewImgContainer { .whatsnewImgContainer {
width: 96%; width: 96%;
display: flex; display: flex;
+4
View File
@@ -0,0 +1,4 @@
{
"last_updated": "2026-10-29T00:00:00.000Z",
"whatsnew_html": "<div class=\"whatsnewTextContainer\"><h3>1. Agreement</h3><p>By installing or using BetterSEQTA+, you agree to these Terms of Service. If you do not agree, do not use the extension.</p><h3>2. The extension</h3><p>BetterSEQTA+ is a browser extension that enhances SEQTA Learn and SEQTA Engage on your device. Features may change over time.</p><h3>3. Your school account</h3><p>You must comply with your school’s policies when using SEQTA. BetterSEQTA+ does not replace your school’s terms.</p><h3>4. Acceptable use</h3><p>Do not use the extension to harm others, bypass security, or violate applicable law.</p><h3>5. Privacy</h3><p>Our Privacy Policy explains what data we process. See <a href=\"https://betterseqta.org/privacy\" target=\"_blank\" rel=\"noopener noreferrer\">betterseqta.org/privacy</a>.</p><h3>6. Changes</h3><p>We may update these terms. Material changes may require you to accept again in the extension.</p></div>"
}
@@ -6,7 +6,7 @@ jest.mock("../DevApiBase", () => ({
})); }));
import { import {
getFallbackPrivacyTerms, getFallbackTermsOfService,
markTermsOfServiceAccepted, markTermsOfServiceAccepted,
shouldShowTermsOfServicePopup, shouldShowTermsOfServicePopup,
} from "./OpenTermsOfServicePopup"; } from "./OpenTermsOfServicePopup";
@@ -55,25 +55,22 @@ describe("shouldShowTermsOfServicePopup", () => {
}); });
describe("markTermsOfServiceAccepted", () => { describe("markTermsOfServiceAccepted", () => {
it("stores the accepted version and legacy privacy flags", () => { it("stores the accepted terms version from GET /api/terms", () => {
const state = { const state = {
termsOfServiceLastAccepted: undefined as string | undefined, termsOfServiceLastAccepted: undefined as string | undefined,
privacyStatementShown: false,
privacyStatementLastUpdated: undefined as string | undefined,
}; };
markTermsOfServiceAccepted(state, SAMPLE_TERMS.last_updated); markTermsOfServiceAccepted(state, SAMPLE_TERMS.last_updated);
expect(state.termsOfServiceLastAccepted).toBe(SAMPLE_TERMS.last_updated); expect(state.termsOfServiceLastAccepted).toBe(SAMPLE_TERMS.last_updated);
expect(state.privacyStatementShown).toBe(true);
expect(state.privacyStatementLastUpdated).toBe(SAMPLE_TERMS.last_updated);
}); });
}); });
describe("getFallbackPrivacyTerms", () => { describe("getFallbackTermsOfService", () => {
it("returns bundled fallback content when the API is unavailable", () => { it("returns bundled fallback content when the API is unavailable", () => {
const fallback = getFallbackPrivacyTerms(); const fallback = getFallbackTermsOfService();
expect(fallback.last_updated).toBeTruthy(); expect(fallback.last_updated).toBeTruthy();
expect(fallback.whatsnew_html).toContain("whatsnewTextContainer"); expect(fallback.whatsnew_html).toContain("whatsnewTextContainer");
expect(fallback.whatsnew_html).toContain("Agreement");
}); });
}); });
@@ -2,49 +2,54 @@ import stringToHTML from "../stringToHTML";
import { settingsState } from "../listeners/SettingsState"; import { settingsState } from "../listeners/SettingsState";
import { getApiBase } from "../DevApiBase"; import { getApiBase } from "../DevApiBase";
import { closePopup, openPopup } from "./PopupManager"; import { closePopup, openPopup } from "./PopupManager";
import fallbackTerms from "@/exampleprivacyresponse.json"; import fallbackTerms from "@/exampletermsresponse.json";
import type { SettingsState } from "@/types/storage"; import type { SettingsState } from "@/types/storage";
export const TERMS_OF_SERVICE_URL = "https://betterseqta.org/terms";
export const PRIVACY_POLICY_URL = "https://betterseqta.org/privacy"; export const PRIVACY_POLICY_URL = "https://betterseqta.org/privacy";
const PRIVACY_FETCH_TIMEOUT_MS = 8_000; const TERMS_FETCH_TIMEOUT_MS = 8_000;
const POPUP_STYLE_ID = "bsplus-tos-popup-styles";
export interface PrivacyTermsPayload { /** Shared shape for `GET /api/terms` and `GET /api/privacy`. */
export interface LegalDocumentPayload {
last_updated: string; last_updated: string;
whatsnew_html: string; whatsnew_html: string;
} }
function isPrivacyTermsPayload(data: unknown): data is PrivacyTermsPayload { function isLegalDocumentPayload(data: unknown): data is LegalDocumentPayload {
return ( return (
!!data && !!data &&
typeof data === "object" && typeof data === "object" &&
typeof (data as PrivacyTermsPayload).last_updated === "string" && typeof (data as LegalDocumentPayload).last_updated === "string" &&
typeof (data as PrivacyTermsPayload).whatsnew_html === "string" && typeof (data as LegalDocumentPayload).whatsnew_html === "string" &&
!!(data as PrivacyTermsPayload).whatsnew_html.trim() !!(data as LegalDocumentPayload).whatsnew_html.trim()
); );
} }
export function getFallbackPrivacyTerms(): PrivacyTermsPayload { export function getFallbackTermsOfService(): LegalDocumentPayload {
return fallbackTerms as PrivacyTermsPayload; return fallbackTerms as LegalDocumentPayload;
} }
export async function fetchPrivacyTerms(): Promise<PrivacyTermsPayload> { /** Loads Terms of Service body from `GET /api/terms`. */
export async function fetchTermsOfService(): Promise<LegalDocumentPayload> {
try { try {
const res = await fetch(`${getApiBase()}/api/privacy`, { const res = await fetch(`${getApiBase()}/api/terms`, {
cache: "no-store", cache: "no-store",
signal: AbortSignal.timeout(PRIVACY_FETCH_TIMEOUT_MS), signal: AbortSignal.timeout(TERMS_FETCH_TIMEOUT_MS),
}); });
if (!res.ok) return getFallbackPrivacyTerms(); if (!res.ok) return getFallbackTermsOfService();
const data: unknown = await res.json(); const data: unknown = await res.json();
if (!isPrivacyTermsPayload(data)) return getFallbackPrivacyTerms(); if (!isLegalDocumentPayload(data)) return getFallbackTermsOfService();
return data; return data;
} catch (err) { } catch (err) {
console.warn("[TermsOfService] Failed to fetch privacy terms:", err); console.warn("[TermsOfService] Failed to fetch terms:", err);
return getFallbackPrivacyTerms(); return getFallbackTermsOfService();
} }
} }
/** @deprecated Use {@link fetchTermsOfService}. */
export const fetchPrivacyTerms = fetchTermsOfService;
function termsVersionIsNewer( function termsVersionIsNewer(
remoteLastUpdated: string, remoteLastUpdated: string,
acceptedLastUpdated?: string, acceptedLastUpdated?: string,
@@ -80,106 +85,16 @@ export function shouldShowTermsOfServicePopup(
| "privacyStatementShown" | "privacyStatementShown"
| "privacyStatementLastUpdated" | "privacyStatementLastUpdated"
>, >,
terms: PrivacyTermsPayload, terms: LegalDocumentPayload,
): boolean { ): boolean {
return termsVersionIsNewer(terms.last_updated, resolvedTermsAcceptance(state)); return termsVersionIsNewer(terms.last_updated, resolvedTermsAcceptance(state));
} }
export function markTermsOfServiceAccepted( export function markTermsOfServiceAccepted(
state: Pick< state: Pick<SettingsState, "termsOfServiceLastAccepted">,
SettingsState,
"termsOfServiceLastAccepted" | "privacyStatementShown" | "privacyStatementLastUpdated"
>,
lastUpdated: string, lastUpdated: string,
): void { ): void {
state.termsOfServiceLastAccepted = lastUpdated; state.termsOfServiceLastAccepted = lastUpdated;
state.privacyStatementShown = true;
state.privacyStatementLastUpdated = lastUpdated;
}
function ensurePopupStyles() {
if (document.getElementById(POPUP_STYLE_ID)) return;
const style = document.createElement("style");
style.id = POPUP_STYLE_ID;
style.textContent = `
#whatsnewbk.bsplus-tos-overlay .bsplus-tos-body {
display: flex !important;
flex-direction: column !important;
gap: 0.75rem !important;
min-height: 0 !important;
flex: 1 1 auto !important;
width: 92% !important;
margin: 0 auto 1rem !important;
}
#whatsnewbk.bsplus-tos-overlay .bsplus-tos-intro {
margin: 0 !important;
font-size: 1rem !important;
line-height: 1.5 !important;
flex-shrink: 0 !important;
}
#whatsnewbk.bsplus-tos-overlay .bsplus-tos-scroll {
flex: 1 1 auto !important;
min-height: 8rem !important;
max-height: min(42vh, 28rem) !important;
overflow: auto !important;
border: 1px solid rgba(17, 24, 39, 0.12) !important;
border-radius: 0.75rem !important;
padding: 0.85rem 1rem !important;
background: rgba(17, 24, 39, 0.03) !important;
font-size: 0.95rem !important;
line-height: 1.55 !important;
}
#whatsnewbk.bsplus-tos-overlay.bsplus-tos-overlay--dark .bsplus-tos-scroll {
border-color: rgba(255, 255, 255, 0.12) !important;
background: rgba(255, 255, 255, 0.04) !important;
}
#whatsnewbk.bsplus-tos-overlay .bsplus-tos-actions {
display: flex !important;
flex-direction: column !important;
gap: 0.65rem !important;
flex-shrink: 0 !important;
}
#whatsnewbk.bsplus-tos-overlay .bsplus-tos-btn {
width: 100% !important;
min-height: 2.75rem !important;
padding: 0.75rem 1rem !important;
border: none !important;
border-radius: 0.75rem !important;
font-size: 0.95rem !important;
font-weight: 600 !important;
font-family: inherit !important;
cursor: pointer !important;
transition: all 0.2s ease-in-out !important;
}
#whatsnewbk.bsplus-tos-overlay .bsplus-tos-btn--primary {
background: #2563eb !important;
color: #ffffff !important;
}
#whatsnewbk.bsplus-tos-overlay .bsplus-tos-btn--secondary {
background: rgba(17, 24, 39, 0.08) !important;
color: inherit !important;
}
#whatsnewbk.bsplus-tos-overlay.bsplus-tos-overlay--dark .bsplus-tos-btn--secondary {
background: rgba(255, 255, 255, 0.1) !important;
}
#whatsnewbk.bsplus-tos-overlay .bsplus-tos-btn:hover:not(:disabled) {
transform: scale(1.02) !important;
}
#whatsnewbk.bsplus-tos-overlay .bsplus-tos-btn:active:not(:disabled) {
transform: scale(0.98) !important;
}
`;
document.head.appendChild(style);
} }
function buildTermsScrollContent(html: string): HTMLElement { function buildTermsScrollContent(html: string): HTMLElement {
@@ -188,7 +103,7 @@ function buildTermsScrollContent(html: string): HTMLElement {
const scroll = document.createElement("div"); const scroll = document.createElement("div");
scroll.className = "bsplus-tos-scroll privacyStatement"; scroll.className = "bsplus-tos-scroll privacyStatement";
scroll.setAttribute("tabindex", "0"); scroll.setAttribute("tabindex", "0");
scroll.setAttribute("aria-label", "Terms of service and privacy policy"); scroll.setAttribute("aria-label", "Terms of service");
if (root?.classList.contains("whatsnewTextContainer")) { if (root?.classList.contains("whatsnewTextContainer")) {
scroll.innerHTML = root.innerHTML; scroll.innerHTML = root.innerHTML;
@@ -203,26 +118,24 @@ function buildTermsScrollContent(html: string): HTMLElement {
export async function openTermsOfServicePopup( export async function openTermsOfServicePopup(
onDismissed?: () => void, onDismissed?: () => void,
options?: { terms?: PrivacyTermsPayload; force?: boolean }, options?: { terms?: LegalDocumentPayload; force?: boolean },
) { ) {
if (document.getElementById("whatsnewbk")) { if (document.getElementById("whatsnewbk")) {
onDismissed?.(); onDismissed?.();
return; return;
} }
const terms = options?.terms ?? (await fetchPrivacyTerms()); const terms = options?.terms ?? (await fetchTermsOfService());
if (!options?.force && !shouldShowTermsOfServicePopup(settingsState, terms)) { if (!options?.force && !shouldShowTermsOfServicePopup(settingsState, terms)) {
onDismissed?.(); onDismissed?.();
return; return;
} }
ensurePopupStyles();
const header = stringToHTML( const header = stringToHTML(
/* html */ /* html */
`<div class="whatsnewHeader"> `<div class="whatsnewHeader bsplus-tos-header">
<h1>Terms of Service</h1> <h1>Terms of Service</h1>
<p>Review the terms below, then accept or dismiss for now</p> <p>Scroll to read the full terms, then accept or dismiss for now</p>
</div>`, </div>`,
).firstChild as HTMLElement; ).firstChild as HTMLElement;
@@ -232,38 +145,36 @@ export async function openTermsOfServicePopup(
body.className = "whatsnewTextContainer bsplus-tos-body"; body.className = "whatsnewTextContainer bsplus-tos-body";
const intro = stringToHTML(/* html */ ` const intro = stringToHTML(/* html */ `
<p class="bsplus-tos-intro"> <p class="bsplus-tos-intro privacyStatement">
Do you accept the terms of service? Read the full policy at Do you accept the terms of service?
<a href="${PRIVACY_POLICY_URL}" target="_blank" rel="noopener noreferrer">betterseqta.org/privacy</a>. <a href="${TERMS_OF_SERVICE_URL}" target="_blank" rel="noopener noreferrer">Terms</a>
·
<a href="${PRIVACY_POLICY_URL}" target="_blank" rel="noopener noreferrer">Privacy</a>
</p> </p>
`).firstChild as HTMLElement; `).firstChild as HTMLElement;
const actions = stringToHTML(/* html */ ` const actions = stringToHTML(/* html */ `
<div class="bsplus-tos-actions"> <div class="bsplus-tos-actions">
<button type="button" id="bsplus-tos-accept" class="bsplus-tos-btn bsplus-tos-btn--primary">
I accept the terms of service
</button>
<button type="button" id="bsplus-tos-decline" class="bsplus-tos-btn bsplus-tos-btn--secondary"> <button type="button" id="bsplus-tos-decline" class="bsplus-tos-btn bsplus-tos-btn--secondary">
Not now Not now
</button> </button>
<button type="button" id="bsplus-tos-accept" class="bsplus-tos-btn bsplus-tos-btn--primary">
I accept the terms of service
</button>
</div> </div>
`).firstChild as HTMLElement; `).firstChild as HTMLElement;
body.append(intro, scrollContent, actions); body.append(intro, scrollContent, actions);
const isDark = settingsState.DarkMode;
openPopup({ openPopup({
header, header,
content: [body], content: [body],
containerClass: "whatsnewContainer--scrollBody whatsnewContainer--compact", containerClass: "bsplus-tos-container",
backgroundClass: isDark backgroundClass: "bsplus-tos-overlay",
? "bsplus-tos-overlay bsplus-tos-overlay--dark"
: "bsplus-tos-overlay",
hideCloseButton: true, hideCloseButton: true,
closeOnBackdrop: false, closeOnBackdrop: false,
closeOnEscape: false, closeOnEscape: false,
animateSelector: ".bsplus-tos-body > *", animateSelector: ".bsplus-tos-header *, .bsplus-tos-body > *",
afterClose: onDismissed, afterClose: onDismissed,
actions: [ actions: [
{ {
+4 -4
View File
@@ -12,7 +12,7 @@ import {
} from "./OpenCoursesAssessmentsFixPopup"; } from "./OpenCoursesAssessmentsFixPopup";
import { syncApiBaseToBackground } from "../DevApiBase"; import { syncApiBaseToBackground } from "../DevApiBase";
import { import {
fetchPrivacyTerms, fetchTermsOfService,
openTermsOfServicePopup, openTermsOfServicePopup,
shouldShowTermsOfServicePopup, shouldShowTermsOfServicePopup,
} from "./OpenTermsOfServicePopup"; } from "./OpenTermsOfServicePopup";
@@ -58,12 +58,12 @@ export async function runStartupPopupQueue() {
steps.push((goNext) => { steps.push((goNext) => {
void (async () => { void (async () => {
const privacyTerms = await fetchPrivacyTerms(); const termsDocument = await fetchTermsOfService();
if (!shouldShowTermsOfServicePopup(settingsState, privacyTerms)) { if (!shouldShowTermsOfServicePopup(settingsState, termsDocument)) {
goNext(); goNext();
return; return;
} }
await openTermsOfServicePopup(goNext, { terms: privacyTerms }); await openTermsOfServicePopup(goNext, { terms: termsDocument });
})(); })();
}); });
+1 -1
View File
@@ -36,7 +36,7 @@ export interface SettingsState {
justupdated?: boolean; justupdated?: boolean;
privacyStatementShown?: boolean; privacyStatementShown?: boolean;
privacyStatementLastUpdated?: string; privacyStatementLastUpdated?: string;
/** ISO timestamp from `/api/privacy` `last_updated` when the user accepted ToS. */ /** ISO timestamp from `GET /api/terms` `last_updated` when the user accepted ToS. */
termsOfServiceLastAccepted?: string; termsOfServiceLastAccepted?: string;
/** One-time announcement: BS Cloud automatic settings sync (last in startup popup queue). */ /** One-time announcement: BS Cloud automatic settings sync (last in startup popup queue). */
bsCloudAutoSyncAnnouncementShown?: boolean; bsCloudAutoSyncAnnouncementShown?: boolean;