mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-08-28 17:21:05 +00:00
feat: fixes and improvements to app store icons plugins
This commit is contained in:
@@ -1,83 +1,82 @@
|
|||||||
import type { Plugin } from "../../core/types";
|
import type { Plugin } from "@/plugins/core/types";
|
||||||
|
import { resolveExtensionAssetUrl } from "@/lib/extensionAssetUrl";
|
||||||
import appstoredark from "@/resources/icons/dlappstore-dark.svg";
|
import appstoredark from "@/resources/icons/dlappstore-dark.svg";
|
||||||
import appstorelight from "@/resources/icons/dlappstore-light.svg";
|
import appstorelight from "@/resources/icons/dlappstore-light.svg";
|
||||||
import gplayicon from "@/resources/icons/googleplay.svg";
|
import gplayicon from "@/resources/icons/googleplay.svg";
|
||||||
|
import styles from "./styles.css?inline";
|
||||||
|
|
||||||
|
const APPSTORE =
|
||||||
|
'a[href="https://itunes.apple.com/au/app/seqta-learn/id1143069793"]>img';
|
||||||
|
const GOOGLEPLAY =
|
||||||
|
'a[href="https://play.google.com/store/apps/details?id=com.seqta.android.learn"]>img';
|
||||||
|
|
||||||
|
const APPSTORE_DARK = resolveExtensionAssetUrl(appstoredark);
|
||||||
|
const APPSTORE_LIGHT = resolveExtensionAssetUrl(appstorelight);
|
||||||
|
const GOOGLEPLAY_ICON = resolveExtensionAssetUrl(gplayicon);
|
||||||
|
|
||||||
const appIconPlugin: Plugin<{}, {}> = {
|
const appIconPlugin: Plugin<{}, {}> = {
|
||||||
id: "app-icons",
|
id: "app-icons",
|
||||||
name: "App Icons",
|
name: "App Icons",
|
||||||
description: "Fixes the unthemed playstore and app store icons in the SEQTA download page in settings.",
|
description:
|
||||||
|
"Fixes unthemed App Store and Google Play icons on the SEQTA settings download page.",
|
||||||
version: "1.0.0",
|
version: "1.0.0",
|
||||||
settings: {},
|
settings: {},
|
||||||
disableToggle: true,
|
disableToggle: true,
|
||||||
|
styles,
|
||||||
|
|
||||||
run: async (api) => {
|
run: async (api) => {
|
||||||
const appstoreSelector =
|
let domObserver: MutationObserver | null = null;
|
||||||
'a[href="https://itunes.apple.com/au/app/seqta-learn/id1143069793"]>img';
|
|
||||||
const googleplaySelector =
|
|
||||||
'a[href="https://play.google.com/store/apps/details?id=com.seqta.android.learn"]>img';
|
|
||||||
|
|
||||||
let observer: MutationObserver | null = null;
|
|
||||||
let classObserver: MutationObserver | null = null;
|
|
||||||
|
|
||||||
const updateIcons = () => {
|
const updateIcons = () => {
|
||||||
const appstore =
|
const appstore = document.querySelector<HTMLImageElement>(APPSTORE);
|
||||||
document.querySelector<HTMLImageElement>(appstoreSelector);
|
const googleplay = document.querySelector<HTMLImageElement>(GOOGLEPLAY);
|
||||||
const googleplay =
|
const dark = document.documentElement.classList.contains("dark");
|
||||||
document.querySelector<HTMLImageElement>(googleplaySelector);
|
|
||||||
|
|
||||||
const isDark =
|
|
||||||
document.documentElement.classList.contains("dark");
|
|
||||||
|
|
||||||
if (appstore) {
|
if (appstore) {
|
||||||
appstore.src = isDark ? appstoredark : appstorelight;
|
appstore.src = dark ? APPSTORE_DARK : APPSTORE_LIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (googleplay && appstore) {
|
if (googleplay) {
|
||||||
googleplay.src = gplayicon;
|
googleplay.src = GOOGLEPLAY_ICON;
|
||||||
googleplay.style.width = `130px`;
|
googleplay.classList.add("bsplus-googleplay-badge");
|
||||||
googleplay.style.height = `40px`;
|
|
||||||
googleplay.style.objectFit = "contain";
|
|
||||||
googleplay.style.flexShrink = "0";
|
|
||||||
googleplay.style.marginLeft = "8px";
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const ensureObserver = () => {
|
const watchDom = () => {
|
||||||
observer?.disconnect();
|
domObserver?.disconnect();
|
||||||
|
domObserver = new MutationObserver(updateIcons);
|
||||||
observer = new MutationObserver(() => {
|
domObserver.observe(document.body, { childList: true, subtree: true });
|
||||||
updateIcons();
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(document.body, {
|
|
||||||
childList: true,
|
|
||||||
subtree: true,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onHashChange = () => {
|
const stopDomWatch = () => {
|
||||||
if (window.location.hash === "#?page=/settings") {
|
domObserver?.disconnect();
|
||||||
|
domObserver = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSettingsPage = (page: string) => {
|
||||||
|
if (page === "settings") {
|
||||||
updateIcons();
|
updateIcons();
|
||||||
ensureObserver();
|
watchDom();
|
||||||
} else {
|
} else {
|
||||||
observer?.disconnect();
|
stopDomWatch();
|
||||||
observer = null;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("hashchange", onHashChange);
|
const pageChange = api.seqta.onPageChange(onSettingsPage);
|
||||||
|
|
||||||
classObserver = new MutationObserver(updateIcons);
|
const themeObserver = new MutationObserver(updateIcons);
|
||||||
classObserver.observe(document.documentElement, {
|
themeObserver.observe(document.documentElement, {
|
||||||
attributes: true,
|
attributes: true,
|
||||||
attributeFilter: ["class"],
|
attributeFilter: ["class"],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (window.location.hash === "#?page=/settings") {
|
onSettingsPage(api.seqta.getCurrentPage());
|
||||||
updateIcons();
|
|
||||||
ensureObserver();
|
return () => {
|
||||||
}
|
pageChange.unregister();
|
||||||
|
stopDomWatch();
|
||||||
|
themeObserver.disconnect();
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
.bsplus-googleplay-badge {
|
||||||
|
width: 130px;
|
||||||
|
height: 40px;
|
||||||
|
object-fit: contain;
|
||||||
|
flex-shrink: 0;
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user