瀏覽代碼

feat: getDefaultFeatures() interface function

Sv443 2 月之前
父節點
當前提交
233869e1a2
共有 3 個文件被更改,包括 5 次插入1 次删除
  1. 1 0
      changelog.md
  2. 2 1
      src/interface.ts
  3. 2 0
      src/types.ts

+ 1 - 0
changelog.md

@@ -17,6 +17,7 @@
       - `reloadTab()` as a better way to reload the page by keeping the same video time and volume and disabling BYTM features like initial tab volume
       - `getVideoElement()` to get the video element (if available) on the current page, on both YT and YTM
       - `getVideoSelector()` to get the CSS selector for the video element on the current page, on both YT and YTM
+      - `getDefaultFeatures()` to return the default / fallback feature configuration object
     - Constants:
       - `initialParams` ([URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)), the search params at the initial point of loading BYTM
       - `sessionStorageAvailable` (boolean), whether the browser supports [sessionStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)

+ 2 - 1
src/interface.ts

@@ -3,7 +3,7 @@ import * as compareVersions from "compare-versions";
 import { mode, branch, host, buildNumber, compressionFormat, scriptInfo, initialParams, sessionStorageAvailable } from "./constants.js";
 import { getDomain, waitVideoElementReady, getResourceUrl, getSessionId, getVideoTime, log, setLocale, getLocale, hasKey, hasKeyFor, t, tp, type TrLocale, info, error, onInteraction, getThumbnailUrl, getBestThumbnailUrl, fetchVideoVotes, setInnerHtml, getCurrentMediaType, tl, tlp, PluginError, formatNumber, reloadTab, getVideoElement, getVideoSelector } from "./utils/index.js";
 import { addSelectorListener } from "./observers.js";
-import { getFeatures, setFeatures } from "./config.js";
+import { defaultData, getFeatures, setFeatures } from "./config.js";
 import { autoLikeStore, featInfo, fetchLyricsUrlTop, getLyricsCacheEntry, sanitizeArtists, sanitizeSong } from "./features/index.js";
 import { allSiteEvents, type SiteEventsMap } from "./siteEvents.js";
 import { type FeatureConfig, type FeatureInfo, type LyricsCacheEntry, type PluginDef, type PluginInfo, type PluginRegisterResult, type PluginDefResolvable, type PluginEventMap, type PluginItem, type BytmObject, type AutoLikeData, type InterfaceFunctions } from "./types.js";
@@ -136,6 +136,7 @@ const globalFuncs: InterfaceFunctions = {
   // feature config:
   /*🔒*/ getFeatures: getFeaturesInterface,
   /*🔒*/ saveFeatures: saveFeaturesInterface,
+  getDefaultFeatures: () => JSON.parse(JSON.stringify(defaultData)),
 
   // lyrics:
   fetchLyricsUrlTop,

+ 2 - 0
src/types.ts

@@ -336,6 +336,8 @@ export type InterfaceFunctions = {
   getFeatures: typeof getFeaturesInterface;
   /** 🔒 Overwrites the feature configuration with the provided one */
   saveFeatures: typeof saveFeaturesInterface;
+  /** Returns the default feature configuration */
+  getDefaultFeatures: () => FeatureConfig;
 
   // lyrics:
   /** Sanitizes the provided artist string - this needs to be done before calling other lyrics related functions! */