32 lines
1.4 KiB
JavaScript
32 lines
1.4 KiB
JavaScript
// 把预设里带的脚本(酒馆助手 / STscript / JS)挑出来看,判断脚本层要什么 API。
|
|
// 用法: node dump-scripts.mjs <preset.json> [每个脚本打印多少字符]
|
|
import { readFileSync } from "node:fs";
|
|
const preset = JSON.parse(readFileSync(process.argv[2], "utf8"));
|
|
const n = Number(process.argv[3] ?? 4000);
|
|
|
|
function walk(node, pathParts, out) {
|
|
if (node == null || typeof node !== "object") return;
|
|
if (Array.isArray(node)) {
|
|
node.forEach((v, i) => walk(v, [...pathParts, String(i)], out));
|
|
return;
|
|
}
|
|
for (const [k, v] of Object.entries(node)) {
|
|
if (typeof v === "string" && /(function|=>|TavernHelper|SillyTavern|jQuery|\$\(|await\s)/.test(v) && v.length > 60 && !/\.png|\.jpg|base64/.test(v.slice(0, 40))) {
|
|
out.push({ path: [...pathParts, k].join("."), len: v.length, code: v });
|
|
} else if (k === "scripts" || k === "Variables" || k === "variables" || k === "data" || k === "info" || k === "content") {
|
|
if (typeof v === "string" && v.length > 60) out.push({ path: [...pathParts, k].join("."), len: v.length, code: v });
|
|
else walk(v, [...pathParts, k], out);
|
|
} else if (typeof v === "object") {
|
|
walk(v, [...pathParts, k], out);
|
|
}
|
|
}
|
|
}
|
|
|
|
const out = [];
|
|
walk(preset, [], out);
|
|
console.log("候选脚本/代码块: " + out.length);
|
|
for (const item of out) {
|
|
console.log("\n=== " + item.path + " (" + item.len + " 字符) ===");
|
|
console.log(item.code.slice(0, n));
|
|
}
|