Explorar el Código

ref: renamed stuff

Sven hace 9 meses
padre
commit
dc39299a3d
Se han modificado 5 ficheros con 21 adiciones y 17 borrados
  1. 2 1
      .vscode/settings.json
  2. 1 1
      assets/translations/en_US.json
  3. 1 1
      src/features/index.ts
  4. 14 13
      src/features/layout.ts
  5. 3 1
      src/types.ts

+ 2 - 1
.vscode/settings.json

@@ -3,7 +3,8 @@
   "typescript.tsdk": "node_modules/typescript/lib",
 
   "search.exclude": {
-    "**/BetterYTM.user.js": true,
+    "**/*.user.js": true,
+    "**/BetterYTM.css": true,
   },
   "files.associations": {
     "*.env": "dotenv",

+ 1 - 1
assets/translations/en_US.json

@@ -174,7 +174,7 @@
     "vote_ratio_blue_gray": "Blue and gray",
 
     "votes_format_short": "Shortened",
-    "votes_format_full": "Full number",
+    "votes_format_long": "Full number",
 
     "unit_entries-1": "entry",
     "unit_entries-n": "entries",

+ 1 - 1
src/features/index.ts

@@ -237,7 +237,7 @@ export const featInfo = {
     type: "select",
     category: "layout",
     options: () => [
-      { value: "full", label: t("votes_format_full") },
+      { value: "long", label: t("votes_format_full") },
       { value: "short", label: t("votes_format_short") },
     ],
     default: "short",

+ 14 - 13
src/features/layout.ts

@@ -6,7 +6,7 @@ import { error, getResourceUrl, log, warn, t, onInteraction, openInTab, getBestT
 import { mode, scriptInfo } from "../constants.js";
 import { openCfgMenu } from "../menu/menu_old.js";
 import { createCircularBtn, createRipple } from "../components/index.js";
-import type { ResourceKey, VideoVotesObj } from "../types.js";
+import type { NumberNotation, ResourceKey, VideoVotesObj } from "../types.js";
 import "./layout.css";
 
 //#region cfg menu btns
@@ -729,33 +729,34 @@ export async function initShowVotes() {
           await siteEvents.once("watchIdChanged");
           return initShowVotes();
         }
+
         const voteObj = await fetchVideoVotes(watchId);
         if(!voteObj || !("likes" in voteObj) || !("dislikes" in voteObj) || !("rating" in voteObj))
           return error("Couldn't fetch votes from the Return YouTube Dislike API");
-  
+
         if(getFeature("showVotes")) {
           addVoteNumbers(voteCont, voteObj);
-  
+
           siteEvents.on("watchIdChanged", async (watchId) => {
             const labelLikes = document.querySelector<HTMLElement>("ytmusic-like-button-renderer .bytm-vote-label.likes");
             const labelDislikes = document.querySelector<HTMLElement>("ytmusic-like-button-renderer .bytm-vote-label.dislikes");
-        
+
             if(!labelLikes || !labelDislikes)
               return error("Couldn't find vote label elements while updating like and dislike counts");
-        
+
             if(labelLikes.dataset.watchId === watchId && labelDislikes.dataset.watchId === watchId)
               return log("Vote labels already updated for this video");
-        
+
             const voteObj = await fetchVideoVotes(watchId);
             if(!voteObj || !("likes" in voteObj) || !("dislikes" in voteObj) || !("rating" in voteObj))
               return error("Couldn't fetch votes from the Return YouTube Dislike API");
-        
+
             labelLikes.dataset.watchId = getWatchId() ?? "";
             labelLikes.textContent = formatVoteNumber(voteObj.likes);
-            labelLikes.title = labelLikes.ariaLabel = tp("vote_label_likes", voteObj.likes, formatVoteNumber(voteObj.likes, "full"));
-        
+            labelLikes.title = labelLikes.ariaLabel = tp("vote_label_likes", voteObj.likes, formatVoteNumber(voteObj.likes, "long"));
+
             labelDislikes.textContent = formatVoteNumber(voteObj.dislikes);
-            labelDislikes.title = labelDislikes.ariaLabel = tp("vote_label_dislikes", voteObj.dislikes, formatVoteNumber(voteObj.dislikes, "full"));
+            labelDislikes.title = labelDislikes.ariaLabel = tp("vote_label_dislikes", voteObj.dislikes, formatVoteNumber(voteObj.dislikes, "long"));
             labelDislikes.dataset.watchId = getWatchId() ?? "";
           });
         }
@@ -778,7 +779,7 @@ function addVoteNumbers(voteCont: HTMLElement, voteObj: VideoVotesObj) {
     const label = document.createElement("span");
     label.classList.add("bytm-vote-label", "bytm-no-select", type);
     label.textContent = String(formatVoteNumber(amount));
-    label.title = label.ariaLabel = tp(`vote_label_${type}`, amount, formatVoteNumber(amount, "full"));
+    label.title = label.ariaLabel = tp(`vote_label_${type}`, amount, formatVoteNumber(amount, "long"));
     label.dataset.watchId = getWatchId() ?? "";
     label.addEventListener("click", (e) => {
       e.preventDefault();
@@ -798,10 +799,10 @@ function addVoteNumbers(voteCont: HTMLElement, voteObj: VideoVotesObj) {
 }
 
 /** Formats a number formatted based on the config or the passed {@linkcode notation} */
-function formatVoteNumber(num: number, notation = getFeature("showVotesFormat")) {
+function formatVoteNumber(num: number, notation?: NumberNotation) {
   return num.toLocaleString(
     getLocale().replace(/_/g, "-"),
-    notation === "short"
+    (notation ?? getFeature("showVotesFormat")) === "short"
       ? {
         notation: "compact",
         compactDisplay: "short",

+ 3 - 1
src/types.ts

@@ -96,6 +96,8 @@ export type VideoVotesObj = {
   timestamp: number;
 };
 
+export type NumberNotation = "short" | "long";
+
 //#region global
 
 /** All properties of the `unsafeWindow.BYTM` object (also called "plugin interface") */
@@ -476,7 +478,7 @@ export interface FeatureConfig {
   /** Whether to show the like/dislike ratio on the currently playing song */
   showVotes: boolean;
   /** Which format to use for the like/dislike ratio on the currently playing song */
-  showVotesFormat: "short" | "full";
+  showVotesFormat: NumberNotation;
 
   //#region volume
   /** Add a percentage label to the volume slider */