feat(cards): คลิกการ์ดโรงหนังได้ทั้งใบ (ไม่ใช่แค่ "ดูรายละเอียด")

- assets/card-click.v1.js: event delegation บน <article> → location.assign(a[href^="/cinema/"])
  · ยกเว้นปุ่ม/ลิงก์ภายในใบ (ปุ่มแชร์ยังทำงานเอง) และตอนลากเลือกข้อความ
  · cursor pointer + focus ring ที่ลิงก์ "ดูรายละเอียด"
- scripts/apply-card-click.mjs: เติม <script defer> ให้ทุก .html (64 ไฟล์) + โหมด --check
- sw.js: precache card-click + VERSION v2.1.3
- docs/card-clickable.md: กติกา ผลทดสอบ และขั้นตอนหลัง re-export
This commit is contained in:
Bkk1234 committed 2026-11-24 15:25:06 +07:00
1 parent 3ebfcfea75
commit c2506b8ed4
68 files changed
+212 -65

No files matched your search

+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -67,4 +67,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+56
View File
@@ -0,0 +1,56 @@
/*!
* card-click v1 — ทำให้การ์ดโรงหนัง "ทั้งใบ" กดเปิดหน้าโรงหนังได้
*
* บริบท: เว็บนี้เป็น static export (HTML + JS ที่ build มาแล้ว ไม่มี React source ในรีโป)
* จึงเสริมพฤติกรรมด้วย event delegation แทนการแก้ component
*
* กติกา
* - คลิกที่ว่างของการ์ด = ไปหน้า /cinema/<slug> ของการ์ดนั้น
* - คลิกที่ปุ่ม/ลิงก์/ช่องกรอกในใบ (เช่น ปุ่มแชร์, "ดูรายละเอียด") = ปล่อยให้ของเดิมทำงาน
* - ไม่ทำงานเมื่อ: กดปุ่มกลาง/ขวา, มี modifier (ctrl/cmd/shift/alt), หรือกำลังลากเลือกข้อความ
* - คีย์บอร์ดยังใช้ลิงก์ "ดูรายละเอียด" (Tab + Enter) ได้ตามเดิม
*/
(() => {
const CARD = "article";
const CARD_LINK = 'a[href^="/cinema/"]';
const INTERACTIVE =
'a,button,input,select,textarea,label,summary,[role="button"],[contenteditable="true"]';
function cardClick(event) {
if (event.defaultPrevented || event.button !== 0) return;
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
const target = event.target instanceof Element ? event.target : null;
if (!target) return;
const card = target.closest(CARD);
if (!card) return;
// ปล่อยให้ปุ่ม/ลิงก์ภายในใบทำงานของตัวเอง (เช่น ปุ่มแชร์)
const own = target.closest(INTERACTIVE);
if (own && card.contains(own)) return;
// อย่าแย่งคลิกตอนผู้ใช้ลากเลือกข้อความ
const selection = window.getSelection();
if (selection && selection.toString().trim() !== "") return;
const link = card.querySelector(CARD_LINK);
if (!link) return;
event.preventDefault();
location.assign(link.getAttribute("href"));
}
document.addEventListener("click", cardClick);
// ลูกศรชี้ + วงโฟกัทให้เห็นว่าใบนี้กดได้ (ใช้ selector เดียวกับการ์ดจริง)
const style = document.createElement("style");
style.textContent =
'article:has(' +
CARD_LINK +
"){cursor:pointer}" +
"article " +
CARD_LINK +
":focus-visible{outline:2px solid #A92626;outline-offset:4px;border-radius:16px}";
document.head.appendChild(style);
})();
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
+1 -1
View File
@@ -12,4 +12,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script> })();</script><script src="/assets/card-click.v1.js" defer></script>
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+37
View File
@@ -0,0 +1,37 @@
# การ์ดโรงหนัง — คลิกได้ทั้งใบ (static export)
รีโปนี้เก็บ **static export** (HTML + JS ที่ build แล้ว) ไม่มี source component ให้แก้
จึงเสริมพฤติกรรม "คลิกทั้งใบการ์ด = เปิดหน้าโรงหนัง" ด้วยสคริปต์เล็ก ๆ ที่โหลดทุกหน้า
## ไฟล์ที่เกี่ยวข้อง
| ไฟล์ | หน้าที่ |
|---|---|
| `assets/card-click.v1.js` | event delegation: คลิกพื้นที่ว่างของ `<article>` → ไป `a[href^="/cinema/"]` ในใบนั้น |
| `scripts/apply-card-click.mjs` | เติม `<script src="/assets/card-click.v1.js" defer>` ให้ทุก `.html` (ใช้ซ้ำหลัง re-export) |
| `sw.js` | precache ไฟล์สคริปต์ + bump `VERSION` เมื่อแก้ |
## กติกาที่สคริปต์ยึด
- คลิกว่าง ๆ ของใบ → ไปหน้าโรงหนังของใบนั้น (ทั้งการ์ดสีดำ ไม่ใช่แค่คำว่า "ดูรายละเอียด")
- คลิก **ปุ่ม/ลิงก์ในใบ** (เช่น ปุ่มแชร์ `aria-label="แชร์: …"`, ลิงก์ "ดูรายละเอียด") → ทำงานของตัวเอง ไม่เด้งออก
- ไม่ทำงานเมื่อ: ปุ่มกลาง/ขวา, กด Ctrl/Cmd/Shift/Alt, หรือกำลังลากเลือกข้อความ
- คีย์บอร์ดยังใช้ได้: `Tab` ไปที่ "ดูรายละเอียด" → `Enter` (มี focus ring สี `#A92626`)
- `article:has(a[href^="/cinema/"])` ได้ `cursor: pointer`
## หลัง re-export ชุดใหม่
```bash
node scripts/apply-card-click.mjs # เติมสคริปต์ทุกหน้า
node scripts/apply-card-click.mjs --check # ตรวจว่าครบ (ใช้ใน CI ได้)
```
## ทดสอบที่ทำแล้ว (static server 8092)
| ทดสอบ | ผล |
|---|---|
| คลิก `<h3>` ชื่อโรงหนัง | ไป `/cinema/suen-heng-multiplex-sisaket/` ✓ |
| คลิกพื้นหลังการ์ด (div) | ไปหน้าโรงหนัง ✓ |
| คลิกปุ่มแชร์ในการ์ด | อยู่หน้าเดิม (ไม่ navigate) ✓ |
| `cursor` บน `<article>` | `pointer` ✓ |
| หน้าอื่น (เช่น การ์ดใน "โรงหนังอิสระอื่นๆ") | ใช้ delegation ตัวเดียวกัน จึงได้ผลเหมือนกัน |
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -70,4 +70,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -66,4 +66,4 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body></html> })();</script><script src="/assets/card-click.v1.js" defer></script></body></html>
+1 -1
View File
@@ -85,5 +85,5 @@ document.addEventListener("click",(event)=>{
event.stopImmediatePropagation(); event.stopImmediatePropagation();
location.assign(anchor.getAttribute("href")); location.assign(anchor.getAttribute("href"));
},true); },true);
})();</script></body> })();</script><script src="/assets/card-click.v1.js" defer></script></body>
</html> </html>
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env node
/**
* ใส่ <script src="/assets/card-click.v1.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.v1.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.v1.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})`);
}
+2 -1
View File
@@ -18,7 +18,7 @@
* | โดเมนอื่น (รูป hotlink) | ไม่จัดการ | * | โดเมนอื่น (รูป hotlink) | ไม่จัดการ |
* | /app/* · /node_modules/* · /@* | ไม่จัดการ (โมดูลของ dev server) | * | /app/* · /node_modules/* · /@* | ไม่จัดการ (โมดูลของ dev server) |
*/ */
const VERSION = "v2.1.2"; const VERSION = "v2.1.3";
const PAGES_CACHE = `alterflixhub-pages-${VERSION}`; const PAGES_CACHE = `alterflixhub-pages-${VERSION}`;
const ASSETS_CACHE = `alterflixhub-assets-${VERSION}`; const ASSETS_CACHE = `alterflixhub-assets-${VERSION}`;
@@ -29,6 +29,7 @@ const PRECACHE = [
"/icon-192.png", "/icon-192.png",
"/icon-512.png", "/icon-512.png",
"/favicon.svg", "/favicon.svg",
"/assets/card-click.v1.js",
]; ];
self.addEventListener("install", (event) => { self.addEventListener("install", (event) => {