Explorar el Código

ref: logging & interface stuff

Sv443 hace 1 año
padre
commit
1767e1d9be
Se han modificado 2 ficheros con 9 adiciones y 6 borrados
  1. 7 4
      src/interface.ts
  2. 2 2
      src/utils/logging.ts

+ 7 - 4
src/interface.ts

@@ -85,7 +85,7 @@ export function initInterface() {
   log("Initialized BYTM interface");
 }
 
-/** Sets a global property on the window.BYTM object */
+/** Sets a global property on the unsafeWindow.BYTM object */
 export function setGlobalProp<
   TKey extends keyof Window["BYTM"],
   TValue = Window["BYTM"][TKey],
@@ -93,10 +93,12 @@ export function setGlobalProp<
   key: TKey | (string & {}),
   value: TValue,
 ) {
-  // use unsafeWindow so the properties are available outside of the userscript's scope
+  // use unsafeWindow so the properties are available to plugins outside of the userscript's scope
   const win = getUnsafeWindow();
-  if(!win.BYTM)
-    win.BYTM = {} as typeof win.BYTM;
+
+  if(typeof win.BYTM !== "object")
+    win.BYTM = {} as typeof window.BYTM;
+
   win.BYTM[key] = value;
 }
 
@@ -113,6 +115,7 @@ export function emitInterface<
 
 //#MARKER proxy functions
 
+/** Returns the current feature config, with sensitive values replaced by `undefined` */
 export function getFeaturesInterface() {
   const features = getFeatures();
   for(const ftKey of Object.keys(features)) {

+ 2 - 2
src/utils/logging.ts

@@ -11,10 +11,10 @@ const consPrefixDbg = `[${scriptInfo.name}/#DEBUG]`;
 
 /** Sets the current log level. 0 = Debug, 1 = Info */
 export function setLogLevel(level: LogLevel) {
-  if(curLogLevel !== level)
-    console.log(consPrefix, "Setting log level to", level === 0 ? "Debug" : "Info");
   curLogLevel = level;
   setGlobalProp("logLevel", level);
+  if(curLogLevel !== level)
+    log("Set the log level to", LogLevel[level]);
 }
 
 /** Extracts the log level from the last item from spread arguments - returns 0 if the last item is not a number or too low or high */