mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
feat(engage): inject settings button, dark/light toggle, and user info with logout
Made-with: Cursor
This commit is contained in:
@@ -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 */ `
|
||||
<button class="addedButton tooltip" id="AddedSettings">
|
||||
<svg width="24" height="24" viewBox="0 0 24 24">
|
||||
@@ -276,17 +281,101 @@ async function createSettingsButton() {
|
||||
);
|
||||
}
|
||||
|
||||
async function getEngageUserInfo() {
|
||||
const response = await fetch(`${location.origin}/seqta/parent/login`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json; charset=utf-8" },
|
||||
body: JSON.stringify({
|
||||
mode: "normal",
|
||||
query: null,
|
||||
redirect_url: location.origin + "/",
|
||||
}),
|
||||
});
|
||||
return (await response.json()).payload as {
|
||||
userDesc: string | null;
|
||||
userName: string | null;
|
||||
userCode: string | null;
|
||||
email: string | null;
|
||||
type: string | null;
|
||||
};
|
||||
}
|
||||
|
||||
async function addEngageUserInfo() {
|
||||
const content = await waitForElm("#content") as HTMLElement;
|
||||
|
||||
let info: Awaited<ReturnType<typeof getEngageUserInfo>>;
|
||||
try {
|
||||
info = await getEngageUserInfo();
|
||||
} catch (error) {
|
||||
console.error("[BetterSEQTA+] Failed to get Engage user info:", error);
|
||||
return;
|
||||
}
|
||||
|
||||
const displayName = info.userDesc || info.userName || "";
|
||||
const subText = info.userCode || info.email || "";
|
||||
|
||||
const titlebar = document.createElement("div");
|
||||
titlebar.classList.add("titlebar", "engage-titlebar");
|
||||
|
||||
titlebar.append(
|
||||
stringToHTML(/* html */ `
|
||||
<div class="userInfo">
|
||||
<div class="userInfoText">
|
||||
${displayName ? `<p class="userInfoName">${displayName}</p>` : ""}
|
||||
${subText ? `<p class="userInfoCode">${subText}</p>` : ""}
|
||||
</div>
|
||||
</div>
|
||||
`).firstChild!,
|
||||
);
|
||||
|
||||
const iconNode = stringToHTML(/* html */ `
|
||||
<div class="userInfosvgdiv tooltip" id="engage-logouttooltip-wrap">
|
||||
<svg class="userInfosvg" viewBox="0 0 24 24"><path fill="var(--text-primary)" d="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"></path></svg>
|
||||
<div class="tooltiptext topmenutooltip" id="engage-logouttooltip">
|
||||
<button class="logout engage-logout">
|
||||
<svg style="width:20px;height:20px;vertical-align:middle;" viewBox="0 0 24 24"><path fill="currentColor" d="M17 7L15.59 8.41L18.17 11H8V13H18.17L15.59 15.58L17 17L22 12M4 5H12V3H4C2.9 3 2 3.9 2 5V19C2 20.1 2.9 21 4 21H12V19H4V5Z"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`).firstChild!;
|
||||
|
||||
titlebar.append(iconNode);
|
||||
content.appendChild(titlebar);
|
||||
|
||||
titlebar.querySelector<HTMLElement>(".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 */ `<defs><clipPath id="__lottie_element_80"><rect width="24" height="24" x="0" y="0"></rect></clipPath></defs><g clip-path="url(#__lottie_element_80)"><g style="display: block;" transform="matrix(1,0,0,1,12,12)" opacity="1"><g opacity="1" transform="matrix(1,0,0,1,0,0)"><path fill-opacity="1" d=" M0,-4 C-2.2100000381469727,-4 -4,-2.2100000381469727 -4,0 C-4,2.2100000381469727 -2.2100000381469727,4 0,4 C2.2100000381469727,4 4,2.2100000381469727 4,0 C4,-2.2100000381469727 2.2100000381469727,-4 0,-4z"></path></g></g><g style="display: block;" transform="matrix(1,0,0,1,12,12)" opacity="1"><g opacity="1" transform="matrix(1,0,0,1,0,0)"><path fill-opacity="1" d=" M0,6 C-3.309999942779541,6 -6,3.309999942779541 -6,0 C-6,-3.309999942779541 -3.309999942779541,-6 0,-6 C3.309999942779541,-6 6,-3.309999942779541 6,0 C6,3.309999942779541 3.309999942779541,6 0,6z M8,-3.309999942779541 C8,-3.309999942779541 8,-8 8,-8 C8,-8 3.309999942779541,-8 3.309999942779541,-8 C3.309999942779541,-8 0,-11.3100004196167 0,-11.3100004196167 C0,-11.3100004196167 -3.309999942779541,-8 -3.309999942779541,-8 C-3.309999942779541,-8 -8,-8 -8,-8 C-8,-8 -8,-3.309999942779541 -8,-3.309999942779541 C-8,-3.309999942779541 -11.3100004196167,0 -11.3100004196167,0 C-11.3100004196167,0 -8,3.309999942779541 -8,3.309999942779541 C-8,3.309999942779541 -8,8 -8,8 C-8,8 -3.309999942779541,8 -3.309999942779541,8 C-3.309999942779541,8 0,11.3100004196167 0,11.3100004196167 C0,11.3100004196167 3.309999942779541,8 3.309999942779541,8 C3.309999942779541,8 8,8 8,8 C8,8 8,3.309999942779541 8,3.309999942779541 C8,3.309999942779541 11.3100004196167,0 11.3100004196167,0 C11.3100004196167,0 8,-3.309999942779541 8,-3.309999942779541z"></path></g></g></g>`;
|
||||
const MOON_ICON_SVG = /* html */ `<defs><clipPath id="__lottie_element_263"><rect width="24" height="24" x="0" y="0"></rect></clipPath></defs><g clip-path="url(#__lottie_element_263)"><g style="display: block;" transform="matrix(1.5,0,0,1.5,7,12)" opacity="1"><g opacity="1" transform="matrix(1,0,0,1,0,0)"><path fill-opacity="1" d=" M0,-4 C-2.2100000381469727,-4 -1.2920000553131104,-2.2100000381469727 -1.2920000553131104,0 C-1.2920000553131104,2.2100000381469727 -2.2100000381469727,4 0,4 C2.2100000381469727,4 4,2.2100000381469727 4,0 C4,-2.2100000381469727 2.2100000381469727,-4 0,-4z"></path></g></g><g style="display: block;" transform="matrix(-1,0,0,-1,12,12)" opacity="1"><g opacity="1" transform="matrix(1,0,0,1,0,0)"><path fill-opacity="1" d=" M0,6 C-3.309999942779541,6 -6,3.309999942779541 -6,0 C-6,-3.309999942779541 -3.309999942779541,-6 0,-6 C3.309999942779541,-6 6,-3.309999942779541 6,0 C6,3.309999942779541 3.309999942779541,6 0,6z M8,-3.309999942779541 C8,-3.309999942779541 8,-8 8,-8 C8,-8 3.309999942779541,-8 3.309999942779541,-8 C3.309999942779541,-8 0,-11.3100004196167 0,-11.3100004196167 C0,-11.3100004196167 -3.309999942779541,-8 -3.309999942779541,-8 C-3.309999942779541,-8 -8,-8 -8,-8 C-8,-8 -8,-3.309999942779541 -8,-3.309999942779541 C-8,-3.309999942779541 -11.3100004196167,0 -11.3100004196167,0 C-11.3100004196167,0 -8,3.309999942779541 -8,3.309999942779541 C-8,3.309999942779541 -8,8 -8,8 C-8,8 -3.309999942779541,8 -3.309999942779541,8 C-3.309999942779541,8 0,11.3100004196167 0,11.3100004196167 C0,11.3100004196167 3.309999942779541,8 3.309999942779541,8 C3.309999942779541,8 8,8 8,8 C8,8 8,3.309999942779541 8,3.309999942779541 C8,3.309999942779541 11.3100004196167,0 11.3100004196167,0 C11.3100004196167,0 8,-3.309999942779541 8,-3.309999942779541z"></path></g></g></g>`;
|
||||
|
||||
document.getElementById("content")!.append(
|
||||
const toggleTarget = parent ?? document.getElementById("content")!;
|
||||
toggleTarget.append(
|
||||
stringToHTML(/* html */ `
|
||||
<button class="addedButton DarkLightButton tooltip" id="LightDarkModeButton">
|
||||
<svg xmlns="http://www.w3.org/2000/svg">${settingsState.DarkMode ? SUN_ICON_SVG : MOON_ICON_SVG}</svg>
|
||||
|
||||
Reference in New Issue
Block a user