Sv443 11 mesiacov pred
rodič
commit
f77d8bca34
2 zmenil súbory, kde vykonal 33 pridanie a 28 odobranie
  1. 32 27
      src/features/input.ts
  2. 1 1
      src/index.ts

+ 32 - 27
src/features/input.ts

@@ -324,39 +324,44 @@ async function addAutoLikeToggleBtn(siblingEl: HTMLElement, channelId: string, c
     toggle: true,
     toggleInitialState: chan?.enabled ?? false,
     async onToggle(toggled, evt) {
-      if(evt.shiftKey) {
-        buttonEl.classList.toggle("toggled");
-        getAutoLikeChannelsDialog().then((dlg) => dlg.open());
-        return;
-      }
-
-      buttonEl.title = buttonEl.ariaLabel = t(`auto_like_button_tooltip${toggled ? "_enabled" : "_disabled"}`);
+      try {
+        if(evt.shiftKey) {
+          buttonEl.classList.toggle("toggled");
+          getAutoLikeChannelsDialog().then((dlg) => dlg.open());
+          return;
+        }
 
-      const chanId = buttonEl.dataset.channelId ?? channelId;
+        buttonEl.title = buttonEl.ariaLabel = t(`auto_like_button_tooltip${toggled ? "_enabled" : "_disabled"}`);
 
-      const imgEl = buttonEl.querySelector<HTMLElement>(".bytm-generic-btn-img");
-      const imgHtml = await resourceToHTMLString(`icon-auto_like${toggled ? "_enabled" : ""}`);
-      if(imgEl && imgHtml)
-        imgEl.innerHTML = imgHtml;
+        const chanId = buttonEl.dataset.channelId ?? channelId;
 
-      showIconToast({
-        message: toggled ? t("auto_like_enabled_toast") : t("auto_like_disabled_toast"),
-        icon: `icon-auto_like${toggled ? "_enabled" : ""}`,
-      });
+        const imgEl = buttonEl.querySelector<HTMLElement>(".bytm-generic-btn-img");
+        const imgHtml = await resourceToHTMLString(`icon-auto_like${toggled ? "_enabled" : ""}`);
+        if(imgEl && imgHtml)
+          imgEl.innerHTML = imgHtml;
 
-      if(autoLikeStore.getData().channels.find((ch) => ch.id === chanId) === undefined) {
-        await autoLikeStore.setData({
-          channels: [
-            ...autoLikeStore.getData().channels,
-            { id: chanId, name: channelName ?? "", enabled: toggled },
-          ],
+        if(autoLikeStore.getData().channels.find((ch) => ch.id === chanId) === undefined) {
+          await autoLikeStore.setData({
+            channels: [
+              ...autoLikeStore.getData().channels,
+              { id: chanId, name: channelName ?? "", enabled: toggled },
+            ],
+          });
+        }
+        else {
+          await autoLikeStore.setData({
+            channels: autoLikeStore.getData().channels
+              .map((ch) => ch.id === chanId ? { ...ch, enabled: toggled } : ch),
+          });
+        }
+        showIconToast({
+          message: toggled ? t("auto_like_enabled_toast") : t("auto_like_disabled_toast"),
+          icon: `icon-auto_like${toggled ? "_enabled" : ""}`,
         });
+        log(`Toggled auto-like for channel '${channelName}' (ID: '${chanId}') to ${toggled ? "enabled" : "disabled"}`);
       }
-      else {
-        await autoLikeStore.setData({
-          channels: autoLikeStore.getData().channels
-            .map((ch) => ch.id === chanId ? { ...ch, enabled: toggled } : ch),
-        });
+      catch(err) {
+        error("Error while toggling auto-like channel:", err);
       }
     }
   });

+ 1 - 1
src/index.ts

@@ -394,7 +394,7 @@ function registerDevMenuCommands() {
         listenersAmt += v.length;
         lines.push(`    [${v.length}] ${k}`);
         v.forEach(({ all, continuous }, i) => {
-          lines.push(`        ${v.length > 1 && i !== v.length - 1 ? "├" : "└"}> ${continuous ? "continuous" : "single-shot"}, ${all ? "select multiple" : "select single"}`);
+          lines.push(`        ${v.length > 1 && i !== v.length - 1 ? "├" : "└"}> ${continuous ? "continuous" : "single-shot"}${all ? ", multiple" : ""}`);
         });
       });
     }