Define an addEventListener overload in alu.d.ts to prevent an annoying cast in settings.ts

This commit is contained in:
wearrrrr 2024-10-27 22:27:02 -05:00
parent c819bce83e
commit f7ad2e3ba0
2 changed files with 9 additions and 9 deletions

5
src/alu.d.ts vendored
View file

@ -6,6 +6,11 @@ export declare global {
reset: (key: Alu.ValidStoreKeys) => void; reset: (key: Alu.ValidStoreKeys) => void;
}; };
// Hacky way to not have to cast the "event" type that lib.dom has to CustomEvent, which is what we actually use.
interface Document {
addEventListener(type: "setting-tabLoad", listener: (this: Document, ev: CustomEvent) => unknown, options?: boolean | AddEventListenerOptions): void;
}
namespace Alu { namespace Alu {
let store: AluStore; let store: AluStore;
let settings: { let settings: {

View file

@ -93,8 +93,6 @@ function getLocalStorageValue(localStorageItem: Alu.ValidStoreKeys, dropdownID:
const dropdownItem = Array.from(dropdownMenu.children).find((dropdown) => { const dropdownItem = Array.from(dropdownMenu.children).find((dropdown) => {
const itemEl = dropdown as HTMLElement; const itemEl = dropdown as HTMLElement;
const item = Alu.store.get(localStorageItem); const item = Alu.store.get(localStorageItem);
console.log("Item Value " + item.value);
console.log("Dataset Setting " + itemEl.dataset.setting);
const find = item.value == itemEl.dataset.setting; const find = item.value == itemEl.dataset.setting;
if (!find && localStorageItem == "wisp" && item.isCustom) { if (!find && localStorageItem == "wisp" && item.isCustom) {
// This means we are on localhost, default to custom and return it's innerText (This is a hack) // This means we are on localhost, default to custom and return it's innerText (This is a hack)
@ -140,11 +138,10 @@ function applyDropdownEventListeners(dropdown: HTMLElement | null, optionalCallb
Alu.store.set(localStorageItem, localStorageItemContent); Alu.store.set(localStorageItem, localStorageItemContent);
applySavedLocalStorage(localStorageItem, dropdown.id); applySavedLocalStorage(localStorageItem, dropdown.id);
closeDropdown(dropdownSibling.id); closeDropdown(dropdownSibling.id);
if (typeof optionalCallback === "function") { return optionalCallback?.();
optionalCallback();
}
}; };
}); });
} }
function applyInputListeners(inputs: HTMLInputElement[], localStorageItem: Alu.ValidStoreKeys[]) { function applyInputListeners(inputs: HTMLInputElement[], localStorageItem: Alu.ValidStoreKeys[]) {
@ -188,8 +185,6 @@ function addThemeToDropdown(extension: ExtensionMetadata) {
} }
} }
loadContent("setting-tab-proxy");
function setupProxySettings() { function setupProxySettings() {
applySavedLocalStorage("proxy", "dropdown__selected-proxy"); applySavedLocalStorage("proxy", "dropdown__selected-proxy");
applySavedLocalStorage("search", "dropdown__search-engine"); applySavedLocalStorage("search", "dropdown__search-engine");
@ -369,8 +364,7 @@ function checkCustomWisp() {
} }
document.addEventListener("setting-tabLoad", (event) => { document.addEventListener("setting-tabLoad", (event) => {
// I hate doing this :/ setupSettings(event);
setupSettings(event as CustomEvent);
}); });
function navigateToNewLangaugePage() { function navigateToNewLangaugePage() {
@ -383,4 +377,5 @@ document.addEventListener("astro:after-swap", () => {
settingsLoad(); settingsLoad();
loadContent("setting-tab-proxy"); loadContent("setting-tab-proxy");
}); });
loadContent("setting-tab-proxy");
settingsLoad(); settingsLoad();