Move the window global in settings.ts to Alu.settings

This commit is contained in:
wearrrrr 2024-08-06 23:17:17 -05:00
parent 255488ad16
commit 0765072ea2
6 changed files with 17 additions and 15 deletions

5
src/alu.d.ts vendored
View file

@ -1,7 +1,10 @@
export declare global {
namespace Alu {
let store: AluStore;
let loadedContentStorage: Record<string, string>;
let settings: {
loadedContentStorage: Record<string, string>;
currentTab: string;
};
type DefaultKeys = {
[key: string]: AluKey;

View file

@ -4,7 +4,10 @@ function instantiateAlu() {
if (globalThis.Alu) return;
globalThis.Alu = {
store: new AluStore(),
loadedContentStorage: {},
settings: {
loadedContentStorage: {},
currentTab: "",
}
};
}

View file

@ -1,13 +1,13 @@
window.loadedContentStorage = {};
window.currentlySelectedTab;
// Alu.settings.loadedContentStorage = {};
document.addEventListener("astro:before-swap", () => {
window.currentlySelectedTab = "";
Alu.settings.currentTab = "";
Alu.settings.loadedContentStorage = {};
});
function settingsLoad() {
Array.from(document.getElementsByClassName("setting-tab")).forEach((tab) => {
const contentToLoad = document.getElementById("content-" + tab.id);
if (contentToLoad) {
window.loadedContentStorage[tab.id] = contentToLoad.innerHTML;
Alu.settings.loadedContentStorage[tab.id] = contentToLoad.innerHTML;
contentToLoad.remove();
}
@ -18,13 +18,13 @@ function settingsLoad() {
});
}
function loadContent(tabID: string) {
if (window.currentlySelectedTab == tabID) return;
else window.currentlySelectedTab = tabID;
if (Alu.settings.currentTab == tabID) return;
else Alu.settings.currentTab = tabID;
const currentContent = document.getElementById("current-content");
if (currentContent) {
currentContent.style.opacity = "0";
setTimeout(() => {
currentContent.innerHTML = window.loadedContentStorage[tabID];
currentContent.innerHTML = Alu.settings.loadedContentStorage[tabID];
currentContent.style.opacity = "1";
document.dispatchEvent(new CustomEvent("setting-tabLoad", { detail: tabID }));
}, 250);
@ -84,7 +84,6 @@ function getLocalStorageValue(localStorageItem: Alu.ValidStoreKeys, dropdownID:
const dropdownMenu = document.getElementById(dropdownID + "-menu") as HTMLElement;
// Janky hack :D
if (dropdownID == "dropdown__search-engine") {
console.log(localStorageItem, dropdownID)
return Alu.store.get(localStorageItem).name;
}

View file

@ -45,7 +45,6 @@ export function getStaticPaths() {
game.style.display = "none";
}
}
console.log(results);
if (results === 0) {
const noResults = document.querySelector(".no-results") as HTMLDivElement;
if (noResults) {

View file

@ -27,6 +27,8 @@
gtag("config", "G-P1JX4G9KSF");
</script>
<script>
import instantiateAlu from "@components/ts/Alu";
instantiateAlu();
const lang = Alu.store.get("lang");
const redirect = (loc: string) => (window.location.href = loc);
if (lang) {

4
src/types.d.ts vendored
View file

@ -8,11 +8,7 @@ interface Window {
__uv$location: Location;
loadFormContent: () => Promise<void> | null;
idb: IDBDatabase;
// Why is this not already on Window?
eval(string): void;
wispData: WispData[];
loadedContentStorage: Record<string, string>;
currentlySelectedTab: string;
}
type ExtType = "serviceWorker" | "theme" | "page";