diff --git a/src/seqta/ui/AddBetterSEQTAElements.ts b/src/seqta/ui/AddBetterSEQTAElements.ts index a2d91d79..05b87b55 100644 --- a/src/seqta/ui/AddBetterSEQTAElements.ts +++ b/src/seqta/ui/AddBetterSEQTAElements.ts @@ -3,6 +3,7 @@ import { isSeqtaEngageExperience } from "@/seqta/utils/isSeqtaEngage"; import { loadHomePage } from "@/seqta/utils/Loaders/LoadHomePage"; import { SendNewsPage } from "@/seqta/utils/SendNewsPage"; import { setupSettingsButton } from "@/seqta/utils/setupSettingsButton"; +import { waitForElm } from "@/seqta/utils/waitForElm"; import { GetThresholdOfColor } from "@/seqta/ui/colors/getThresholdColour"; import { appendBackgroundToUI } from "./ImageBackgrounds"; @@ -44,7 +45,10 @@ export async function getUserInfo() { export async function AddBetterSEQTAElements() { if (isSeqtaEngageExperience()) { + await waitForElm("#content"); addExtensionSettings(); + void setupEngageSettingsButton(); + void addEngageUserInfo(); return; } @@ -263,8 +267,9 @@ function setupEventListeners() { }); } -async function createSettingsButton() { - document.getElementById("content")!.append( +async function createSettingsButton(parent?: Element) { + const target = parent ?? document.getElementById("content")!; + target.append( stringToHTML(/* html */ ` + + + `).firstChild!; + + titlebar.append(iconNode); + content.appendChild(titlebar); + + titlebar.querySelector(".engage-logout")?.addEventListener("click", async () => { + await fetch(`${location.origin}/seqta/parent/logout`, { method: "POST" }); + location.reload(); + }); +} + +async function setupEngageSettingsButton() { + try { + const notificationsWrapper = await waitForElm( + "#content > div.connectedNotificationsWrapper > div", + ); + const parent = notificationsWrapper.parentElement!; + await addDarkLightToggle(parent); + await createSettingsButton(parent); + setupSettingsButton(); + } catch { + await addDarkLightToggle(); + await createSettingsButton(); + setupSettingsButton(); + } +} + function GetLightDarkModeString() { return settingsState.DarkMode ? "Switch to light theme" : "Switch to dark theme"; } -async function addDarkLightToggle() { +async function addDarkLightToggle(parent?: Element) { const SUN_ICON_SVG = /* html */ ``; const MOON_ICON_SVG = /* html */ ``; - document.getElementById("content")!.append( + const toggleTarget = parent ?? document.getElementById("content")!; + toggleTarget.append( stringToHTML(/* html */ `