From d136acf92a804bb8cddad669e8c78409301cc1fb Mon Sep 17 00:00:00 2001 From: Chen Buyi Date: Sat, 24 Feb 2024 15:48:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=89=B9=E9=87=8F=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/index.html | 27 ++++++++-- docs/steam-id.js | 126 +++++++++++++++++++++++++++++++++++++++-------- src/batch.ts | 83 +++++++++++++++++++++++++++++++ src/main.ts | 41 +++++++-------- 4 files changed, 234 insertions(+), 43 deletions(-) create mode 100644 src/batch.ts diff --git a/docs/index.html b/docs/index.html index a81cd45..7a2d3a3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -37,7 +37,7 @@ margin: 5px; } - #txtOutput { + textarea { display: block; margin: 5px; width: 80%; @@ -94,7 +94,28 @@

Steam ID 转换

-

各种 Steam ID

+

批量转换

+ 输入的类型: +
+ id64 + id32 + id3 + 好友代码 + 群组代码 +
+ 输出的类型: +
+ id64 + id32 + id3 + 好友/群组代码 +
+ +

+ +
+
+

各种 Steam ID 示例

@@ -145,4 +166,4 @@

各种 Steam ID

- + \ No newline at end of file diff --git a/docs/steam-id.js b/docs/steam-id.js index 8c9a052..601e723 100644 --- a/docs/steam-id.js +++ b/docs/steam-id.js @@ -1,4 +1,89 @@ "use strict"; +const butConvertBatch = document.getElementById("butConvertBatch"); +const txtBatch = document.getElementById("txtBatch"); +function ConvertBatch() { + let inputType = SteamId.SteamIdType.id64; + let radios = document.getElementsByName("steamIdType2"); + let inputv = ""; + for (const element of radios) { + const radio = element; + if (radio.checked) { + inputv = radio.value; + inputType = getTypeFromTypeName(radio.value); + break; + } + } + let outputType = ""; + radios = document.getElementsByName("steamIdType3"); + for (const element of radios) { + const radio = element; + if (radio.checked) { + outputType = radio.value; + break; + } + } + let raw = txtBatch.value.trim(); + if (raw.length < 1) { + return ""; + } + let lines = raw.split("\n"); + let output = ""; + function addLine(str) { + if (output.length > 0) { + output += "\n"; + } + output += str; + } + for (const lineraw of lines) { + let line = lineraw.trim(); + if (line.length < 1) { + addLine(""); + continue; + } + switch (inputv) { + case 'id3num': + line = `U:1:${line}`; + break; + case 'id3numgroup': + line = `g:1:${line}`; + break; + } + try { + const id = new SteamId.SteamIdInfo(line, inputType); + switch (outputType) { + case "id64": + addLine(id.GetId64()); + break; + case "id32": + addLine(id.GetId32()); + break; + case "id3": + addLine(id.GetId3()); + break; + case "id3num": + addLine(id.GetId3Number().toString()); + break; + default: + addLine("未知类型 " + outputType); + break; + } + } + catch (error) { + addLine(`错误 ${line} ${error}`); + } + } + return output.trim(); +} +butConvertBatch.addEventListener("click", function () { + let str; + try { + str = ConvertBatch(); + } + catch (error) { + str = "出错: " + String(error); + } + txtBatch.value = str; +}); var SteamId; (function (SteamId) { let SteamIdType; @@ -124,6 +209,22 @@ const butConvert = document.getElementById('butConvert'); const txtOutput = document.getElementById('txtOutput'); const butGotoURL = document.getElementById('butGotoURL'); let lastUrl = ""; +function getTypeFromTypeName(s) { + switch (s) { + case 'id3num': + return SteamId.SteamIdType.id3; + case 'id3numgroup': + return SteamId.SteamIdType.id3; + case 'id3': + return SteamId.SteamIdType.id3; + case 'id64': + return SteamId.SteamIdType.id64; + case 'id32': + return SteamId.SteamIdType.id32; + default: + throw `无法识别的输入类型: ${s}`; + } +} function doWork() { lastUrl = ""; let inputType = SteamId.SteamIdType.id64; @@ -133,25 +234,7 @@ function doWork() { const radio = element; if (radio.checked) { inputv = radio.value; - switch (inputv) { - case 'id3num': - inputType = SteamId.SteamIdType.id3; - break; - case 'id3numgroup': - inputType = SteamId.SteamIdType.id3; - break; - case 'id3': - inputType = SteamId.SteamIdType.id3; - break; - case 'id64': - inputType = SteamId.SteamIdType.id64; - break; - case 'id32': - inputType = SteamId.SteamIdType.id32; - break; - default: - throw `无法识别的输入类型: ${inputv}`; - } + inputType = getTypeFromTypeName(inputv); break; } } @@ -186,7 +269,10 @@ function doWork() { addLine(`id32: ${id.GetId32()}`); addLine(`id3: ${id.GetId3()}`); if (id.IsGroup) { - addLine("群组"); + addLine(`群组代码: ${id.GetId3Number()}`); + } + else { + addLine(`好友代码: ${id.GetId3Number()}`); } return out; } diff --git a/src/batch.ts b/src/batch.ts new file mode 100644 index 0000000..4f172ad --- /dev/null +++ b/src/batch.ts @@ -0,0 +1,83 @@ +const butConvertBatch = document.getElementById("butConvertBatch") as HTMLButtonElement +const txtBatch = document.getElementById("txtBatch") as HTMLTextAreaElement + +function ConvertBatch(): string { + let inputType: SteamId.SteamIdType = SteamId.SteamIdType.id64 + let radios = document.getElementsByName("steamIdType2") + let inputv: string = "" + for (const element of radios) { + const radio = element as HTMLInputElement + if (radio.checked) { + inputv = radio.value + inputType = getTypeFromTypeName(radio.value) + break; + } + } + let outputType: string = "" + radios = document.getElementsByName("steamIdType3") + for (const element of radios) { + const radio = element as HTMLInputElement + if (radio.checked) { + outputType = radio.value + break; + } + } + let raw = txtBatch.value.trim() + if (raw.length < 1) { return ""; } + let lines = raw.split("\n") + let output = "" + function addLine(str: string) { + if (output.length > 0) { + output += "\n" + } + output += str + } + for (const lineraw of lines) { + let line = lineraw.trim() + if (line.length < 1) { + addLine("") + continue + } + switch (inputv) { + case 'id3num': + line = `U:1:${line}` + break + case 'id3numgroup': + line = `g:1:${line}` + break + } + try { + const id = new SteamId.SteamIdInfo(line, inputType) + switch (outputType) { + case "id64": + addLine(id.GetId64()) + break + case "id32": + addLine(id.GetId32()) + break + case "id3": + addLine(id.GetId3()) + break + case "id3num": + addLine(id.GetId3Number().toString()) + break + default: + addLine("未知类型 " + outputType) + break + } + } catch (error) { + addLine(`错误 ${line} ${error}`) + } + } + return output.trim() +} + +butConvertBatch.addEventListener("click", function () { + let str: string + try { + str = ConvertBatch() + } catch (error) { + str = "出错: " + String(error) + } + txtBatch.value = str +}) \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 3d473ff..62f77fb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,6 +8,23 @@ const butGotoURL = document.getElementById('butGotoURL') as HTMLAnchorElement let lastUrl = "" +function getTypeFromTypeName(s: string): SteamId.SteamIdType { + switch (s) { + case 'id3num': + return SteamId.SteamIdType.id3 + case 'id3numgroup': + return SteamId.SteamIdType.id3 + case 'id3': + return SteamId.SteamIdType.id3 + case 'id64': + return SteamId.SteamIdType.id64 + case 'id32': + return SteamId.SteamIdType.id32 + default: + throw `无法识别的输入类型: ${s}` + } +} + function doWork(): string { lastUrl = "" let inputType: SteamId.SteamIdType = SteamId.SteamIdType.id64 @@ -17,25 +34,7 @@ function doWork(): string { const radio = element as HTMLInputElement if (radio.checked) { inputv = radio.value - switch (inputv) { - case 'id3num': - inputType = SteamId.SteamIdType.id3 - break - case 'id3numgroup': - inputType = SteamId.SteamIdType.id3 - break - case 'id3': - inputType = SteamId.SteamIdType.id3 - break - case 'id64': - inputType = SteamId.SteamIdType.id64 - break - case 'id32': - inputType = SteamId.SteamIdType.id32 - break - default: - throw `无法识别的输入类型: ${inputv}` - } + inputType = getTypeFromTypeName(inputv) break; } } @@ -67,7 +66,9 @@ function doWork(): string { addLine(`id32: ${id.GetId32()}`) addLine(`id3: ${id.GetId3()}`) if (id.IsGroup) { - addLine("群组") + addLine(`群组代码: ${id.GetId3Number()}`) + } else { + addLine(`好友代码: ${id.GetId3Number()}`) } return out; }
名字