Przeglądaj źródła

ref: change buildId location

Sv443 1 rok temu
rodzic
commit
23b70b2abd
6 zmienionych plików z 20 dodań i 9 usunięć
  1. 3 1
      src/constants.ts
  2. 1 1
      src/features/lyrics.ts
  3. 2 2
      src/index.ts
  4. 4 1
      src/interface.ts
  5. 3 3
      src/menu/menu_old.ts
  6. 7 1
      src/utils/xhr.ts

+ 3 - 1
src/constants.ts

@@ -3,6 +3,7 @@ import { LogLevel } from "./types";
 const modeRaw = "#{{MODE}}";
 const branchRaw = "#{{BRANCH}}";
 const hostRaw = "#{{HOST}}";
+const buildNumberRaw  = "#{{BUILD_NUMBER}}";
 
 /** The mode in which the script was built (production or development) */
 export const mode = (modeRaw.match(/^#{{.+}}$/) ? "production" : modeRaw) as "production" | "development";
@@ -12,6 +13,8 @@ export const branch = (branchRaw.match(/^#{{.+}}$/) ? "main" : branchRaw) as "ma
 export const repo = "Sv443/BetterYTM";
 /** Which host the userscript was installed from */
 export const host = (hostRaw.match(/^#{{.+}}$/) ? "github" : hostRaw) as "github" | "greasyfork" | "openuserjs";
+/** The build number of the userscript */
+export const buildNumber = (buildNumberRaw.match(/^#{{.+}}$/) ? "BUILD_ERROR!" : buildNumberRaw) as string; // asserted as generic string instead of literal
 
 /** Names of platforms by value of {@linkcode host} */
 export const platformNames: Record<typeof host, string> = {
@@ -34,5 +37,4 @@ export const scriptInfo = {
   name: GM.info.script.name,
   version: GM.info.script.version,
   namespace: GM.info.script.namespace,
-  buildNumber: "#{{BUILD_NUMBER}}" as string, // asserted as generic string instead of literal
 };

+ 1 - 1
src/features/lyrics.ts

@@ -329,7 +329,7 @@ export async function fetchLyricsUrls(artist: string, song: string): Promise<Omi
     const fetchUrl = constructUrlString(geniURLSearchUrl, {
       disableFuzzy: null,
       utm_source: scriptInfo.name,
-      utm_content: mode === "development" ? "dev" : `v${scriptInfo.version}`,
+      utm_content: `v${scriptInfo.version}${mode === "development" ? "-dev" : ""}`,
       artist,
       song,
     });

+ 2 - 2
src/index.ts

@@ -1,7 +1,7 @@
 import { addGlobalStyle, decompress, type Stringifiable } from "@sv443-network/userutils";
 import { initOnSelector } from "./utils";
 import { clearConfig, getFeatures, initConfig } from "./config";
-import { compressionFormat, defaultLogLevel, mode, scriptInfo } from "./constants";
+import { buildNumber, compressionFormat, defaultLogLevel, mode, scriptInfo } from "./constants";
 import { error, getDomain, info, getSessionId, log, setLogLevel, initTranslations, setLocale } from "./utils";
 import { initSiteEvents, siteEvents } from "./siteEvents";
 import { emitInterface, initInterface } from "./interface";
@@ -46,7 +46,7 @@ import {
 
   console.log();
   console.log(
-    `%c${scriptInfo.name}%cv${scriptInfo.version}%c\n\nBuild ${scriptInfo.buildNumber} ─ ${scriptInfo.namespace}`,
+    `%c${scriptInfo.name}%cv${scriptInfo.version}%c\n\nBuild ${buildNumber} ─ ${scriptInfo.namespace}`,
     `font-weight: bold; ${styleCommon} ${styleGradient}`,
     `background-color: #333; ${styleCommon}`,
     "padding: initial;",

+ 4 - 1
src/interface.ts

@@ -1,5 +1,5 @@
 import * as UserUtils from "@sv443-network/userutils";
-import { mode, branch, scriptInfo } from "./constants";
+import { mode, branch, host, buildNumber, compressionFormat, scriptInfo } from "./constants";
 import { getResourceUrl, getSessionId, getVideoTime, log, setLocale, getLocale, hasKey, hasKeyFor, t, tp, type TrLocale } from "./utils";
 import { addSelectorListener } from "./observers";
 import { getFeatures, saveFeatures } from "./config";
@@ -50,6 +50,9 @@ export function initInterface() {
   const props = {
     mode,
     branch,
+    host,
+    buildNumber,
+    compressionFormat,
     ...scriptInfo,
     ...globalFuncs,
     UserUtils,

+ 3 - 3
src/menu/menu_old.ts

@@ -1,6 +1,6 @@
 import { compress, decompress, debounce, isScrollable } from "@sv443-network/userutils";
 import { defaultConfig, getFeatures, migrations, saveFeatures, setDefaultFeatures } from "../config";
-import { compressionFormat, host, scriptInfo } from "../constants";
+import { buildNumber, compressionFormat, host, mode, scriptInfo } from "../constants";
 import { featInfo, disableBeforeUnload } from "../features/index";
 import { error, getResourceUrl, info, log, resourceToHTMLString, warn, getLocale, hasKey, initTranslations, setLocale, t, parseMarkdown, getChangelogMd, compressionSupported } from "../utils";
 import { formatVersion } from "../config";
@@ -535,8 +535,8 @@ async function addCfgMenu() {
   versionElem.classList.add("bytm-link");
   versionElem.role = "button";
   versionElem.tabIndex = 0;
-  versionElem.ariaLabel = versionElem.title = t("version_tooltip", scriptInfo.version, scriptInfo.buildNumber);
-  versionElem.textContent = `v${scriptInfo.version} (${scriptInfo.buildNumber})`;
+  versionElem.ariaLabel = versionElem.title = t("version_tooltip", scriptInfo.version, buildNumber);
+  versionElem.textContent = `v${scriptInfo.version} (${buildNumber})${mode === "development" ? " [dev build]" : ""}`;
   const versionElemClicked = async (e: MouseEvent | KeyboardEvent) => {
     e.preventDefault();
     e.stopPropagation();

+ 7 - 1
src/utils/xhr.ts

@@ -8,7 +8,12 @@ import type { HttpUrlString } from "../types";
  * @returns Returns a string instead of a URL object
  */
 export function constructUrlString(baseUrl: HttpUrlString, params: Record<string, Stringifiable | null>) {
-  return `${baseUrl}?${Object.entries(params).map(([key, val]) => `${key}${val === null ? "" : `=${encodeURIComponent(String(val))}`}`).join("&")}`;
+  return `${baseUrl}?${
+    Object.entries(params)
+      .filter(([,v]) => v !== undefined)
+      .map(([key, val]) => `${key}${val === null ? "" : `=${encodeURIComponent(String(val))}`}`)
+      .join("&")
+  }`;
 }
 
 /**
@@ -28,6 +33,7 @@ export function constructUrl(base: HttpUrlString, params: Record<string, Stringi
 export function sendRequest<T = any>(details: GM.Request<T>) {
   return new Promise<GM.Response<T>>((resolve, reject) => {
     GM.xmlHttpRequest({
+      timeout: 10_000,
       ...details,
       onload: resolve,
       onerror: reject,