소스 검색

feat: better delete GM value dev cmd

Sv443 1 년 전
부모
커밋
ad9ccd403e
1개의 변경된 파일11개의 추가작업 그리고 6개의 파일을 삭제
  1. 11 6
      src/index.ts

+ 11 - 6
src/index.ts

@@ -335,12 +335,17 @@ function registerMenuCommands() {
       }
     }, "d");
 
-    GM.registerMenuCommand("Delete GM value by name", async () => {
-      const key = prompt("Enter the name of the GM value to delete.\nEmpty input cancels the operation.");
-      if(key && key.length > 0) {
-        const oldVal = await GM.getValue(key);
-        await GM.deleteValue(key);
-        console.log(`Deleted GM value '${key}' with previous value '${oldVal}'`);
+    GM.registerMenuCommand("Delete GM values by name (comma separated)", async () => {
+      const keys = prompt("Enter the name(s) of the GM value to delete (comma separated).\nEmpty input cancels the operation.");
+      if(!keys)
+        return;
+      for(const key of keys?.split(",") ?? []) {
+        if(key && key.length > 0) {
+          const truncLength = 400;
+          const oldVal = await GM.getValue(key);
+          await GM.deleteValue(key);
+          console.log(`Deleted GM value '${key}' with previous value '${oldVal && String(oldVal).length > truncLength ? String(oldVal).substring(0, truncLength) + `… (${String(oldVal).length} / ${truncLength} chars.)` : oldVal}'`);
+        }
       }
     }, "n");