Explorar el Código

fix: song time remember sites default val

Sv443 hace 11 meses
padre
commit
f90f8a44b2
Se han modificado 4 ficheros con 14 adiciones y 6 borrados
  1. 2 0
      src/config.ts
  2. 8 2
      src/features/behavior.ts
  3. 1 1
      src/features/index.ts
  4. 3 3
      src/utils/NanoEmitter.ts

+ 2 - 0
src/config.ts

@@ -63,6 +63,8 @@ export const migrations: DataMigrationsDict = {
     "autoLikeChannels", "autoLikeChannelToggleBtn",
     "autoLikePlayerBarToggleBtn", "autoLikeTimeout",
     "autoLikeShowToast", "autoLikeOpenMgmtDialog",
+    // reset existing:
+    "rememberSongTimeSites",
   ]),
   // TODO: once advanced filtering is fully implemented, clear cache on migration to fv6
   // 6 -> 7 (v2.x)

+ 8 - 2
src/features/behavior.ts

@@ -135,15 +135,21 @@ async function restoreSongTime() {
   }
 }
 
+let lastSongTime = -1;
+
 /** Only call once as this calls itself after a timeout! - Updates the currently playing song's entry in GM storage */
 async function remSongUpdateEntry() {
   if(location.pathname.startsWith("/watch")) {
+    const songTime = await getVideoTime() ?? 0;
+
+    if(songTime === lastSongTime)
+      return;
+    lastSongTime = songTime;
+
     const watchID = getWatchId();
     if(!watchID)
       return;
 
-    const songTime = await getVideoTime() ?? 0;
-
     const paused = document.querySelector<HTMLVideoElement>(getVideoSelector())?.paused ?? false;
 
     // don't immediately update to reduce race conditions and only update if the video is playing

+ 1 - 1
src/features/index.ts

@@ -353,7 +353,7 @@ export const featInfo = {
     type: "select",
     category: "behavior",
     options: options.siteSelection,
-    default: "ytm",
+    default: "all",
     textAdornment: adornments.reloadRequired,
   },
   rememberSongTimeDuration: {

+ 3 - 3
src/utils/NanoEmitter.ts

@@ -5,8 +5,8 @@ interface NanoEmitterSettings {
   publicEmit: boolean;
 }
 
-/** Abstract class that can be extended to create an event emitter with helper methods and a strongly typed event map */
-export abstract class NanoEmitter<TEvtMap extends EventsMap = DefaultEvents> {
+/** Class that can be extended or instantiated by itself to create an event emitter with helper methods and a strongly typed event map */
+export class NanoEmitter<TEvtMap extends EventsMap = DefaultEvents> {
   protected readonly events = createNanoEvents<TEvtMap>();
   protected eventUnsubscribes: Unsubscribe[] = [];
   protected emitterSettings: NanoEmitterSettings;
@@ -43,7 +43,7 @@ export abstract class NanoEmitter<TEvtMap extends EventsMap = DefaultEvents> {
       let unsub: Unsubscribe | undefined;
 
       const onceProxy = ((...args: Parameters<TEvtMap[TKey]>) => {
-        unsub?.();
+        unsub!();
         cb?.(...args);
         resolve(args);
       }) as TEvtMap[TKey];