Browse Source

ref: siteevents emit function

Sven 9 months ago
parent
commit
2f046f714e

+ 3 - 3
src/components/hotkeyInput.ts

@@ -1,4 +1,4 @@
-import { siteEvents } from "../siteEvents.js";
+import { emitSiteEvent, siteEvents } from "../siteEvents.js";
 import { onInteraction, t } from "../utils/index.js";
 import type { HotkeyObj } from "../types.js";
 import "./hotkeyInput.css";
@@ -40,7 +40,7 @@ export function createHotkeyInput({ initialValue, onChange }: HotkeyInputProps):
   const deactivate = () => {
     if(!otherHotkeyInputActive)
       return;
-    siteEvents.emit("hotkeyInputActive", false);
+    emitSiteEvent("hotkeyInputActive", false);
     otherHotkeyInputActive = false;
     const curHk = currentHotkey ?? initialValue;
     inputElem.value = curHk?.code ?? t("hotkey_input_click_to_change");
@@ -52,7 +52,7 @@ export function createHotkeyInput({ initialValue, onChange }: HotkeyInputProps):
   const activate = () => {
     if(otherHotkeyInputActive)
       return;
-    siteEvents.emit("hotkeyInputActive", true);
+    emitSiteEvent("hotkeyInputActive", true);
     otherHotkeyInputActive = true;
     inputElem.value = "< ... >";
     inputElem.dataset.state = "active";

+ 4 - 4
src/dialogs/autoLike.ts

@@ -2,7 +2,7 @@ import { compress, debounce } from "@sv443-network/userutils";
 import { compressionSupported, error, getDomain, log, onInteraction, parseChannelIdFromUrl, t, tryToDecompressAndParse } from "../utils/index.js";
 import { BytmDialog, createCircularBtn, createToggleInput, showToast } from "../components/index.js";
 import { autoLikeStore, initAutoLikeStore } from "../features/index.js";
-import { siteEvents } from "../siteEvents.js";
+import { emitSiteEvent, siteEvents } from "../siteEvents.js";
 import { ExImDialog } from "../components/ExImDialog.js";
 import { compressionFormat } from "../constants.js";
 import type { AutoLikeData } from "../types.js";
@@ -64,7 +64,7 @@ export async function getAutoLikeDialog() {
             return alert(t("import_error_no_data"));
 
           await autoLikeStore.setData(parsed);
-          siteEvents.emit("autoLikeChannelsUpdated");
+          emitSiteEvent("autoLikeChannelsUpdated");
 
           showToast({ message: t("import_success") });
           autoLikeImExDialog?.unmount();
@@ -219,7 +219,7 @@ async function renderBody() {
             .map((ch) => ch.id === chanId ? { ...ch, name: newName, id: newId } : ch),
         });
 
-        siteEvents.emit("autoLikeChannelsUpdated");
+        emitSiteEvent("autoLikeChannelsUpdated");
       },
     });
     btnCont.appendChild(editBtn);
@@ -316,7 +316,7 @@ async function addAutoLikeEntryPrompts() {
       }
   );
 
-  siteEvents.emit("autoLikeChannelsUpdated");
+  emitSiteEvent("autoLikeChannelsUpdated");
 
   const unsub = autoLikeDialog?.on("clear", async () => {
     unsub?.();

+ 2 - 2
src/dialogs/versionNotif.ts

@@ -3,7 +3,7 @@ import { getChangelogMd, getResourceUrl, onInteraction, parseMarkdown, t } from
 import { BytmDialog, createToggleInput } from "../components/index.js";
 import { getFeature, getFeatures, setFeatures } from "../config.js";
 import pkg from "../../package.json" with { type: "json" };
-import { siteEvents } from "../siteEvents.js";
+import { emitSiteEvent } from "../siteEvents.js";
 
 let verNotifDialog: BytmDialog | null = null;
 
@@ -145,7 +145,7 @@ async function renderBody({
     else if(!config.versionCheck && !disableUpdateCheck)
       config.versionCheck = true;
     await setFeatures(config);
-    recreateCfgMenu && siteEvents.emit("recreateCfgMenu");
+    recreateCfgMenu && emitSiteEvent("recreateCfgMenu");
   });
 
   const btnWrapper = document.createElement("div");

+ 2 - 2
src/features/input.ts

@@ -2,7 +2,7 @@ import { DataStore, clamp, compress, decompress } from "@sv443-network/userutils
 import { error, getVideoTime, info, log, warn, getVideoSelector, getDomain, compressionSupported, t, clearNode, resourceAsString, getCurrentChannelId, currentMediaType } from "../utils/index.js";
 import type { AutoLikeData, Domain } from "../types.js";
 import { disableBeforeUnload } from "./behavior.js";
-import { siteEvents } from "../siteEvents.js";
+import { emitSiteEvent, siteEvents } from "../siteEvents.js";
 import { featInfo } from "./index.js";
 import { getFeature } from "../config.js";
 import { compressionFormat } from "../constants.js";
@@ -373,7 +373,7 @@ async function addAutoLikeToggleBtn(siblingEl: HTMLElement, channelId: string, c
           });
         }
 
-        siteEvents.emit("autoLikeChannelsUpdated");
+        emitSiteEvent("autoLikeChannelsUpdated");
         showIconToast({
           message: toggled ? t("auto_like_enabled_toast") : t("auto_like_disabled_toast"),
           icon: `icon-auto_like${toggled ? "_enabled" : ""}`,

+ 1 - 1
src/menu/menu_old.ts

@@ -323,7 +323,7 @@ async function mountCfgMenu() {
     else if(getLocale() !== featConf.locale)
       setLocale(featConf.locale);
 
-    siteEvents.emit("configOptionChanged", key, initialVal, newVal);
+    emitSiteEvent("configOptionChanged", key, initialVal, newVal);
   };
 
   /** Call whenever the feature config is changed */

+ 2 - 2
src/siteEvents.ts

@@ -211,8 +211,8 @@ export function emitSiteEvent<TKey extends keyof SiteEventsMap>(key: TKey, ...ar
 //#region other
 
 /** Checks if the watch ID has changed and emits a `watchIdChanged` siteEvent if it has */
-function checkWatchIdChange(watchId?: string | null) {
-  const newWatchId = watchId ?? new URL(location.href).searchParams.get("v");
+function checkWatchIdChange(newId?: string | null) {
+  const newWatchId = newId ?? new URL(location.href).searchParams.get("v");
   if(newWatchId && newWatchId !== lastWatchId) {
     info(`Detected watch ID change - old ID: "${lastWatchId}" - new ID: "${newWatchId}"`);
     emitSiteEvent("watchIdChanged", newWatchId, lastWatchId);