index.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. import { formatNumber, getLocale, getPreferredLocale, getResourceUrl, reloadTab, resourceAsString, t, tp } from "../utils/index.js";
  2. import { clearLyricsCache, getLyricsCache } from "./lyricsCache.js";
  3. import { doVersionCheck } from "./versionCheck.js";
  4. import { getFeature, promptResetConfig } from "../config.js";
  5. import { FeatureInfo, type ColorLightnessPref, type ResourceKey, type SiteSelection, type SiteSelectionOrNone } from "../types.js";
  6. import { emitSiteEvent } from "../siteEvents.js";
  7. import langMapping from "../../assets/locales.json" with { type: "json" };
  8. import { getAutoLikeDialog, getPluginListDialog, showPrompt } from "../dialogs/index.js";
  9. import { showIconToast } from "../components/index.js";
  10. import { mode } from "../constants.js";
  11. import { getStoreSerializer } from "../serializer.js";
  12. //#region re-exports
  13. export * from "./layout.js";
  14. export * from "./behavior.js";
  15. export * from "./input.js";
  16. export * from "./integrations.js";
  17. export * from "./lyrics.js";
  18. export * from "./lyricsCache.js";
  19. export * from "./songLists.js";
  20. export * from "./versionCheck.js";
  21. export * from "./volume.js";
  22. //#region misc
  23. function noop() {
  24. void 0;
  25. }
  26. void [noop];
  27. //#region adornments
  28. type AdornmentFunc =
  29. | ((...args: any[]) => Promise<string | undefined>)
  30. | Promise<string | undefined>;
  31. /** Creates an HTML string for the given adornment properties */
  32. const getAdornHtml = async (className: string, title: string | undefined, resource: ResourceKey, extraAttributes?: string) =>
  33. `<span class="${className} bytm-adorn-icon" ${title ? `title="${title}" aria-label="${title}"` : ""}${extraAttributes ? ` ${extraAttributes}` : ""}>${await resourceAsString(resource) ?? ""}</span>`;
  34. /** Combines multiple async functions or promises that resolve with an adornment HTML string into a single string */
  35. const combineAdornments = (
  36. adornments: Array<AdornmentFunc>
  37. ) => new Promise<string>(
  38. async (resolve) => {
  39. const sortedAdornments = adornments.sort((a, b) => {
  40. const aIndex = adornmentOrder.get(a) ? adornmentOrder.get(a)! : -1;
  41. const bIndex = adornmentOrder.has(b) ? adornmentOrder.get(b)! : -1;
  42. return aIndex - bIndex;
  43. });
  44. const html = [] as string[];
  45. for(const adornment of sortedAdornments) {
  46. const val = typeof adornment === "function"
  47. ? await adornment()
  48. : await adornment;
  49. val && html.push(val);
  50. }
  51. resolve(html.join(""));
  52. }
  53. );
  54. /** Decoration elements that can be added next to the label */
  55. const adornments = {
  56. advanced: async () => getAdornHtml("bytm-advanced-mode-icon", t("advanced_mode"), "icon-advanced_mode"),
  57. experimental: async () => getAdornHtml("bytm-experimental-icon", t("experimental_feature"), "icon-experimental"),
  58. globe: async () => getAdornHtml("bytm-locale-icon", undefined, "icon-globe_small"),
  59. alert: async (title: string) => getAdornHtml("bytm-warning-icon", title, "icon-error", "role=\"alert\""),
  60. reload: async () => getFeature("advancedMode") ? getAdornHtml("bytm-reload-icon", t("feature_requires_reload"), "icon-reload") : undefined,
  61. } satisfies Record<string, AdornmentFunc>;
  62. /** Order of adornment elements in the {@linkcode combineAdornments()} function */
  63. const adornmentOrder = new Map<AdornmentFunc, number>();
  64. adornmentOrder.set(adornments.alert, 0);
  65. adornmentOrder.set(adornments.experimental, 1);
  66. adornmentOrder.set(adornments.globe, 2);
  67. adornmentOrder.set(adornments.reload, 3);
  68. adornmentOrder.set(adornments.advanced, 4);
  69. //#region select options
  70. interface SelectOption<TValue = number | string> {
  71. value: TValue;
  72. label: string;
  73. }
  74. /** Common options for config items of type "select" */
  75. const options = {
  76. siteSelection: (): SelectOption<SiteSelection>[] => [
  77. { value: "all", label: t("site_selection_both_sites") },
  78. { value: "yt", label: t("site_selection_only_yt") },
  79. { value: "ytm", label: t("site_selection_only_ytm") },
  80. ],
  81. siteSelectionOrNone: (): SelectOption<SiteSelectionOrNone>[] => [
  82. { value: "all", label: t("site_selection_both_sites") },
  83. { value: "yt", label: t("site_selection_only_yt") },
  84. { value: "ytm", label: t("site_selection_only_ytm") },
  85. { value: "none", label: t("site_selection_none") },
  86. ],
  87. locale: () => Object.entries(langMapping)
  88. .reduce((a, [locale, { name }]) => {
  89. return [...a, {
  90. value: locale,
  91. label: name,
  92. }];
  93. }, [] as SelectOption[])
  94. .sort((a, b) => a.label.localeCompare(b.label)),
  95. colorLightness: (): SelectOption<ColorLightnessPref>[] => [
  96. { value: "darker", label: t("color_lightness_darker") },
  97. { value: "normal", label: t("color_lightness_normal") },
  98. { value: "lighter", label: t("color_lightness_lighter") },
  99. ],
  100. };
  101. //#region rendering
  102. /** Renders a long number with a thousands separator */
  103. function renderLongNumberValue(val: string, maximumFractionDigits = 0) {
  104. return Number(val).toLocaleString(
  105. getLocale().replace(/_/g, "-"),
  106. {
  107. style: "decimal",
  108. maximumFractionDigits,
  109. }
  110. );
  111. }
  112. //#region features
  113. /**
  114. * Contains all possible features with their default values and other configuration.
  115. *
  116. * **Required props:**
  117. * <!------------------------------------------------------------------------------------------------------------------------------------------------------------------>
  118. * | Property | Description |
  119. * | :----------------------------- | :------------------------------------------------------------------------------------------------------------------------------- |
  120. * | `type: string` | Type of the feature configuration element - use autocomplete or check `FeatureTypeProps` in `src/types.ts` |
  121. * | `category: string` | Category of the feature - use autocomplete or check `FeatureCategory` in `src/types.ts` |
  122. * | `default: unknown` | Default value of the feature - type of the value depends on the given `type` |
  123. * | `enable(value: unknown): void` | (required if reloadRequired = false) - function that will be called when the feature is enabled / initialized for the first time |
  124. * <!------------------------------------------------------------------------------------------------------------------------------------------------------------------>
  125. *
  126. *
  127. * **Optional props:**
  128. * <!------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->
  129. * | Property | Description |
  130. * | :----------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------|
  131. * | `disable(newValue: unknown): void` | For type `toggle` only - function that will be called when the feature is disabled - can be a synchronous or asynchronous function |
  132. * | `change(key: string, prevValue: unknown, newValue: unknown): void` | For types `number`, `select`, `slider` and `hotkey` only - function that will be called when the value is changed |
  133. * | `click(): void` | For type `button` only - function that will be called when the button is clicked |
  134. * | `helpText: string \| () => string` | Function that returns an HTML string or the literal string itself that will be the help text for this feature - writing as function is useful for pluralizing or inserting values into the translation at runtime - if not set, translation with key `feature_helptext_featureKey` will be used instead, if available |
  135. * | `textAdornment(): string \| Promise<string>` | Function that returns an HTML string that will be appended to the text in the config menu as an adornment element |
  136. * | `unit: string \| (val: number) => string` | For types `number` or `slider` only - The unit text that is displayed next to the input element, i.e. " px" - a leading space need to be added too! |
  137. * | `min: number` | For types `number` or `slider` only - Overwrites the default of the `min` property of the HTML input element |
  138. * | `max: number` | For types `number` or `slider` only - Overwrites the default of the `max` property of the HTML input element |
  139. * | `step: number` | For types `number` or `slider` only - Overwrites the default of the `step` property of the HTML input element |
  140. * | `options: SelectOption[] \| () => SelectOption[]` | For type `select` only - function that returns an array of objects with `value` and `label` properties |
  141. * | `reloadRequired: boolean` | If true (default), the page needs to be reloaded for the changes to take effect - if false, `enable()` needs to be provided |
  142. * | `advanced: boolean` | If true, the feature will only be shown if the advanced mode feature has been turned on |
  143. * | `hidden: boolean` | If true, the feature will not be shown in the settings - default is undefined (false) |
  144. * | `valueHidden: boolean` | If true, the value of the feature will be hidden in the settings and via the plugin interface - default is undefined (false) |
  145. * | `normalize(val: unknown): unknown` | Function that will be called to normalize the value before it is saved - useful for trimming strings or other simple operations |
  146. * | `renderValue(val: string): string` | If provided, is used to render the value's label in the config menu |
  147. * <!------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->
  148. *
  149. * TODO: go through all features and set as many as possible to reloadRequired = false
  150. */
  151. export const featInfo = {
  152. //#region cat:layout
  153. watermarkEnabled: {
  154. type: "toggle",
  155. category: "layout",
  156. default: true,
  157. textAdornment: adornments.reload,
  158. },
  159. removeShareTrackingParam: {
  160. type: "toggle",
  161. category: "layout",
  162. default: true,
  163. textAdornment: adornments.reload,
  164. },
  165. removeShareTrackingParamSites: {
  166. type: "select",
  167. category: "layout",
  168. options: options.siteSelection,
  169. default: "all",
  170. advanced: true,
  171. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  172. },
  173. fixSpacing: {
  174. type: "toggle",
  175. category: "layout",
  176. default: true,
  177. advanced: true,
  178. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  179. },
  180. thumbnailOverlayBehavior: {
  181. type: "select",
  182. category: "layout",
  183. options: () => [
  184. { value: "songsOnly", label: t("thumbnail_overlay_behavior_songs_only") },
  185. { value: "videosOnly", label: t("thumbnail_overlay_behavior_videos_only") },
  186. { value: "always", label: t("thumbnail_overlay_behavior_always") },
  187. { value: "never", label: t("thumbnail_overlay_behavior_never") },
  188. ],
  189. default: "songsOnly",
  190. reloadRequired: false,
  191. enable: noop,
  192. },
  193. thumbnailOverlayToggleBtnShown: {
  194. type: "toggle",
  195. category: "layout",
  196. default: true,
  197. textAdornment: adornments.reload,
  198. },
  199. thumbnailOverlayShowIndicator: {
  200. type: "toggle",
  201. category: "layout",
  202. default: true,
  203. textAdornment: adornments.reload,
  204. },
  205. thumbnailOverlayIndicatorOpacity: {
  206. type: "slider",
  207. category: "layout",
  208. min: 5,
  209. max: 100,
  210. step: 5,
  211. default: 40,
  212. unit: "%",
  213. advanced: true,
  214. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  215. },
  216. thumbnailOverlayImageFit: {
  217. type: "select",
  218. category: "layout",
  219. options: () => [
  220. { value: "cover", label: t("thumbnail_overlay_image_fit_crop") },
  221. { value: "contain", label: t("thumbnail_overlay_image_fit_full") },
  222. { value: "fill", label: t("thumbnail_overlay_image_fit_stretch") },
  223. ],
  224. default: "cover",
  225. advanced: true,
  226. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  227. },
  228. hideCursorOnIdle: {
  229. type: "toggle",
  230. category: "layout",
  231. default: true,
  232. reloadRequired: false,
  233. enable: noop,
  234. },
  235. hideCursorOnIdleDelay: {
  236. type: "slider",
  237. category: "layout",
  238. min: 0.5,
  239. max: 10,
  240. step: 0.25,
  241. default: 2,
  242. unit: "s",
  243. advanced: true,
  244. textAdornment: adornments.advanced,
  245. reloadRequired: false,
  246. enable: noop,
  247. },
  248. fixHdrIssues: {
  249. type: "toggle",
  250. category: "layout",
  251. default: true,
  252. advanced: true,
  253. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  254. },
  255. showVotes: {
  256. type: "toggle",
  257. category: "layout",
  258. default: true,
  259. textAdornment: adornments.reload,
  260. },
  261. // archived idea for future version
  262. // (shows a bar under the like/dislike buttons that shows the ratio of likes to dislikes)
  263. // showVoteRatio: {
  264. // type: "select",
  265. // category: "layout",
  266. // options: () => [
  267. // { value: "disabled", label: t("vote_ratio_disabled") },
  268. // { value: "greenRed", label: t("vote_ratio_green_red") },
  269. // { value: "blueGray", label: t("vote_ratio_blue_gray") },
  270. // ],
  271. // default: "disabled",
  272. // textAdornment: adornments.reload,
  273. // },
  274. //#region cat:volume
  275. volumeSliderLabel: {
  276. type: "toggle",
  277. category: "volume",
  278. default: true,
  279. textAdornment: adornments.reload,
  280. },
  281. volumeSliderSize: {
  282. type: "number",
  283. category: "volume",
  284. min: 50,
  285. max: 500,
  286. step: 5,
  287. default: 150,
  288. unit: "px",
  289. textAdornment: adornments.reload,
  290. },
  291. volumeSliderStep: {
  292. type: "slider",
  293. category: "volume",
  294. min: 1,
  295. max: 25,
  296. default: 2,
  297. unit: "%",
  298. textAdornment: adornments.reload,
  299. },
  300. volumeSliderScrollStep: {
  301. type: "slider",
  302. category: "volume",
  303. min: 1,
  304. max: 25,
  305. default: 4,
  306. unit: "%",
  307. textAdornment: adornments.reload,
  308. },
  309. volumeSharedBetweenTabs: {
  310. type: "toggle",
  311. category: "volume",
  312. default: false,
  313. textAdornment: adornments.reload,
  314. },
  315. setInitialTabVolume: {
  316. type: "toggle",
  317. category: "volume",
  318. default: false,
  319. textAdornment: () => getFeature("volumeSharedBetweenTabs")
  320. ? combineAdornments([adornments.alert(t("feature_warning_setInitialTabVolume_volumeSharedBetweenTabs_incompatible").replace(/"/g, "'")), adornments.reload])
  321. : adornments.reload(),
  322. },
  323. initialTabVolumeLevel: {
  324. type: "slider",
  325. category: "volume",
  326. min: 0,
  327. max: 100,
  328. step: 1,
  329. default: 100,
  330. unit: "%",
  331. textAdornment: () => getFeature("volumeSharedBetweenTabs")
  332. ? combineAdornments([adornments.alert(t("feature_warning_setInitialTabVolume_volumeSharedBetweenTabs_incompatible").replace(/"/g, "'")), adornments.reload])
  333. : adornments.reload(),
  334. reloadRequired: false,
  335. enable: noop,
  336. },
  337. //#region cat:song lists
  338. lyricsQueueButton: {
  339. type: "toggle",
  340. category: "songLists",
  341. default: true,
  342. textAdornment: adornments.reload,
  343. },
  344. deleteFromQueueButton: {
  345. type: "toggle",
  346. category: "songLists",
  347. default: true,
  348. textAdornment: adornments.reload,
  349. },
  350. listButtonsPlacement: {
  351. type: "select",
  352. category: "songLists",
  353. options: () => [
  354. { value: "queueOnly", label: t("list_button_placement_queue_only") },
  355. { value: "everywhere", label: t("list_button_placement_everywhere") },
  356. ],
  357. default: "everywhere",
  358. advanced: true,
  359. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  360. },
  361. scrollToActiveSongBtn: {
  362. type: "toggle",
  363. category: "songLists",
  364. default: true,
  365. textAdornment: adornments.reload,
  366. },
  367. clearQueueBtn: {
  368. type: "toggle",
  369. category: "songLists",
  370. default: true,
  371. textAdornment: adornments.reload,
  372. },
  373. aboveQueueBtnsSticky: {
  374. type: "toggle",
  375. category: "songLists",
  376. default: true,
  377. advanced: true,
  378. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  379. },
  380. //#region cat:behavior
  381. disableBeforeUnloadPopup: {
  382. type: "toggle",
  383. category: "behavior",
  384. default: false,
  385. textAdornment: adornments.reload,
  386. },
  387. closeToastsTimeout: {
  388. type: "number",
  389. category: "behavior",
  390. min: 0,
  391. max: 30,
  392. step: 0.5,
  393. default: 3,
  394. unit: "s",
  395. reloadRequired: false,
  396. enable: noop,
  397. },
  398. rememberSongTime: {
  399. type: "toggle",
  400. category: "behavior",
  401. default: true,
  402. helpText: () => tp("feature_helptext_rememberSongTime", getFeature("rememberSongTimeMinPlayTime"), getFeature("rememberSongTimeMinPlayTime")),
  403. textAdornment: adornments.reload,
  404. },
  405. rememberSongTimeSites: {
  406. type: "select",
  407. category: "behavior",
  408. options: options.siteSelection,
  409. default: "all",
  410. textAdornment: adornments.reload,
  411. },
  412. rememberSongTimeDuration: {
  413. type: "number",
  414. category: "behavior",
  415. min: 1,
  416. max: 60 * 60 * 24 * 7,
  417. step: 1,
  418. default: 60,
  419. unit: "s",
  420. advanced: true,
  421. textAdornment: adornments.advanced,
  422. reloadRequired: false,
  423. enable: noop,
  424. },
  425. rememberSongTimeReduction: {
  426. type: "number",
  427. category: "behavior",
  428. min: 0,
  429. max: 30,
  430. step: 0.05,
  431. default: 0.2,
  432. unit: "s",
  433. advanced: true,
  434. textAdornment: adornments.advanced,
  435. reloadRequired: false,
  436. enable: noop,
  437. },
  438. rememberSongTimeMinPlayTime: {
  439. type: "slider",
  440. category: "behavior",
  441. min: 3,
  442. max: 30,
  443. step: 0.5,
  444. default: 10,
  445. unit: "s",
  446. advanced: true,
  447. textAdornment: adornments.advanced,
  448. reloadRequired: false,
  449. enable: noop,
  450. },
  451. //#region cat:input
  452. arrowKeySupport: {
  453. type: "toggle",
  454. category: "input",
  455. default: true,
  456. reloadRequired: false,
  457. enable: noop,
  458. },
  459. arrowKeySkipBy: {
  460. type: "slider",
  461. category: "input",
  462. min: 0.5,
  463. max: 30,
  464. step: 0.5,
  465. default: 5,
  466. unit: "s",
  467. reloadRequired: false,
  468. enable: noop,
  469. },
  470. switchBetweenSites: {
  471. type: "toggle",
  472. category: "input",
  473. default: true,
  474. reloadRequired: false,
  475. enable: noop,
  476. },
  477. switchSitesHotkey: {
  478. type: "hotkey",
  479. category: "input",
  480. default: {
  481. code: "F9",
  482. shift: false,
  483. ctrl: false,
  484. alt: false,
  485. },
  486. reloadRequired: false,
  487. enable: noop,
  488. },
  489. anchorImprovements: {
  490. type: "toggle",
  491. category: "input",
  492. default: true,
  493. textAdornment: adornments.reload,
  494. },
  495. numKeysSkipToTime: {
  496. type: "toggle",
  497. category: "input",
  498. default: true,
  499. reloadRequired: false,
  500. enable: noop,
  501. },
  502. autoLikeChannels: {
  503. type: "toggle",
  504. category: "input",
  505. default: true,
  506. textAdornment: adornments.reload,
  507. },
  508. autoLikeChannelToggleBtn: {
  509. type: "toggle",
  510. category: "input",
  511. default: true,
  512. reloadRequired: false,
  513. enable: noop,
  514. advanced: true,
  515. textAdornment: adornments.advanced,
  516. },
  517. // TODO(v2.2):
  518. // autoLikePlayerBarToggleBtn: {
  519. // type: "toggle",
  520. // category: "input",
  521. // default: false,
  522. // textAdornment: adornments.reload,
  523. // },
  524. autoLikeTimeout: {
  525. type: "slider",
  526. category: "input",
  527. min: 3,
  528. max: 30,
  529. step: 0.5,
  530. default: 5,
  531. unit: "s",
  532. advanced: true,
  533. reloadRequired: false,
  534. enable: noop,
  535. textAdornment: adornments.advanced,
  536. },
  537. autoLikeShowToast: {
  538. type: "toggle",
  539. category: "input",
  540. default: true,
  541. reloadRequired: false,
  542. advanced: true,
  543. enable: noop,
  544. textAdornment: adornments.advanced,
  545. },
  546. autoLikeOpenMgmtDialog: {
  547. type: "button",
  548. category: "input",
  549. click: () => getAutoLikeDialog().then(d => d.open()),
  550. },
  551. //#region cat:lyrics
  552. geniusLyrics: {
  553. type: "toggle",
  554. category: "lyrics",
  555. default: true,
  556. textAdornment: adornments.reload,
  557. },
  558. errorOnLyricsNotFound: {
  559. type: "toggle",
  560. category: "lyrics",
  561. default: false,
  562. reloadRequired: false,
  563. enable: noop,
  564. },
  565. geniUrlBase: {
  566. type: "text",
  567. category: "lyrics",
  568. default: "https://api.sv443.net/geniurl",
  569. normalize: (val: string) => val.trim().replace(/\/+$/, ""),
  570. advanced: true,
  571. textAdornment: adornments.advanced,
  572. reloadRequired: false,
  573. enable: noop,
  574. },
  575. geniUrlToken: {
  576. type: "text",
  577. valueHidden: true,
  578. category: "lyrics",
  579. default: "",
  580. normalize: (val: string) => val.trim(),
  581. advanced: true,
  582. textAdornment: adornments.advanced,
  583. reloadRequired: false,
  584. enable: noop,
  585. },
  586. lyricsCacheMaxSize: {
  587. type: "slider",
  588. category: "lyrics",
  589. default: 2000,
  590. min: 100,
  591. max: 10000,
  592. step: 100,
  593. unit: (val: number) => ` ${tp("unit_entries", val)}`,
  594. renderValue: renderLongNumberValue,
  595. advanced: true,
  596. textAdornment: adornments.advanced,
  597. reloadRequired: false,
  598. enable: noop,
  599. },
  600. lyricsCacheTTL: {
  601. type: "slider",
  602. category: "lyrics",
  603. default: 21,
  604. min: 1,
  605. max: 100,
  606. step: 1,
  607. unit: (val: number) => " " + tp("unit_days", val),
  608. advanced: true,
  609. textAdornment: adornments.advanced,
  610. reloadRequired: false,
  611. enable: noop,
  612. },
  613. clearLyricsCache: {
  614. type: "button",
  615. category: "lyrics",
  616. async click() {
  617. const entries = getLyricsCache().length;
  618. const formattedEntries = entries.toLocaleString(getLocale(), { style: "decimal", maximumFractionDigits: 0 });
  619. if(await showPrompt({ type: "confirm", message: tp("lyrics_clear_cache_confirm_prompt", entries, formattedEntries) })) {
  620. await clearLyricsCache();
  621. await showPrompt({ type: "alert", message: t("lyrics_clear_cache_success") });
  622. }
  623. },
  624. advanced: true,
  625. textAdornment: adornments.advanced,
  626. },
  627. // advancedLyricsFilter: {
  628. // type: "toggle",
  629. // category: "lyrics",
  630. // default: false,
  631. // change: () => setTimeout(async () => await showPrompt({ type: "confirm", message: t("lyrics_cache_changed_clear_confirm") }) && clearLyricsCache(), 200),
  632. // advanced: true,
  633. // textAdornment: adornments.experimental,
  634. // reloadRequired: false,
  635. // enable: noop,
  636. // },
  637. //#region cat:integrations
  638. disableDarkReaderSites: {
  639. type: "select",
  640. category: "integrations",
  641. options: options.siteSelectionOrNone,
  642. default: "all",
  643. advanced: true,
  644. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  645. },
  646. sponsorBlockIntegration: {
  647. type: "toggle",
  648. category: "integrations",
  649. default: true,
  650. advanced: true,
  651. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  652. },
  653. themeSongIntegration: {
  654. type: "toggle",
  655. category: "integrations",
  656. default: false,
  657. textAdornment: adornments.reload,
  658. },
  659. themeSongLightness: {
  660. type: "select",
  661. category: "integrations",
  662. options: options.colorLightness,
  663. default: "darker",
  664. textAdornment: adornments.reload,
  665. },
  666. //#region cat:plugins
  667. openPluginList: {
  668. type: "button",
  669. category: "plugins",
  670. default: undefined,
  671. click: () => getPluginListDialog().then(d => d.open()),
  672. },
  673. initTimeout: {
  674. type: "number",
  675. category: "plugins",
  676. min: 3,
  677. max: 30,
  678. default: 8,
  679. step: 0.1,
  680. unit: "s",
  681. advanced: true,
  682. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  683. },
  684. //#region cat:general
  685. locale: {
  686. type: "select",
  687. category: "general",
  688. options: options.locale,
  689. default: getPreferredLocale(),
  690. textAdornment: () => combineAdornments([adornments.globe, adornments.reload]),
  691. },
  692. localeFallback: {
  693. type: "toggle",
  694. category: "general",
  695. default: true,
  696. advanced: true,
  697. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  698. },
  699. versionCheck: {
  700. type: "toggle",
  701. category: "general",
  702. default: true,
  703. textAdornment: adornments.reload,
  704. },
  705. checkVersionNow: {
  706. type: "button",
  707. category: "general",
  708. click: () => doVersionCheck(true),
  709. },
  710. numbersFormat: {
  711. type: "select",
  712. category: "general",
  713. options: () => [
  714. { value: "long", label: `${formatNumber(12_345_678, "long")} (${t("votes_format_long")})` },
  715. { value: "short", label: `${formatNumber(12_345_678, "short")} (${t("votes_format_short")})` },
  716. ],
  717. default: "short",
  718. reloadRequired: false,
  719. enable: noop,
  720. },
  721. toastDuration: {
  722. type: "slider",
  723. category: "general",
  724. min: 0,
  725. max: 15,
  726. default: 4,
  727. step: 0.5,
  728. unit: "s",
  729. reloadRequired: false,
  730. advanced: true,
  731. textAdornment: adornments.advanced,
  732. enable: noop,
  733. change: () => showIconToast({
  734. message: t("example_toast"),
  735. iconSrc: getResourceUrl(`img-logo${mode === "development" ? "_dev" : ""}`),
  736. }),
  737. },
  738. showToastOnGenericError: {
  739. type: "toggle",
  740. category: "general",
  741. default: true,
  742. advanced: true,
  743. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  744. },
  745. resetConfig: {
  746. type: "button",
  747. category: "general",
  748. click: promptResetConfig,
  749. textAdornment: adornments.reload,
  750. },
  751. resetEverything: {
  752. type: "button",
  753. category: "general",
  754. click: async () => {
  755. if(await showPrompt({
  756. type: "confirm",
  757. message: t("reset_everything_confirm"),
  758. })) {
  759. await getStoreSerializer().resetStoresData();
  760. await reloadTab();
  761. }
  762. },
  763. advanced: true,
  764. textAdornment: () => combineAdornments([adornments.advanced, adornments.reload]),
  765. },
  766. logLevel: {
  767. type: "select",
  768. category: "general",
  769. options: () => [
  770. { value: 0, label: t("log_level_debug") },
  771. { value: 1, label: t("log_level_info") },
  772. ],
  773. default: 1,
  774. textAdornment: adornments.reload,
  775. },
  776. advancedMode: {
  777. type: "toggle",
  778. category: "general",
  779. default: false,
  780. textAdornment: () => getFeature("advancedMode") ? adornments.advanced() : undefined,
  781. change: (_key, prevValue, newValue) =>
  782. prevValue !== newValue &&
  783. emitSiteEvent("recreateCfgMenu"),
  784. },
  785. } as const satisfies FeatureInfo;