- card-click v2: ตรวจว่าคลิกอยู่ใน parent ของลิงก์ "ดูรายละเอียด" (= กล่อง bg-[#1B1B1B]) · คลิกรูป/พื้นที่ด้านบนการ์ด → ไม่ทำอะไร · คลิกกล่องข้อความ (km./ชื่อ/ที่ตั้ง/tag/ช่องว่าง) → เปิดหน้าโรงหนัง · ปุ่มแชร์ยังทำงานเอง - cursor: pointer เฉพาะกล่องข้อความ (article = auto) - ลบ card-click.v1.js · อัปเดตแท็กใน 64 หน้า · sw VERSION v2.1.4 + precache v2 - docs/card-clickable.md: อธิบายขอบเขตการคลิกด้วยโครงสร้าง DOM จริง
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* ใส่ <script src="/assets/card-click.v2.js" defer> ให้ทุกไฟล์ .html
|
|
*
|
|
* ใช้: node scripts/apply-card-click.mjs [--check]
|
|
* --check = ดูว่ามีไฟล์ไหนยังไม่ถูกใส่ (ไม่เขียนไฟล์)
|
|
*
|
|
* ไฟล์นี้มีไว้เพราะรีโปนี้เก็บ "static export" ไม่มี source ให้แก้ component
|
|
* ถ้า re-export ใหม่ทั้งชุด ให้รันสคริปต์นี้ซ้ำเพื่อเติมสคริปต์กลับเข้าไป
|
|
*/
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
const TAG = '<script src="/assets/card-click.v2.js" defer></script>';
|
|
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("</body>")
|
|
? html.replace("</body>", `${TAG}</body>`)
|
|
: 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})`);
|
|
}
|