From 9dfe38a48385c1e1b59cf1d5464b58efe1a1d8ed Mon Sep 17 00:00:00 2001 From: Aden Lindsay Date: Tue, 1 Sep 2026 18:07:43 +0930 Subject: [PATCH] feat: pull in tags from accounts --- .npmrc | 1 - src/css/injected.scss | 305 +++++++++++++++++- src/interface/pages/settings.svelte | 11 +- src/interface/pages/settings/general.svelte | 46 ++- src/seqta/ui/AddBetterSEQTAElements.ts | 27 +- src/seqta/ui/dev/hideSensitiveContent.ts | 2 +- .../founderBadge/mountTitlebarFounderBadge.ts | 79 +++++ .../ui/founderBadge/openFounderBadgeModal.ts | 84 +++++ .../founderBadge/openFounderBadgeSettings.ts | 16 + src/seqta/utils/CloudAuth.ts | 9 + src/seqta/utils/Openers/PopupManager.ts | 67 +++- src/seqta/utils/cloudPfpSync.ts | 3 + src/seqta/utils/defaultSettings.ts | 1 + src/seqta/utils/founderBadges.ts | 165 ++++++++++ src/seqta/utils/settingsNavigation.ts | 2 +- src/types/storage.ts | 2 + 16 files changed, 800 insertions(+), 20 deletions(-) create mode 100644 src/seqta/ui/founderBadge/mountTitlebarFounderBadge.ts create mode 100644 src/seqta/ui/founderBadge/openFounderBadgeModal.ts create mode 100644 src/seqta/ui/founderBadge/openFounderBadgeSettings.ts create mode 100644 src/seqta/utils/founderBadges.ts diff --git a/.npmrc b/.npmrc index 8c1d73ae..521a9f7c 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1 @@ legacy-peer-deps=true - diff --git a/src/css/injected.scss b/src/css/injected.scss index fbc90533..d0cafcb4 100644 --- a/src/css/injected.scss +++ b/src/css/injected.scss @@ -3844,18 +3844,320 @@ div.day-empty { .userInfo { display: flex; align-items: center; - padding-top: 4px; + padding: 4px 0; } .userInfoText { text-align: end; + padding: 2px 0; } .userInfoName { margin: 0 !important; font-size: 20px; font-weight: 700; + line-height: 1.2; } .userInfoCode { margin: 0 !important; + line-height: 1.2; +} +.userInfoNameRow { + display: inline-flex; + align-items: center; + justify-content: flex-end; + gap: 6px; +} +.userInfoDetails { + display: flex; + flex-direction: column; + align-items: flex-end; + gap: 2px; +} +.userInfoHouseWrap { + display: inline-block; + margin: 0 8px; + text-align: center; +} +.userInfoHouseWrap .userInfohouse { + display: block; + margin: 0 !important; + padding: 0 6px !important; + box-sizing: border-box; +} +.userInfoHouseWrap .bsplus-founder-badge-slot { + width: 100%; + margin-top: 4px; +} +.userInfoHouseWrap .bsplus-founder-badge-slot[hidden], +.bsplus-founder-badge-slot[hidden] { + display: none; +} +.bsplus-founder-badge--titlebar { + display: block; + width: 100%; + border-radius: 5px; +} +.bsplus-founder-badge--titlebar .bsplus-founder-badge__glass, +.bsplus-founder-badge--titlebar .bsplus-founder-badge__content { + width: 100%; + border-radius: 5px; + box-sizing: border-box; +} +.bsplus-founder-badge--titlebar .bsplus-founder-badge__content { + justify-content: center; + padding: 0 6px; + gap: 0; + min-height: 0; + height: auto; + font-size: 15px; + line-height: normal; + backdrop-filter: none; + -webkit-backdrop-filter: none; + background: rgba(255, 255, 255, 0.12); + box-shadow: + inset 0 0 0 1px rgba(255, 255, 255, 0.28), + inset 0 1px 0 rgba(255, 255, 255, 0.16), + inset 0 -1px 0 rgba(0, 0, 0, 0.12); +} +.bsplus-founder-badge--titlebar .bsplus-founder-badge__label { + display: block; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + text-align: center; +} +.bsplus-founder-badge--titlebar:focus-visible .bsplus-founder-badge__content { + box-shadow: + inset 0 0 0 1px rgba(255, 255, 255, 0.28), + inset 0 1px 0 rgba(255, 255, 255, 0.16), + inset 0 -1px 0 rgba(0, 0, 0, 0.12), + 0 0 0 2px var(--theme-primary, #f97316), + 0 0 0 4px rgba(249, 115, 22, 0.35); +} +.legacy-root .bsplus-founder-badge, +.legacy-root .bsplus-founder-badge-actions .bsplus-cal-btn { + background: transparent !important; +} +.legacy-root .bsplus-founder-badge::after, +.legacy-root .bsplus-founder-badge-actions .bsplus-cal-btn::after { + display: none !important; + content: none !important; +} +.legacy-root .bsplus-founder-badge-actions .bsplus-cal-btn--ghost { + background: color-mix(in srgb, var(--text-primary, #111) 8%, transparent) !important; +} +.legacy-root .bsplus-founder-badge-actions .bsplus-cal-btn--ghost:hover { + background: color-mix(in srgb, var(--text-primary, #111) 14%, transparent) !important; +} +.legacy-root .bsplus-founder-badge-actions .bsplus-cal-btn--primary { + background: var(--better-main, #3b82f6) !important; +} +.bsplus-founder-badge { + position: relative; + display: inline-flex; + padding: 0; + margin: 0; + border: none; + border-radius: 5px; + background: transparent; + vertical-align: middle; + cursor: pointer; + font-family: var(--betterseqta-font-family, Rubik), sans-serif !important; + transition: transform 0.2s ease; + white-space: nowrap; +} +.bsplus-founder-badge--hero { + border-radius: 12px; +} +.bsplus-founder-badge:hover { + transform: scale(1.02); +} +.bsplus-founder-badge:focus { + outline: none; +} +.bsplus-founder-badge:focus-visible .bsplus-founder-badge__glass { + box-shadow: + inset 0 0 0 1px rgba(255, 255, 255, 0.78), + inset 0 1px 0 rgba(255, 255, 255, 0.52), + inset 0 2px 8px rgba(255, 255, 255, 0.14), + inset 0 -1px 0 rgba(0, 0, 0, 0.08), + 0 0 0 2px var(--theme-primary, #f97316), + 0 0 0 4px rgba(249, 115, 22, 0.35); +} +.bsplus-founder-badge__glass { + position: relative; + display: inline-flex; + overflow: hidden; + border-radius: inherit; + background: var(--badge-base, #1e293b); +} +.bsplus-founder-badge__blobs { + position: absolute; + inset: 0; + pointer-events: none; + background: + radial-gradient(ellipse 72% 68% at 18% 42%, var(--badge-blob-a), transparent 72%), + radial-gradient(ellipse 68% 62% at 82% 58%, var(--badge-blob-b), transparent 70%), + radial-gradient(ellipse 64% 56% at 50% 88%, var(--badge-blob-c), transparent 68%); + filter: blur(1px); +} +.bsplus-founder-badge__content { + position: relative; + z-index: 1; + display: inline-flex; + align-items: center; + gap: 5px; + padding: 0 10px; + min-height: 22px; + border-radius: inherit; + color: #fff; + font-size: 15px; + font-weight: 600; + line-height: 22px; + letter-spacing: 0.01em; + font-family: inherit; + text-shadow: 0 1px 1px rgba(0, 0, 0, 0.22); + backdrop-filter: blur(14px) saturate(1.3); + -webkit-backdrop-filter: blur(14px) saturate(1.3); + background: rgba(255, 255, 255, 0.16); + box-shadow: + inset 0 0 0 1px rgba(255, 255, 255, 0.78), + inset 0 1px 0 rgba(255, 255, 255, 0.52), + inset 0 2px 8px rgba(255, 255, 255, 0.14), + inset 0 -1px 0 rgba(0, 0, 0, 0.08); +} +.bsplus-founder-badge--hero .bsplus-founder-badge__content { + gap: 8px; + padding: 10px 16px; + min-height: auto; + font-size: 14px; + line-height: 1.2; + backdrop-filter: none; + -webkit-backdrop-filter: none; + background: rgba(255, 255, 255, 0.2); +} +.bsplus-founder-badge--hero .bsplus-founder-badge__glass { + background: transparent; +} +.bsplus-founder-badge__icon { + flex-shrink: 0; + width: 15px; + height: 15px; + opacity: 0.95; +} +.bsplus-founder-badge--hero .bsplus-founder-badge__icon { + width: 20px; + height: 20px; +} +.bsplus-founder-badge-hero { + position: relative; + display: block; + overflow: hidden; + margin: 0 auto; + width: 90%; + aspect-ratio: 16 / 9; + border-radius: 16px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); + background: var(--badge-base, #0f172a); +} +.bsplus-founder-badge-hero__blobs { + position: absolute; + inset: -22%; + pointer-events: none; + background: + radial-gradient(ellipse 72% 62% at 18% 34%, var(--badge-blob-a), transparent 76%), + radial-gradient(ellipse 68% 58% at 82% 42%, var(--badge-blob-b), transparent 74%), + radial-gradient(ellipse 74% 64% at 52% 88%, var(--badge-blob-c), transparent 76%), + radial-gradient(ellipse 78% 68% at 48% 52%, var(--badge-blob-b), transparent 78%); + filter: blur(10px); +} +.bsplus-founder-badge-hero__vignette { + position: absolute; + inset: 0; + pointer-events: none; + background: radial-gradient(ellipse at center, transparent 34%, rgba(0, 0, 0, 0.62) 100%); + opacity: 0.84; +} +.bsplus-founder-badge-hero__stage { + position: absolute; + inset: 0; + display: grid; + place-items: center; + pointer-events: none; +} +.bsplus-founder-badge-hero__stage .bsplus-founder-badge { + pointer-events: auto; +} +.whatsnewTextContainer.bsplus-founder-badge-body p { + margin: 0 0 1rem; + font-size: 1.2rem; + line-height: 1.6; +} +.whatsnewTextContainer.bsplus-founder-badge-body a { + color: inherit; + text-decoration: underline; + text-underline-offset: 2px; +} +.bsplus-founder-badge-signup { + margin: 0 0 1rem !important; + padding: 0.55rem 0.75rem; + border-radius: 0.6rem; + border: 1px solid color-mix(in srgb, var(--text-primary) 12%, transparent); + background: color-mix(in srgb, var(--text-primary) 5%, transparent); + font-size: 1rem !important; + font-weight: 600; + font-variant-numeric: tabular-nums; +} +.bsplus-founder-badge-header { + align-items: center; + text-align: center; + + h1, + p { + width: 100%; + } +} +.bsplus-founder-badge-actions { + display: flex; + flex-wrap: wrap; + gap: 8px; + justify-content: center; + margin-top: 1.25rem; +} +.bsplus-founder-badge-actions .bsplus-cal-btn { + padding: 8px 14px; + border: none; + border-radius: 10px; + font-size: 13px; + font-weight: 600; + font-family: inherit; + line-height: 1.25; + cursor: pointer; + transition: all 0.2s ease; +} +.bsplus-founder-badge-actions .bsplus-cal-btn:focus-visible { + outline: none; + box-shadow: + 0 0 0 2px var(--background-primary, #fff), + 0 0 0 4px var(--better-main, #3b82f6); +} +.bsplus-founder-badge-actions .bsplus-cal-btn--ghost { + background: color-mix(in srgb, var(--text-primary, #111) 8%, transparent); + color: var(--text-primary, #111); +} +.bsplus-founder-badge-actions .bsplus-cal-btn--ghost:hover { + background: color-mix(in srgb, var(--text-primary, #111) 14%, transparent); + transform: scale(1.02); +} +.bsplus-founder-badge-actions .bsplus-cal-btn--primary { + background: var(--better-main, #3b82f6); + color: #fff; +} +.bsplus-founder-badge-actions .bsplus-cal-btn--primary:hover { + filter: brightness(1.06); + transform: scale(1.02); +} +.bsplus-founder-badge-actions .bsplus-cal-btn:active { + transform: scale(0.98); } .userInfosvg { width: 50px; @@ -3898,6 +4200,7 @@ div.day-empty { color: var(--text-primary); background: var(--auto-background); outline: solid 1px black; + text-align: center; } .DarkLightButton { right: 145px !important; diff --git a/src/interface/pages/settings.svelte b/src/interface/pages/settings.svelte index b635e4f9..3a9f6523 100644 --- a/src/interface/pages/settings.svelte +++ b/src/interface/pages/settings.svelte @@ -283,9 +283,14 @@ const applyDestination = (destination: SettingsDestination) => { activePage = destination.page; - if (destination.page === "settings" && destination.section) { - settingsSearch = ""; - activeSection = destination.section; + if (destination.page === "settings") { + if (destination.section) { + settingsSearch = ""; + activeSection = destination.section; + } + if (destination.search) { + settingsSearch = destination.search; + } } else if (destination.page === "themes" && destination.view) { activeThemeView = destination.view === "store" ? "theme-store" : "theme-settings"; } else if (destination.page === "backgrounds" && destination.view) { diff --git a/src/interface/pages/settings/general.svelte b/src/interface/pages/settings/general.svelte index 7982596a..54c79405 100644 --- a/src/interface/pages/settings/general.svelte +++ b/src/interface/pages/settings/general.svelte @@ -173,6 +173,28 @@ return !q || parts.some((part) => part?.toLowerCase().includes(q)); }; + const founderBadgeSetting = { + title: "Titlebar Founder Badge", + description: + "Show your BetterSEQTA Cloud founder badge next to your name in the SEQTA titlebar", + } as const; + + const showCloudCardHeader = $derived( + matchesSearch("BetterSEQTA Cloud", "Account & sync"), + ); + + const showFounderBadgeSetting = $derived( + matchesSearch( + founderBadgeSetting.title, + founderBadgeSetting.description, + "founder badge", + "titlebar", + "founder", + ), + ); + + const showCloudAccountCard = $derived(showCloudCardHeader || showFounderBadgeSetting); + const pluginHit = (plugin: Plugin) => matchesSearch(plugin.name, plugin.description, ...Object.values(plugin.settings).flatMap((s) => [s.title, s.description])); @@ -214,9 +236,10 @@ props: {} })} - {#if matchesSearch("BetterSEQTA Cloud", "Account & sync")} + {#if showCloudAccountCard}
+ {#if showCloudCardHeader}

BetterSEQTA Cloud

@@ -226,9 +249,28 @@
+ {/if} {#if cloudState.isLoggedIn} -
+
+ {#if showCloudCardHeader} showDisclaimer(onConfirm, onCancel, "Restore from cloud?", "This will replace your local settings with the cloud backup. Continue?")} /> + {/if} + {#if showFounderBadgeSetting} + {@render Setting({ + title: founderBadgeSetting.title, + description: founderBadgeSetting.description, + id: 17, + Component: Switch, + props: { + state: $settingsState.showTitlebarFounderBadge !== false, + onChange: (isOn: boolean) => (settingsState.showTitlebarFounderBadge = isOn), + }, + })} + {/if} +
+ {:else if showFounderBadgeSetting} +
+ Sign in to BetterSEQTA Cloud to manage your titlebar founder badge.
{/if}
diff --git a/src/seqta/ui/AddBetterSEQTAElements.ts b/src/seqta/ui/AddBetterSEQTAElements.ts index 85b34b57..bdc782af 100644 --- a/src/seqta/ui/AddBetterSEQTAElements.ts +++ b/src/seqta/ui/AddBetterSEQTAElements.ts @@ -16,6 +16,7 @@ import { updateAllColors } from "./colors/Manager"; import { delay } from "@/seqta/utils/delay"; import { LUCIDE_MOON_ICON_SVG } from "@/lib/icons/lucideMoon"; import { LUCIDE_SUN_ICON_SVG } from "@/lib/icons/lucideSun"; +import { ensureTitlebarFounderBadgeMounted, refreshTitlebarFounderBadge } from "@/seqta/ui/founderBadge/mountTitlebarFounderBadge"; let cachedUserInfo: any = null; let userInfoFetchPromise: Promise | null = null; @@ -181,6 +182,7 @@ async function handleUserInfoAndStudentData() { ]); updateUserInfo(userInfo); + ensureTitlebarFounderBadgeMounted(); await updateStudentInfo((await studentResponse.json()).payload, userInfo); } catch (error) { console.error( @@ -227,11 +229,16 @@ function updateUserInfo(info: { stringToHTML(/* html */ `
-
- - ${displayName ? `

${displayName}

` : ""} +
+
+ + +
+
+ ${displayName ? `

${displayName}

` : ""} + ${metadata ? `

${metadata}

` : ""} +
- ${metadata ? `

${metadata}

` : ""}
`).firstChild!, @@ -277,6 +284,7 @@ async function updateStudentInfo(students: any, info: Awaited
- ${displayName ? `

${displayName}

` : ""} - ${subText ? `

${subText}

` : ""} +
+ +
+ ${displayName ? `

${displayName}

` : ""} + ${subText ? `

${subText}

` : ""} +
+
`).firstChild!, ); + ensureTitlebarFounderBadgeMounted(); + const iconNode = stringToHTML(/* html */ `
diff --git a/src/seqta/ui/dev/hideSensitiveContent.ts b/src/seqta/ui/dev/hideSensitiveContent.ts index d2b44e7d..b8f86457 100644 --- a/src/seqta/ui/dev/hideSensitiveContent.ts +++ b/src/seqta/ui/dev/hideSensitiveContent.ts @@ -76,7 +76,7 @@ const contentConfig: ContentConfig = { }, }, userCode: { - selector: ".userInfoText > .userInfoCode", + selector: ".userInfoText .userInfoCode", action: (element) => { element.textContent = generateMockUserCode(); }, diff --git a/src/seqta/ui/founderBadge/mountTitlebarFounderBadge.ts b/src/seqta/ui/founderBadge/mountTitlebarFounderBadge.ts new file mode 100644 index 00000000..b4767ec9 --- /dev/null +++ b/src/seqta/ui/founderBadge/mountTitlebarFounderBadge.ts @@ -0,0 +1,79 @@ +import { cloudAuth } from "@/seqta/utils/CloudAuth"; +import { refreshCloudUserFromServer } from "@/seqta/utils/cloudPfpSync"; +import { settingsState } from "@/seqta/utils/listeners/SettingsState"; +import { + founderBadgeChipHtml, + pickPrimaryFounderBadge, + type FounderBadgeItem, +} from "@/seqta/utils/founderBadges"; +import { openFounderBadgeModal } from "@/seqta/ui/founderBadge/openFounderBadgeModal"; + +let subscribed = false; +let refreshPending = false; + +function renderBadgeChip( + slot: HTMLElement, + badge: FounderBadgeItem, + signupNumber?: number | null, +): void { + const house = slot + .closest(".userInfoHouseWrap") + ?.querySelector(".userInfohouse"); + if (house?.style.display === "none") { + slot.replaceChildren(); + slot.hidden = true; + return; + } + + slot.hidden = false; + slot.innerHTML = founderBadgeChipHtml(badge, { titlebar: true }); + + const chip = slot.querySelector(".bsplus-founder-badge"); + if (!chip) return; + + chip.setAttribute("aria-label", `${badge.label} — linked to your BetterSEQTA Cloud account`); + chip.addEventListener("click", () => openFounderBadgeModal(badge, signupNumber)); +} + +async function syncTitlebarFounderBadge(): Promise { + const slots = document.querySelectorAll(".titlebar .bsplus-founder-badge-slot"); + for (const slot of slots) { + slot.replaceChildren(); + slot.hidden = true; + } + + if (settingsState.showTitlebarFounderBadge === false || !cloudAuth.state.isLoggedIn) return; + + let user = cloudAuth.state.user; + if (user && user.signup_number == null && !user.badges?.length) { + if (!refreshPending) { + refreshPending = true; + try { + await refreshCloudUserFromServer(); + user = cloudAuth.state.user; + } finally { + refreshPending = false; + } + } + } + + const badge = pickPrimaryFounderBadge(user?.badges ?? [], user?.signup_number); + if (!badge) return; + + for (const slot of slots) { + renderBadgeChip(slot, badge, user?.signup_number); + } +} + +export function refreshTitlebarFounderBadge(): void { + void syncTitlebarFounderBadge(); +} + +export function ensureTitlebarFounderBadgeMounted(): void { + if (!subscribed) { + subscribed = true; + cloudAuth.subscribe(() => void syncTitlebarFounderBadge()); + settingsState.register("showTitlebarFounderBadge", () => void syncTitlebarFounderBadge()); + } + void syncTitlebarFounderBadge(); +} diff --git a/src/seqta/ui/founderBadge/openFounderBadgeModal.ts b/src/seqta/ui/founderBadge/openFounderBadgeModal.ts new file mode 100644 index 00000000..e6ad124f --- /dev/null +++ b/src/seqta/ui/founderBadge/openFounderBadgeModal.ts @@ -0,0 +1,84 @@ +import stringToHTML from "@/seqta/utils/stringToHTML"; +import { closePopup, openPopup } from "@/seqta/utils/Openers/PopupManager"; +import { openFounderBadgeSettings } from "@/seqta/ui/founderBadge/openFounderBadgeSettings"; +import { + founderBadgeChipHtml, + tierBlobStyle, + tierForBadgeKey, + type FounderBadgeItem, +} from "@/seqta/utils/founderBadges"; + +const ACCOUNTS_URL = "https://accounts.betterseqta.org"; + +function esc(value: string): string { + return value + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """); +} + +export function openFounderBadgeModal( + badge: FounderBadgeItem, + signupNumber?: number | null, +): void { + const tier = tierForBadgeKey(badge.key); + if (!tier) return; + + const header = stringToHTML(/* html */ ` +
+

${esc(badge.label)}

+

${esc(tier.rankLabel)}

+
+ `).firstChild as HTMLElement; + + const signupLine = + signupNumber != null + ? `` + : ""; + + const hero = stringToHTML(/* html */ ` +
+
+ + +
+ ${founderBadgeChipHtml(badge, { hero: true })} +
+
+
+ `).firstChild as HTMLElement; + + const text = stringToHTML(/* html */ ` +
+

${esc(tier.description)}

+

+ This badge is linked to your BetterSEQTA Cloud account at + accounts.betterseqta.org. + Your signup order is based on when you created your Cloud account and stays with you wherever you're signed in — including BetterSEQTA+. +

+ ${signupLine} +
+ + +
+
+ `).firstChild as HTMLElement; + + openPopup({ + header, + content: [hero, text], + animateSelector: ".whatsnewImgContainer, .whatsnewTextContainer *", + actions: [ + { id: "bsplus-founder-badge-dismiss", onClick: () => closePopup() }, + { + id: "bsplus-founder-badge-settings-link", + onClick: () => void closePopup().then(() => openFounderBadgeSettings()), + }, + ], + }); +} diff --git a/src/seqta/ui/founderBadge/openFounderBadgeSettings.ts b/src/seqta/ui/founderBadge/openFounderBadgeSettings.ts new file mode 100644 index 00000000..9b340f9b --- /dev/null +++ b/src/seqta/ui/founderBadge/openFounderBadgeSettings.ts @@ -0,0 +1,16 @@ +import { requestSettingsDestination } from "@/seqta/utils/settingsNavigation"; +import { openSettingsPopup } from "@/seqta/utils/setupSettingsButton"; + +const FOUNDER_BADGE_SETTING_SEARCH = "Titlebar Founder Badge"; + +/** Open BetterSEQTA+ settings on the titlebar founder badge toggle. */ +export async function openFounderBadgeSettings(): Promise { + requestSettingsDestination({ + page: "settings", + section: "account", + search: FOUNDER_BADGE_SETTING_SEARCH, + }); + await openSettingsPopup(); +} + +export { FOUNDER_BADGE_SETTING_SEARCH }; diff --git a/src/seqta/utils/CloudAuth.ts b/src/seqta/utils/CloudAuth.ts index e81d2633..4f183650 100644 --- a/src/seqta/utils/CloudAuth.ts +++ b/src/seqta/utils/CloudAuth.ts @@ -12,6 +12,12 @@ const STORAGE_KEYS = { user: "bsplus_user", } as const; +export type CloudBadge = { + key: string; + label: string; + awarded_at?: number; +}; + export type CloudUser = { id: string; email?: string; @@ -20,6 +26,9 @@ export type CloudUser = { pfpUrl?: string; pfpHash?: string | null; admin_level?: number; + signup_number?: number | null; + badges?: CloudBadge[]; + is_founding_2500?: boolean; }; export type CloudAuthState = { diff --git a/src/seqta/utils/Openers/PopupManager.ts b/src/seqta/utils/Openers/PopupManager.ts index 6bf68bdb..5dc86c09 100644 --- a/src/seqta/utils/Openers/PopupManager.ts +++ b/src/seqta/utils/Openers/PopupManager.ts @@ -3,8 +3,20 @@ import { animate as motionAnimate, stagger } from "motion"; type AnimationTarget = string | Element | Element[] | NodeList | null; +export interface PopupRoot { + background: HTMLElement; + container: HTMLElement; +} + +export interface PopupAction { + /** Element id inside popup content (e.g. button#bsplus-founder-badge-settings-link). */ + id: string; + onClick: () => void | Promise; +} + let isClosing = false; let pendingAfterClose: (() => void) | undefined; +let escapeListener: ((event: KeyboardEvent) => void) | null = null; function invokeAfterClose() { const fn = pendingAfterClose; @@ -12,9 +24,24 @@ function invokeAfterClose() { fn?.(); } +function detachEscapeListener() { + if (!escapeListener) return; + document.removeEventListener("keydown", escapeListener); + escapeListener = null; +} + +function attachEscapeListener() { + detachEscapeListener(); + escapeListener = (event: KeyboardEvent) => { + if (event.key === "Escape") void closePopup(); + }; + document.addEventListener("keydown", escapeListener); +} + export async function closePopup() { if (isClosing) return; isClosing = true; + detachEscapeListener(); const background = document.getElementById("whatsnewbk"); const popup = document.getElementsByClassName("whatsnewContainer")[0] as @@ -47,6 +74,7 @@ export async function closePopup() { interface OpenPopupOptions { header?: Node | null; + hero?: Node | null; content?: (Node | null | undefined)[]; animateSelector?: AnimationTarget; /** Called once after this popup is fully closed (including skip-animation path). */ @@ -55,6 +83,12 @@ interface OpenPopupOptions { clearJustUpdated?: boolean; /** Extra classes on `.whatsnewContainer` (e.g. `whatsnewContainer--scrollBody`). */ containerClass?: string; + /** Extra classes on `.whatsnewBackground` (e.g. frosted backdrop). */ + backgroundClass?: string; + /** Wire click handlers for buttons/links by element id (deep links, dismiss, etc.). */ + actions?: PopupAction[]; + /** Called after the popup DOM is mounted — use for one-off setup when actions are not enough. */ + onReady?: (root: PopupRoot) => void; } function chainAfterClose(next?: () => void) { @@ -66,13 +100,35 @@ function chainAfterClose(next?: () => void) { }; } +function applyClassList(element: HTMLElement, classNames?: string) { + if (!classNames) return; + for (const name of classNames.split(/\s+/)) { + if (name) element.classList.add(name); + } +} + +function wirePopupActions(actions?: PopupAction[]) { + if (!actions?.length) return; + queueMicrotask(() => { + for (const action of actions) { + document.getElementById(action.id)?.addEventListener("click", () => { + void Promise.resolve(action.onClick()); + }); + } + }); +} + export function openPopup({ header, + hero, content = [], animateSelector = ".whatsnewTextContainer *", afterClose, clearJustUpdated = false, containerClass, + backgroundClass, + actions, + onReady, }: OpenPopupOptions = {}) { if (document.getElementById("whatsnewbk")) { chainAfterClose(afterClose); @@ -84,15 +140,13 @@ export function openPopup({ const background = document.createElement("div"); background.id = "whatsnewbk"; background.classList.add("whatsnewBackground"); + applyClassList(background, backgroundClass); const container = document.createElement("div"); container.classList.add("whatsnewContainer"); - if (containerClass) { - for (const name of containerClass.split(/\s+/)) { - if (name) container.classList.add(name); - } - } + applyClassList(container, containerClass); + if (hero) container.append(hero); if (header) container.append(header); for (const node of content) if (node) container.append(node); @@ -139,4 +193,7 @@ export function openPopup({ }); closeButton.addEventListener("click", () => void closePopup()); + attachEscapeListener(); + wirePopupActions(actions); + onReady?.({ background, container }); } diff --git a/src/seqta/utils/cloudPfpSync.ts b/src/seqta/utils/cloudPfpSync.ts index 9532597e..016f86fe 100644 --- a/src/seqta/utils/cloudPfpSync.ts +++ b/src/seqta/utils/cloudPfpSync.ts @@ -72,6 +72,9 @@ function mergeMeIntoUser(current: CloudUser, data: Record): Clo username: (raw.username as string | undefined) ?? current.username, displayName: (raw.displayName as string | undefined) ?? current.displayName, admin_level: (raw.admin_level as number | undefined) ?? current.admin_level, + signup_number: (raw.signup_number as number | null | undefined) ?? current.signup_number, + badges: (raw.badges as CloudUser["badges"]) ?? current.badges, + is_founding_2500: (raw.is_founding_2500 as boolean | undefined) ?? current.is_founding_2500, pfpUrl, pfpHash, }; diff --git a/src/seqta/utils/defaultSettings.ts b/src/seqta/utils/defaultSettings.ts index 3d019ade..bcd57396 100644 --- a/src/seqta/utils/defaultSettings.ts +++ b/src/seqta/utils/defaultSettings.ts @@ -74,6 +74,7 @@ export function getDefaultSettingsState(): SettingsState { adaptiveThemeColourTransition: true, themeOfTheMonthDisabled: false, autoCloudSettingsSync: true, + showTitlebarFounderBadge: true, selectedFont: "rubik", timeFormat: "24", privacyStatementShown: false, diff --git a/src/seqta/utils/founderBadges.ts b/src/seqta/utils/founderBadges.ts new file mode 100644 index 00000000..f6c5f69e --- /dev/null +++ b/src/seqta/utils/founderBadges.ts @@ -0,0 +1,165 @@ +/** Founder badge tiers — keep in sync with betterseqta-accounts/utils/badges.ts */ + +export const BADGE_TIERS = [ + { + key: "founder_10", + label: "Pioneer", + threshold: 10, + rankLabel: "Top 10", + description: "One of the first 10 people to create a BetterSEQTA Cloud account.", + base: "#78350f", + blobs: ["rgba(251,191,36,0.58)", "rgba(234,88,12,0.48)", "rgba(254,243,199,0.42)"], + icon: "sparkles", + }, + { + key: "founder_25", + label: "Early Adopter", + threshold: 25, + rankLabel: "Top 25", + description: "One of the first 25 people to join BetterSEQTA Cloud.", + base: "#1e3a8a", + blobs: ["rgba(79,70,229,0.52)", "rgba(37,99,235,0.46)", "rgba(129,140,248,0.38)"], + icon: "sparkles", + }, + { + key: "founder_50", + label: "Founding Member", + threshold: 50, + rankLabel: "Top 50", + description: "One of the first 50 Cloud members — an early supporter of BetterSEQTA.", + base: "#0c4a6e", + blobs: ["rgba(2,132,199,0.5)", "rgba(13,148,136,0.44)", "rgba(56,189,248,0.36)"], + icon: "star", + }, + { + key: "founder_100", + label: "Centurion", + threshold: 100, + rankLabel: "Top 100", + description: "Among the first 100 BetterSEQTA Cloud accounts ever created.", + base: "#064e3b", + blobs: ["rgba(5,150,105,0.5)", "rgba(22,163,74,0.44)", "rgba(52,211,153,0.36)"], + icon: "star", + }, + { + key: "founder_250", + label: "Quarter Thousand", + threshold: 250, + rankLabel: "Top 250", + description: "One of the first 250 people to sign up for BetterSEQTA Cloud.", + base: "#7c2d12", + blobs: ["rgba(217,119,6,0.52)", "rgba(234,88,12,0.46)", "rgba(251,191,36,0.38)"], + icon: "trophy", + }, + { + key: "founder_500", + label: "Half Thousand", + threshold: 500, + rankLabel: "Top 500", + description: "Among the first 500 BetterSEQTA Cloud members.", + base: "#7c2d12", + blobs: ["rgba(234,88,12,0.52)", "rgba(249,115,22,0.46)", "rgba(251,146,60,0.38)"], + icon: "trophy", + }, + { + key: "founder_1000", + label: "Thousand Club", + threshold: 1000, + rankLabel: "Top 1,000", + description: "One of the first 1,000 BetterSEQTA Cloud accounts.", + base: "#881337", + blobs: ["rgba(225,29,72,0.5)", "rgba(219,39,119,0.44)", "rgba(251,113,133,0.36)"], + icon: "fire", + }, + { + key: "founder_2500", + label: "Founding Cloud", + threshold: 2500, + rankLabel: "Top 2,500", + description: "One of the first 2,500 Cloud members — part of the founding generation of BetterSEQTA Cloud.", + base: "#713f12", + blobs: ["rgba(245,158,11,0.52)", "rgba(234,179,8,0.46)", "rgba(252,211,77,0.4)"], + icon: "fire", + }, +] as const; + +export type BadgeKey = (typeof BADGE_TIERS)[number]["key"]; + +export type FounderBadgeItem = { + key: string; + label: string; + awarded_at?: number; +}; + +const TIER_BY_KEY = new Map(BADGE_TIERS.map((t) => [t.key, t])); + +export function tierForBadgeKey(key: string) { + return TIER_BY_KEY.get(key as BadgeKey); +} + +export function primaryFounderBadgeKey(signupNumber: number): BadgeKey | null { + const tier = BADGE_TIERS.find((t) => signupNumber <= t.threshold); + return tier?.key ?? null; +} + +export function pickPrimaryFounderBadge( + badges: FounderBadgeItem[], + signupNumber?: number | null, +): FounderBadgeItem | null { + if (signupNumber != null) { + const key = primaryFounderBadgeKey(signupNumber); + if (!key) return null; + return badges.find((b) => b.key === key) ?? { key, label: TIER_BY_KEY.get(key)?.label ?? key }; + } + + if (badges.length === 0) return null; + + let best: FounderBadgeItem | null = null; + let bestThreshold = Infinity; + for (const badge of badges) { + const tier = TIER_BY_KEY.get(badge.key as BadgeKey); + if (tier && tier.threshold < bestThreshold) { + bestThreshold = tier.threshold; + best = badge; + } + } + return best; +} + +const ICON_PATHS: Record = { + sparkles: + "M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 00-2.456 2.456zM16.894 20.567L16.5 21.75l-.394-1.183a2.25 2.25 0 00-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 001.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 001.423 1.423l1.183.394-1.183.394a2.25 2.25 0 00-1.423 1.423z", + star: "M10.788 3.21c.448-1.077 1.976-1.077 2.424 0l2.082 5.006 5.404.434c1.164.093 1.636 1.545.749 2.305l-4.117 3.527 1.257 5.273c.271 1.136-.964 2.033-1.96 1.425L12 18.354 7.373 21.18c-.996.608-2.231-.29-1.96-1.425l1.257-5.273-4.117-3.527c-.887-.76-.415-2.212.749-2.305l5.404-.434 2.082-5.005z", + trophy: + "M16.5 18.75h-9m9 0a3 3 0 013 3h-15a3 3 0 013-3m9 0v-3.375c0-.621-.503-1.125-1.125-1.125h-.871M7.5 18.75v-3.375c0-.621.504-1.125 1.125-1.125h.872m5.007 0H9.497m5.007 0a7.454 7.454 0 01-.982-3.172M9.497 14.25a7.454 7.454 0 00.981-3.172M5.25 4.236c-.982.143-1.954.317-2.916.52A6.003 6.003 0 007.73 9.728M5.25 4.236V4.5c0 2.108.966 3.99 2.48 5.228M5.25 4.236V2.721C7.456 2.41 9.71 2.25 12 2.25c2.291 0 4.545.16 6.75.47v1.516M7.73 9.728a6.726 6.726 0 002.748 1.35m8.272-6.842V4.5c0 2.108-.966 3.99-2.48 5.228m2.48-5.492a46.32 46.32 0 012.916.52 6.003 6.003 0 01-5.395 4.972m0 0a6.726 6.726 0 01-2.749 1.35m0 0a6.726 6.726 0 01-3.128 0m3.128 0a6.726 6.726 0 01-3.128 0", + fire: "M15.362 5.214A8.252 8.252 0 0112 21 8.25 8.25 0 016.038 7.048 8.287 8.287 0 009 9.6a8.983 8.983 0 013.361-6.867 8.21 8.21 0 003 2.48zM12 18a3.75 3.75 0 00.495-7.467 5.99 5.99 0 00-1.925 3.546 5.974 5.974 0 01-2.133-1A3.75 3.75 0 0012 18z", +}; + +export function badgeIconSvg(icon: string, size = 15): string { + const path = ICON_PATHS[icon] ?? ICON_PATHS.sparkles; + return ``; +} + +export function tierBlobStyle(tier: (typeof BADGE_TIERS)[number]): string { + return [ + `--badge-base:${tier.base}`, + `--badge-blob-a:${tier.blobs[0]}`, + `--badge-blob-b:${tier.blobs[1]}`, + `--badge-blob-c:${tier.blobs[2]}`, + ].join(";"); +} + +export function founderBadgeChipHtml( + badge: FounderBadgeItem, + options?: { hero?: boolean; titlebar?: boolean }, +): string { + const tier = tierForBadgeKey(badge.key); + if (!tier) return ""; + + const hero = options?.hero ?? false; + const titlebar = options?.titlebar ?? false; + const mods = `${hero ? " bsplus-founder-badge--hero" : ""}${titlebar ? " bsplus-founder-badge--titlebar" : ""}`; + const icon = titlebar ? "" : badgeIconSvg(tier.icon, hero ? 20 : 15); + + return ``; +} diff --git a/src/seqta/utils/settingsNavigation.ts b/src/seqta/utils/settingsNavigation.ts index 8290d9ab..8b05cdf3 100644 --- a/src/seqta/utils/settingsNavigation.ts +++ b/src/seqta/utils/settingsNavigation.ts @@ -1,5 +1,5 @@ export type SettingsDestination = - | { page: "settings"; section?: string } + | { page: "settings"; section?: string; search?: string } | { page: "themes" | "backgrounds"; view?: "settings" | "store" }; export const SETTINGS_NAVIGATION_EVENT = "bsplus:navigate-settings"; diff --git a/src/types/storage.ts b/src/types/storage.ts index 8edd8f05..2b7b3fc0 100644 --- a/src/types/storage.ts +++ b/src/types/storage.ts @@ -96,6 +96,8 @@ export interface SettingsState { // BetterSEQTA Cloud (accounts.betterseqta.org) — stored via CloudAuth, not settingsState /** When not `false`, automatic cloud settings sync is enabled (default-on). */ autoCloudSettingsSync?: boolean; + /** When not `false`, show the Cloud founder badge in the SEQTA titlebar (default-on). */ + showTitlebarFounderBadge?: boolean; } interface ToggleItem {