#!/usr/bin/env node /** * ใส่ '; const CHECK = process.argv.includes("--check"); const SKIP = new Set(["node_modules", ".git"]); function walk(dir, out = []) { for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { if (SKIP.has(entry.name)) continue; const full = path.join(dir, entry.name); if (entry.isDirectory()) walk(full, out); else if (entry.name.endsWith(".html")) out.push(full); } return out; } const files = walk("."); let patched = 0; const missing = []; for (const file of files) { const html = fs.readFileSync(file, "utf8"); if (html.includes("card-click.v2.js")) continue; missing.push(file); if (CHECK) continue; const next = html.includes("") ? html.replace("", `${TAG}`) : html + TAG; fs.writeFileSync(file, next); patched++; } if (CHECK) { console.log( missing.length === 0 ? `ครบแล้ว: ${files.length} ไฟล์` : `ยังขาด ${missing.length}/${files.length} ไฟล์:\n${missing.join("\n")}`, ); } else { console.log(`เติมสคริปต์แล้ว ${patched} ไฟล์ (จากทั้งหมด ${files.length})`); }