ระบบ affiliate พาร์ทเนอร์ + นับผู้เข้าชม + สายที่เปิดดูบ่อย + ความปลอดภัยรูป
== ระบบพาร์ทเนอร์ (affiliate) ==
- resource/data/affiliates.json — ข้อมูล 11 โปรแกรม (8 ใน footer) + ที่วางลิงก์แนะนำ
- home.init.js: initSponsors() สร้างไทล์ marquee จาก JSON (ไม่ฮาร์ดโค้ดใน HTML)
· มี affiliate_link → <a target=_blank rel="noopener sponsored">
· ยังไม่มีลิงก์ → <span> แสดงรูปเฉย ๆ (กดไม่ได้ ไม่พาไปหน้าเปล่า)
· โหลด JSON ไม่ได้ → คงไทล์ fallback ที่ฝังใน HTML (8 ไทล์)
- เติมลิงก์ affiliate แล้ว 6 แบรนด์: 7-Eleven · Shopee · Lazada · airasia MOVE ·
busonlineticket · Trip.com
== ระบบสถิติ (ฝั่งเบราว์เซอร์ ไม่มี backend) ==
- ui/popular.js — "สายที่เปิดดูบ่อย" ใน footer
· score = hits × 0.5^(อายุวัน/30) — กันคะแนนเฟ้อ (ครึ่งชีวิต 30 วัน)
· ทิ้งข้อมูลที่ตายเกิน 180 วันอัตโนมัติ · เก็บ 2 ตัวเลข/สาย (~24 ไบต์)
· ไม่มีข้อมูล → ใช้ค่าเริ่มต้น 101/902/15/464
- ui/visitors.js — นับผู้เข้าชมจริง (ฐาน 12,834)
· กันเฟ้อ 3 ชั้น: sessionStorage (F5 ไม่นับ) → 1 ครั้ง/วัน → dayKey กันล้าง session
· กดตัวเลข 5 ครั้ง → ช่องกรอกรหัส (SHA-256 ไม่เก็บรหัสจริงในโค้ด) → รีเซ็ตเป็น 0
- หัวข้อ footer เปลี่ยนเป็น "สายที่เปิดดูบ่อย" / "Most Viewed Routes"
== ความปลอดภัยของรูป ==
- images.zip: ลบ EXIF/GPS ทั้งหมด 12 ไฟล์ (piexif — ไม่แตะ pixel data, คง ICC profile)
· ตัด .image/partners/_original/ ออก (ไฟล์สำรองที่ไม่ควรแจก)
· ตรวจแล้ว: GPS=0 · EXIF=0 · รูปเสีย=0 · 39.4 MB → 37 MB
- tcl999-angthong.jpg ย่อ 4032×3024 (2.5 MB) → 700×525 (86 KB) สำหรับใช้บนเว็บ
== UI ==
- nav (mu-topbar) z-index 50 → 1100 + isolation:isolate ที่กรอบแผนที่
(Leaflet ใช้ z-index ถึง 1000 — เดิมปุ่มซูม/ป๊อปอัปทะลุขึ้นทับ nav)
- รูปสำรองสถานี: ไม่มีรูป → แสดง minibus-512x512 (.is-fallback ใช้ object-fit:contain)
- affiliate.json เป็น CRLF ตาม pattern เดิมของโปรเจกต์
This commit is contained in:
1 parent
488b4c6054
commit
74d605f1c4
17 files changed
+624
-29
No files matched your search
@@ -0,0 +1,116 @@
|
||||
{
|
||||
"updated": "2026-10-07",
|
||||
"source_folder": "resource/sponsor/ลงทะเบียน affiliate program/",
|
||||
"warning": "ไฟล์นี้ถูกเสิร์ฟให้ผู้ใช้ทั่วไป — ห้ามใส่รหัสผ่าน อีเมล หรือคีย์ลับใด ๆ เก็บเฉพาะลิงก์สาธารณะ",
|
||||
"note": "affiliate_link = ลิงก์แนะนำของเรา (ยังว่าง — รอเติมหลังได้ลิงก์จริงจากแต่ละโปรแกรม) · program_url = หน้าลงทะเบียน/ล็อกอินของโปรแกรมนั้น",
|
||||
"partners": [
|
||||
{
|
||||
"id": "7-eleven",
|
||||
"brand": "7-Eleven",
|
||||
"brand_th": "เซเว่น อีเลฟเว่น",
|
||||
"tile_image": ".image/partners/7-11.png",
|
||||
"in_footer_marquee": true,
|
||||
"affiliate_program": "All Online (7-Eleven)",
|
||||
"program_url": "https://affiliate.allonline.7eleven.co.th",
|
||||
"affiliate_link": "https://allonline.link/r/lZ8z9",
|
||||
"status": "registered",
|
||||
"note": "ลงทะเบียนแล้วผ่าน All Online"
|
||||
},
|
||||
{
|
||||
"id": "shopee",
|
||||
"brand": "Shopee",
|
||||
"brand_th": "ช้อปปี้",
|
||||
"tile_image": ".image/partners/shopee.png",
|
||||
"in_footer_marquee": true,
|
||||
"affiliate_program": "Shopee Affiliate Program",
|
||||
"program_url": "https://affiliate.shopee.co.th/",
|
||||
"affiliate_link": "https://raka.is/r/w7LYb",
|
||||
"status": "unknown",
|
||||
"note": "ยังไม่พบข้อมูลในโฟลเดอร์ — รอตรวจ/ยืนยันบัญชี"
|
||||
},
|
||||
{
|
||||
"id": "lazada",
|
||||
"brand": "Lazada",
|
||||
"brand_th": "ลาซาด้า",
|
||||
"tile_image": ".image/partners/lazada.png",
|
||||
"in_footer_marquee": true,
|
||||
"affiliate_program": "Lazada Affiliate Program",
|
||||
"program_url": "https://www.lazada.co.th/affiliate-program/",
|
||||
"affiliate_link": "https://raka.is/r/DmYeP",
|
||||
"status": "unknown",
|
||||
"note": "ยังไม่พบข้อมูลในโฟลเดอร์ — รอตรวจ/ยืนยันบัญชี"
|
||||
},
|
||||
{
|
||||
"id": "airasia-move",
|
||||
"brand": "airasia MOVE",
|
||||
"brand_th": "แอร์เอเชีย มูฟ",
|
||||
"tile_image": ".image/partners/airasia-move.png",
|
||||
"in_footer_marquee": true,
|
||||
"affiliate_program": "airasia rewards / MOVE affiliate",
|
||||
"program_url": "https://www.airasia.com/",
|
||||
"affiliate_link": "https://prf.hn/l/8jkWB2w/",
|
||||
"status": "unknown",
|
||||
"note": "ยังไม่พบข้อมูลในโฟลเดอร์ — รอตรวจ/ยืนยันบัญชี"
|
||||
},
|
||||
{
|
||||
"id": "busonlineticket",
|
||||
"brand": "busonlineticket",
|
||||
"brand_th": "บัสออนไลน์ทิกเก็ต",
|
||||
"tile_image": ".image/partners/busonlineticket.png",
|
||||
"in_footer_marquee": true,
|
||||
"affiliate_program": "BusOnlineTicket Affiliates",
|
||||
"program_url": "https://www.busonlineticket.co.th/booking/affiliates.aspx",
|
||||
"affiliate_link": "https://www.busonlineticket.co.th/booking/default.aspx?refererid=Natthaphat",
|
||||
"status": "registered",
|
||||
"note": "มีบัญชีแล้ว (ชื่อผู้ใช้แบบไม่ใช้อีเมล)"
|
||||
},
|
||||
{
|
||||
"id": "trip-com",
|
||||
"brand": "Trip.com",
|
||||
"brand_th": "ทริปดอทคอม",
|
||||
"tile_image": ".image/partners/trip.jpg",
|
||||
"in_footer_marquee": true,
|
||||
"affiliate_program": "Trip.com Partners",
|
||||
"program_url": "https://th.trip.com/partners",
|
||||
"affiliate_link": "https://www.trip.com/t/fhNrva0meW2",
|
||||
"status": "registered",
|
||||
"note": "มีบัญชีแล้ว"
|
||||
},
|
||||
{
|
||||
"id": "truck2hand",
|
||||
"brand": "truck2hand",
|
||||
"brand_th": "ทรัคทูแฮนด์",
|
||||
"tile_image": ".image/partners/truck2hand.png",
|
||||
"in_footer_marquee": true,
|
||||
"affiliate_program": "truck2hand (รถบรรทุกมือสอง)",
|
||||
"program_url": "https://www.truck2hand.com/",
|
||||
"affiliate_link": "https://www.truck2hand.com/category/cat_bus_bus-type-minibus/",
|
||||
"status": "unknown",
|
||||
"note": "ยังไม่พบข้อมูลในโฟลเดอร์ — รอตรวจ/ยืนยันบัญชี"
|
||||
},
|
||||
{
|
||||
"id": "12go",
|
||||
"brand": "12go",
|
||||
"brand_th": "วัน ทู โก",
|
||||
"tile_image": ".image/partners/12go.png",
|
||||
"in_footer_marquee": true,
|
||||
"affiliate_program": "12go",
|
||||
"program_url": "https://agent.12go.com/th",
|
||||
"affiliate_link": "https://12go.asia/?z=10049585",
|
||||
"status": "unknown",
|
||||
"note": "มีบัญชีแล้ว"
|
||||
},
|
||||
{
|
||||
"id": "priceza",
|
||||
"brand": "Priceza",
|
||||
"brand_th": "ไพรซ์ซ่า",
|
||||
"tile_image": "",
|
||||
"in_footer_marquee": false,
|
||||
"affiliate_program": "Priceza Affiliate",
|
||||
"program_url": "https://aff.priceza.com/login",
|
||||
"affiliate_link": "",
|
||||
"status": "registered",
|
||||
"note": "มีบัญชีแล้ว — ยังไม่ใช้ใน footer"
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
+41
-21
@@ -12,8 +12,8 @@
|
||||
<link href="./_shared.css" rel="stylesheet">
|
||||
<link href="./vendor/leaflet/leaflet.css" rel="stylesheet">
|
||||
<link href="./map.css" rel="stylesheet">
|
||||
<meta name="app-version" content="2026.09.27.82">
|
||||
<link rel="icon" type="image/png" href="../.image/icons/minibus-512x512.png?v=2026.09.27.82">
|
||||
<meta name="app-version" content="2026.09.27.94">
|
||||
<link rel="icon" type="image/png" href="../.image/icons/minibus-512x512.png?v=2026.09.27.94">
|
||||
<style>
|
||||
.mu-card.empty { width: 100%; padding: 16px; text-align: center; color: #6f7b95; background: #fff7fb; border: 1px dashed #f4c7df; }
|
||||
a.mu-card { text-decoration: none; color: inherit; display: block; }
|
||||
@@ -70,7 +70,9 @@
|
||||
.mu-container { max-width: 1200px; margin: 0 auto; padding: 0 28px; }
|
||||
|
||||
/* Topbar */
|
||||
.mu-topbar { background: #ffffff; border-bottom: 1px solid #e9eef7; position: sticky; top: 0; z-index: 50; box-shadow: 0 2px 8px rgba(20,40,90,.04); }
|
||||
/* z-index 1100 — ต้องสูงกว่า Leaflet (pane 400 · control 800 · .leaflet-top 1000)
|
||||
ไม่งั้นแผนที่จะบัง nav ตอนเลื่อน */
|
||||
.mu-topbar { background: #ffffff; border-bottom: 1px solid #e9eef7; position: sticky; top: 0; z-index: 1100; box-shadow: 0 2px 8px rgba(20,40,90,.04); }
|
||||
.mu-topbar-inner { display: flex; align-items: center; gap: 18px; padding: 14px 28px; }
|
||||
.mu-brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
|
||||
.mu-logo-img { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg,#8b5cf6,#ec4899); padding: 4px; transition: transform .15s ease; }
|
||||
@@ -254,6 +256,33 @@
|
||||
}
|
||||
.mu-visitor svg { width: 14px; height: 14px; color: #b694f6; flex: none; }
|
||||
.mu-visitor strong { color: #fff; font-weight: 700; font-variant-numeric: tabular-nums; }
|
||||
/* ปุ่ม/ช่องรีเซ็ตผู้เข้าชม (ซ่อน — กดตัวเลข 5 ครั้ง) */
|
||||
#visitor-count { cursor: pointer; }
|
||||
.mu-vreset {
|
||||
position: fixed; inset: 0; z-index: 3000; display: flex; align-items: center; justify-content: center;
|
||||
padding: 20px; background: rgba(15, 23, 42, .55); backdrop-filter: blur(3px);
|
||||
}
|
||||
.mu-vreset-card {
|
||||
width: 100%; max-width: 340px; background: #fff; border-radius: 16px; padding: 20px;
|
||||
box-shadow: 0 18px 50px rgba(15, 23, 42, .28);
|
||||
}
|
||||
.mu-vreset-card h4 { margin: 0 0 12px; font-size: 1rem; color: #1f2a44; }
|
||||
.mu-vreset-card label { display: block; font-size: .8rem; color: #6b7a94; margin-bottom: 6px; }
|
||||
.mu-vreset-card input {
|
||||
width: 100%; box-sizing: border-box; padding: 10px 12px; font-size: .95rem;
|
||||
border: 1px solid #d9d3e8; border-radius: 10px; color: #1f2a44; background: #fbfaff;
|
||||
}
|
||||
.mu-vreset-card input:focus { outline: 2px solid #7a4cc0; outline-offset: 1px; border-color: #7a4cc0; }
|
||||
.mu-vreset-msg { margin: 10px 0 0; min-height: 18px; font-size: .8rem; color: #b3261e; }
|
||||
.mu-vreset-msg.is-ok { color: #1f7a3d; }
|
||||
.mu-vreset-row { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }
|
||||
.mu-vreset-row button {
|
||||
padding: 9px 16px; font-size: .85rem; font-weight: 700; border-radius: 10px; cursor: pointer;
|
||||
border: 1px solid #d9d3e8; background: #fff; color: #3d4a63;
|
||||
}
|
||||
.mu-vreset-row button:hover { background: #fbfaff; }
|
||||
.mu-vreset-ok { border-color: #7a4cc0 !important; background: #7a4cc0 !important; color: #fff !important; }
|
||||
.mu-vreset-ok:hover { background: #6a3fb0 !important; }
|
||||
|
||||
/* ===== Sponsor marquee (between hero and main) ===== */
|
||||
.mu-sponsor-marquee { padding: 26px 0 6px; background: #fff; border-bottom: 1px solid #f0f2f8; }
|
||||
@@ -310,10 +339,12 @@
|
||||
<meta name="theme-color" content="#7a4cc0">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
||||
<link rel="apple-touch-icon" href="../.image/icons/minibus-192x192.png?v=2026.09.27.82">
|
||||
<link rel="apple-touch-icon" href="../.image/icons/minibus-192x192.png?v=2026.09.27.94">
|
||||
<script src="./imageurl.js" defer></script>
|
||||
<script src="./pwa.js" defer></script>
|
||||
<script src="./i18n.js" defer></script>
|
||||
<script src="./popular.js" defer></script>
|
||||
<script src="./visitors.js" defer></script>
|
||||
<script src="./vendor/leaflet/leaflet.js" defer></script>
|
||||
<script src="./map.js" defer></script>
|
||||
<script src="./partials/schedules.js" defer></script>
|
||||
@@ -413,7 +444,7 @@
|
||||
<header class="mu-topbar">
|
||||
<div class="mu-container mu-topbar-inner">
|
||||
<a class="mu-brand" href="#/" aria-label="Atroute — หน้าแรก">
|
||||
<img class="mu-logo-img" src="../.image/icons/minibus-512x512.png?v=2026.09.27.82" alt="Atroute logo" width="44" height="44" decoding="async">
|
||||
<img class="mu-logo-img" src="../.image/icons/minibus-512x512.png?v=2026.09.27.94" alt="Atroute logo" width="44" height="44" decoding="async">
|
||||
<span>
|
||||
<span class="mu-brand-title">Atroute</span>
|
||||
<span class="mu-brand-subtitle" data-i18n="brand.subtitle">สถานีขนส่งผู้โดยสารจังหวัดอ่างทอง</span>
|
||||
@@ -456,7 +487,7 @@
|
||||
<div class="mu-footer-grid">
|
||||
<div class="mu-footer-brand">
|
||||
<div class="mu-footer-brand-row">
|
||||
<img src="../.image/icons/minibus-512x512.png?v=2026.09.27.82" alt="Atroute">
|
||||
<img src="../.image/icons/minibus-512x512.png?v=2026.09.27.94" alt="Atroute">
|
||||
<div>
|
||||
<strong>Atroute</strong>
|
||||
<span data-i18n="brand.subtitle">สถานีขนส่งผู้โดยสารจังหวัดอ่างทอง</span>
|
||||
@@ -475,8 +506,9 @@
|
||||
<li><a href="#/credits" data-i18n="nav.credits">เครดิต</a></li></ul>
|
||||
</div>
|
||||
<div class="mu-footer-col">
|
||||
<h4 data-i18n="footer.popular">สายที่ค้นหาบ่อยที่สุด</h4>
|
||||
<ul>
|
||||
<h4 data-i18n="footer.popular">สายที่เปิดดูบ่อย</h4>
|
||||
<!-- เติมด้วย Popular.mount() — li ข้างในเป็น fallback เมื่อ JS ปิด -->
|
||||
<ul id="footer-popular-list" data-i18n-skip>
|
||||
<li><a href="#/routes/101">สาย 101 · อ่างทอง-อยุธยา</a></li>
|
||||
<li><a href="#/routes/902">สาย 902 · กรุงเทพ-อ่างทอง</a></li>
|
||||
<li><a href="#/routes/15">สาย 15 · สายใน</a></li>
|
||||
@@ -494,24 +526,12 @@
|
||||
<span class="mu-visitor" title="จำนวนผู้เข้าชมเว็บไซต์">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/></svg>
|
||||
<span>ผู้เข้าชม</span>
|
||||
<strong id="visitor-count">12,483</strong>
|
||||
<strong id="visitor-count">12,834</strong>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
var KEY = 'at_transit_visitor_count';
|
||||
var BASE = 12483;
|
||||
var el = document.getElementById('visitor-count');
|
||||
if (!el) return;
|
||||
var n = parseInt(localStorage.getItem(KEY), 10);
|
||||
n = isNaN(n) ? BASE : n + 1;
|
||||
try { localStorage.setItem(KEY, String(n)); } catch (err) {}
|
||||
el.textContent = n.toLocaleString('en-US');
|
||||
})();
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// ปิดเมนู hamburger เมื่อ hash เปลี่ยน หรือคลิกนอกเมนู
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@
|
||||
"map.youAreHere": "Your location",
|
||||
"cta.check": "Check Schedules",
|
||||
"footer.menu": "Menu",
|
||||
"footer.popular": "Most Searched Routes",
|
||||
"footer.popular": "Most Viewed Routes",
|
||||
"footer.popstops": "Popular Stops",
|
||||
"footer.contact": "Contact",
|
||||
"footer.about": "Every bus stop in Ang Thong and nearby provinces — locations and routes served.",
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@
|
||||
"map.youAreHere": "ตำแหน่งของคุณ",
|
||||
"cta.check": "เช็กเวลาเดินรถ",
|
||||
"footer.menu": "เมนู",
|
||||
"footer.popular": "สายที่ค้นหาบ่อยที่สุด",
|
||||
"footer.popular": "สายที่เปิดดูบ่อย",
|
||||
"footer.popstops": "ป้ายยอดนิยม",
|
||||
"footer.contact": "ติดต่อ",
|
||||
"footer.about": "รวมป้ายขึ้น-ลงรถทุกจุดในจังหวัดอ่างทองและจังหวัดใกล้เคียง พร้อมตำแหน่งและสายรถที่ผ่าน",
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
.at-map {
|
||||
position: relative;
|
||||
isolation: isolate; /* กัก z-index ของ Leaflet (400–1000) ไว้ในกรอบแผนที่ — ไม่ให้ทับ nav */
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
border: 1px solid #ddd5c0;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -236,7 +236,7 @@
|
||||
"3.เปิดเส้นทางใหม่ เอาจริงๆข้อนี้ก็ยากเพราะข้าราชการจะยอมเปิดเส้นทางใหม่มั้ย ถ้าเปิดเส้นทางใหม่แล้วใครจะมาประมูลใบอนุญาตและกลุ่มผู้โดยสารขาประจำจะมีเพียงพอมั้ยก็ไม่รู้ อยากเสนอให้พิจารณา ได้แก่ ",
|
||||
"รถไฟฟ้าสายสีแดงเข้ม อ่างทอง-ป่าโมก-สถานีชุมทางบ้านภาชี ทั้งๆที่มีสถานีรถไฟชานเมืองอยู่แล้ว แม้ว่าจะอ้อมกว่าเล็กน้อยจะเสนอ เพราะว่าการขึ้นสถานีต้นทางประกันว่ามีที่นั่งแน่นอนและหนีความวุ่นวาย สถานีรถไฟฟ้าอยุธยาต้องวุ่นวายทั้งคนรอรถไฟความเร็วสูง รถไฟฟ้าชานเมือง นักท่องเที่ยว ",
|
||||
"รถไฟฟ้าความเร็วสูง อ่างทอง-ป่าโมก-สถานีรถไฟฟ้าความเร็วสูงอยุธยา ทั้งๆที่ตั้งอยู่ที่เดียวกันนั่นแหละ แต่เสนอเพราะอยากให้เดินทางเร็วสอดคล้องกับเที่ยวรถไฟความเร็วสูงคนที่จะไป อีสานและกรุงเทพ ",
|
||||
"รถไฟฟ้ารางเดี่ยวสีชมพู อ่างทอง-ป่าโมก-MRT แยกปากเกร็ด หรือ ทะเลสาบเมืองทองธานี หรือวัชรพล เชื่อมต่อรถไฟฟ้ารางเดี่ยวสามารถพาไปส่วนต่างๆของนนทบุรีได้และต่อไปรถไฟฟ้าสายสีอื่นๆได้ "
|
||||
"รถไฟฟ้ารางเดี่ยวสีชมพู อ่างทอง-ป่าโมก-MRT แยกปากเกร็ด หรือ ทะเลสาบเมืองทองธานี หรือวัชรพล เชื่อมต่อรถไฟฟ้ารางเดี่ยว ส่งคนชอบดูงานอีเว้นชอบสามารถพาไปส่วนต่างๆของนนทบุรีได้และต่อไปรถไฟฟ้าสายสีอื่นๆได้ "
|
||||
]
|
||||
},
|
||||
"en": {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"date": "2026-10-05",
|
||||
"th": {
|
||||
"title": "กฎหมาย 4 หมวดรถประจำทาง กับทางออกของอ่างทอง",
|
||||
"tag": "ความฝัน",
|
||||
"body": [
|
||||
"ตามกฎหมายควบคุมการขนส่งทางบกแบ่งรถประจำทางออกเป็น 4 หมวด ได้แก่ 1.รถประจำทางในเขตเทศบาล 2.รถจากต่างจังหวัดเข้ากรุงเทพ 3.รถจากจังหวัดหนึ่งถึงอีกจังหวัดหนึ่ง 4.รถภายในจังหวัด",
|
||||
"กรมการขนส่งใช้ระบบให้นิติบุคคล พวก บริษัท ห้างหุ้นส่วน หรือสหกรณ์ใครสนใจก็เข้าไปของใบอนุญาต ซึ่งหลักการนี้ก็ใช้มาตั้งแต่ ปี 2520 กว่าๆ ถึงจะออกกฎระเบียบรองๆตามสภาพบ้านเมืองแต่ปัจจุบันเราก็เห็นสภาพกันอยู่ว่ามันแย่แค่ไหน",
|
||||
"อยากเสนอให้ องค์กรปกครองส่วนท้องถิ่นเข้ามาเดินรถ หมวด1 และหมวด4 ไม่ว่าจะดำเนินการเอง จ้างเหมาเอกชนหรือทำข้อตกลงสำรองจ่ายเฉพาะส่วนต่างที่เอกชน เราก็อาจจะเห็นบางจังหวัดเริ่มทำบ้างแล้ว แต่สำหรับอ่างทองจะเอาเงินจากไหนมาจัดบริการแบบนี้ ส่วนรถหมวด 2 และ 3 ถึงเราจะอยากให้อุดหนุนแต่มันก็เลยคำว่า บริการพื้นฐานไปแล้วก็คงได้แต่ส่งกำลังใจให้มีกำไรและจัดบริการดีๆ"
|
||||
]
|
||||
},
|
||||
"en": {
|
||||
"title": "The 4 bus categories — and a way forward for Ang Thong",
|
||||
"tag": "A dream",
|
||||
"body": [
|
||||
"Under the law governing land transport, buses are divided into 4 categories: (1) buses within a municipality, (2) buses from the provinces into Bangkok, (3) buses from one province to another, and (4) buses within a province.",
|
||||
"The Department of Land Transport works on a juristic-person system — companies, partnerships and cooperatives. Anyone interested applies for a licence. This principle has been in place since around 1977; the rules have been adjusted bit by bit to match the times, but today we can all see for ourselves just how bad things have become.",
|
||||
"I'd like to propose that local administrative organisations step in to run the category 1 and category 4 routes — whether by operating them themselves, contracting out to the private sector, or agreeing to subsidise only the shortfall, with the private operator covering the rest. A few provinces have started doing this already. But where would Ang Thong get the money to fund a service like this? As for categories 2 and 3, even if we'd like to subsidise them, they're already beyond what counts as a basic service — so all we can do is send our encouragement for them to stay profitable and keep running a good service."
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,9 @@
|
||||
background: linear-gradient(180deg, rgba(15, 23, 42, 0), rgba(15, 23, 42, .62));
|
||||
}
|
||||
/* --- แผนที่ "เส้นทางที่เสนอ" (ความฝัน) + รายการคลิกได้ + แผงรายละเอียด --- */
|
||||
.blog-mapx { margin: 0 0 16px; position: relative; }
|
||||
/* isolation:isolate — กัก z-index ของ Leaflet (400–1000) ไว้ในกรอบแผนที่
|
||||
ไม่ให้ปุ่มซูม/ป๊อปอัปทะลุขึ้นไปทับ nav (z-index 1100) */
|
||||
.blog-mapx { margin: 0 0 16px; position: relative; isolation: isolate; }
|
||||
/* ป้ายหมวดบนแผนที่ (มุมขวาบน — หลบปุ่มซูมของ Leaflet ที่มุมซ้ายบน) */
|
||||
.blog-mapx-tag {
|
||||
position: absolute; top: 12px; right: 12px; z-index: 500;
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
routeGroups: '../resource/data/route_groups.json',
|
||||
routes: '../resource/data/routes.json',
|
||||
routesMunicipal: '../resource/data/routes_municipal.json',
|
||||
schedules: '../resource/data/schedules.json'
|
||||
schedules: '../resource/data/schedules.json',
|
||||
affiliates: '../resource/data/affiliates.json',
|
||||
};
|
||||
|
||||
// จังหวัดเริ่มต้น (home province ของเว็บนี้) — ใช้เป็นค่า default ของ hero + ตัวเลือก
|
||||
@@ -146,6 +147,50 @@
|
||||
});
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
ไทล์พาร์ทเนอร์ (marquee) — สร้างจาก resource/data/affiliates.json
|
||||
· แก้รายชื่อ/รูป/ลิงก์ที่ไฟล์ JSON ไม่ต้องแตะโค้ด
|
||||
· affiliate_link ว่าง = ยังไม่มีลิงก์ → แสดงเป็นไทล์เฉย ๆ (ไม่เป็นลิงก์ กดไม่ได้)
|
||||
· โหลด JSON ไม่ได้/ว่าง → คงไทล์เดิมที่ฝังใน HTML (fallback ไม่ให้หน้าว่าง)
|
||||
============================================================ */
|
||||
function initSponsors() {
|
||||
var track = document.querySelector('.mu-marquee-track');
|
||||
if (!track) return Promise.resolve();
|
||||
|
||||
return fetchJSON(DATA_URL.affiliates).then(function (d) {
|
||||
var list = (d && d.partners) || [];
|
||||
var tiles = list.filter(function (p) { return p && p.in_footer_marquee && p.tile_image; });
|
||||
if (!tiles.length) return; /* ไม่มีข้อมูล → คงไทล์เดิม */
|
||||
|
||||
var frag = document.createDocumentFragment();
|
||||
tiles.forEach(function (p) {
|
||||
var link = String(p.affiliate_link || '').trim();
|
||||
/* มีลิงก์ = <a> · ยังไม่มี = <span> (กดไม่ได้ ไม่พาไปหน้าเปล่า) */
|
||||
var node = document.createElement(link ? 'a' : 'span');
|
||||
node.className = 'mu-marquee-tile';
|
||||
node.setAttribute('aria-label', p.brand || '');
|
||||
|
||||
var img = document.createElement('img');
|
||||
var src = '../' + String(p.tile_image).replace(/^\.?\//, '');
|
||||
img.src = (window.ImgURL && ImgURL.of) ? ImgURL.of(src) : src;
|
||||
img.alt = p.brand || '';
|
||||
img.decoding = 'async';
|
||||
node.appendChild(img);
|
||||
|
||||
if (link) {
|
||||
node.href = link;
|
||||
node.target = '_blank';
|
||||
node.rel = 'noopener sponsored'; /* ลิงก์ affiliate → ระบุ sponsored */
|
||||
} else {
|
||||
node.setAttribute('title', p.brand || '');
|
||||
}
|
||||
frag.appendChild(node);
|
||||
});
|
||||
track.innerHTML = '';
|
||||
track.appendChild(frag);
|
||||
});
|
||||
}
|
||||
|
||||
function initMarquee() {
|
||||
var track = document.querySelector('.mu-marquee-track');
|
||||
if (!track || track.dataset.cloned) return;
|
||||
@@ -401,6 +446,6 @@
|
||||
}
|
||||
|
||||
initHomeSelectors();
|
||||
initMarquee();
|
||||
initSponsors().then(initMarquee); /* เติมไทล์จาก JSON ก่อน แล้วค่อย clone (ไม่งั้นไทล์ที่เพิ่มจะไม่ถูก clone) */
|
||||
initShare();
|
||||
})();
|
||||
@@ -392,6 +392,11 @@
|
||||
/* === Modern image polish === */
|
||||
.mu-logo-img { width: 44px; height: 44px; border-radius: 12px; object-fit: cover; box-shadow: 0 4px 12px rgba(0,0,0,.12); }
|
||||
.mu-stop-hero-photo { width: 100%; height: 220px; object-fit: cover; border-radius: 16px; display: block; margin-bottom: 12px; box-shadow: 0 10px 24px rgba(63,43,94,.16); }
|
||||
/* รูปสำรอง (สถานียังไม่มีรูป) — เป็นไอคอนโปร่งใส จึงใช้ contain + พื้นอ่อน ไม่ให้ยืด/ตัด */
|
||||
.mu-stop-hero-photo.is-fallback {
|
||||
object-fit: contain; padding: 22px; box-sizing: border-box;
|
||||
background: #f7f4fd; box-shadow: none; border: 1px solid #e8e4f2;
|
||||
}
|
||||
.mu-nearby {
|
||||
background: #fff; border: 1px solid var(--mu-border); border-radius: 20px;
|
||||
padding: 18px; margin: 14px 0; box-shadow: 0 10px 24px rgba(63,43,94,.06);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
var DATA = '../resource/data/';
|
||||
var PHOTO_DIR = '../.image/stations/'; /* รูปสถานี: <station_id>.<jpg|jpeg|webp|png> (ไล่ลองนามสกุลให้) */
|
||||
var PHOTO_EXTS = ['jpg', 'jpeg', 'webp', 'png'];
|
||||
var PHOTO_FALLBACK = '../.image/stations/minibus-512x512.png'; /* รูปสำรองเมื่อสถานียังไม่มีรูป */
|
||||
|
||||
/* ประเภทป้าย → คีย์แปล + โทนสี */
|
||||
var TYPE_KEY = {
|
||||
@@ -89,6 +90,8 @@
|
||||
|
||||
/* ---------- รูปสถานี: .image/stations/<station_id>.jpg ----------
|
||||
เลือกตาม station_id ใน stations.json · ไฟล์หาย → ไม่แสดงช่องว่าง (hero ยืดเต็ม) */
|
||||
function bust(u) { return (window.ImgURL && ImgURL.of) ? ImgURL.of(u) : u; }
|
||||
|
||||
function findPhoto(station) {
|
||||
if (station.photo) return station.photo; /* ระบุพาธเองได้ใน stations.json (ทับค่าเริ่มต้น) */
|
||||
var n = station.__seq || 1; /* รูปเสริมของสถานีเดียวกัน: 2-2.jpg, 2-3.jpeg … */
|
||||
@@ -165,7 +168,12 @@
|
||||
img.hidden = true; /* ซ่อนไว้ก่อน — รอผลตรวจว่ามีไฟล์จริง */
|
||||
var cands = [].concat(photo || []).filter(Boolean); /* รองรับทั้งสตริงเดียวและรายการนามสกุล */
|
||||
(function tryNext(i) {
|
||||
if (i >= cands.length) return; /* ไม่มีไฟล์เลย → ไม่แสดงช่องว่าง */
|
||||
if (i >= cands.length) { /* ไม่มีรูปสถานี → ใช้รูปสำรอง ไม่ปล่อยช่องว่าง */
|
||||
img.classList.add('is-fallback');
|
||||
img.src = bust(PHOTO_FALLBACK);
|
||||
img.hidden = false;
|
||||
return;
|
||||
}
|
||||
var url = cands[i];
|
||||
fetch(url, { method: 'HEAD', cache: 'no-store' })
|
||||
.then(function (r) {
|
||||
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
/* popular.js — อัลกอริทึมนับ "สายที่เปิดดูบ่อย" สำหรับ footer (ฝั่งเบราว์เซอร์ ไม่มี backend)
|
||||
|
||||
กลไก
|
||||
• จับการเปิดดูสาย: Popular.hit(route_id) — เรียกจาก busDetail.init.js / stopDetail / รายการสาย
|
||||
• เก็บใน localStorage: { "102": [hits, lastTs], ... } (id → [จำนวนครั้ง, เวลาล่าสุด])
|
||||
• คะแนนไม่เฟ้อ: score = hits × 0.5 ^ (อายุวัน / HALF_LIFE) ← ครึ่งชีวิต 30 วัน
|
||||
สายที่ไม่มีคนเปิดนาน ๆ จะค่อย ๆ ตกลงเองโดยไม่ต้องลบข้อมูล
|
||||
• แสดง 4 อันดับใน footer · ไม่มีข้อมูลพอ → ใช้ DEFAULT_IDS (ของเดิม) เป็น fallback
|
||||
• ประหยัดพื้นที่: เก็บแค่ 2 ตัวเลข/สาย · ทิ้งข้อมูลที่ตายเกิน PRUNE_DAYS วัน
|
||||
|
||||
ไม่มี dependency — โหลดก่อน router.js (หลัง i18n.js เพื่อให้ข้อความถูกภาษา)
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var KEY = 'at_route_hits'; /* คีย์ใน localStorage */
|
||||
var HALF_LIFE = 30; /* วัน — คะแนนลดครึ่งเมื่อไม่ถูกเปิดนาน 30 วัน */
|
||||
var PRUNE_DAYS = 180; /* ทิ้งข้อมูลที่ไม่ถูกเปิดเกิน 180 วัน (กันบวม) */
|
||||
var TOP_N = 4; /* จำนวนที่แสดงใน footer */
|
||||
var DAY_MS = 86400000;
|
||||
|
||||
/* ค่าเริ่มต้น (ของเดิมใน footer) — ใช้เมื่อยังไม่มีข้อมูลจริง หรือมีไม่ครบ TOP_N */
|
||||
var DEFAULT_IDS = ['101', '902', '15', '464'];
|
||||
|
||||
function now() { return Date.now(); }
|
||||
|
||||
/* ── อ่าน/เขียน storage (ทน localStorage ใช้ไม่ได้ เช่น โหมดส่วนตัว) ── */
|
||||
function read() {
|
||||
try {
|
||||
var raw = localStorage.getItem(KEY);
|
||||
if (!raw) return {};
|
||||
var d = JSON.parse(raw);
|
||||
return (d && typeof d === 'object') ? d : {};
|
||||
} catch (e) { return {}; }
|
||||
}
|
||||
|
||||
function write(d) {
|
||||
try { localStorage.setItem(KEY, JSON.stringify(d)); } catch (e) { /* เงียบ */ }
|
||||
}
|
||||
|
||||
/* คะแนนของรายการเดียว: hits × 0.5^(อายุวัน/ครึ่งชีวิต) */
|
||||
function score(entry, ts) {
|
||||
if (!entry || !entry.length) return 0;
|
||||
var hits = Number(entry[0]) || 0;
|
||||
var last = Number(entry[1]) || 0;
|
||||
if (hits <= 0 || last <= 0) return 0;
|
||||
var ageDays = Math.max(0, (ts - last) / DAY_MS);
|
||||
return hits * Math.pow(0.5, ageDays / HALF_LIFE);
|
||||
}
|
||||
|
||||
/* ตัดข้อมูลที่ตายเกิน PRUNE_DAYS ทิ้ง (คืนค่า true ถ้ามีการแก้) */
|
||||
function prune(d, ts) {
|
||||
var cut = PRUNE_DAYS * DAY_MS;
|
||||
var changed = false;
|
||||
Object.keys(d).forEach(function (id) {
|
||||
var e = d[id];
|
||||
var last = (e && Number(e[1])) || 0;
|
||||
if (!last || (ts - last) > cut) { delete d[id]; changed = true; }
|
||||
});
|
||||
return changed;
|
||||
}
|
||||
|
||||
var Popular = {
|
||||
/* นับการเปิดดูสาย 1 ครั้ง */
|
||||
hit: function (routeId) {
|
||||
var id = String(routeId == null ? '' : routeId).trim();
|
||||
if (!id) return;
|
||||
var ts = now();
|
||||
var d = read();
|
||||
var e = d[id];
|
||||
d[id] = [(e && Number(e[0]) || 0) + 1, ts];
|
||||
prune(d, ts);
|
||||
write(d);
|
||||
},
|
||||
|
||||
/* อันดับ id เรียงจากคะแนนมาก→น้อย · ไม่มีข้อมูล → DEFAULT_IDS */
|
||||
ranked: function (n) {
|
||||
var ts = now();
|
||||
var d = read();
|
||||
if (prune(d, ts)) write(d);
|
||||
|
||||
var rows = Object.keys(d).map(function (id) {
|
||||
return { id: id, score: score(d[id], ts) };
|
||||
}).filter(function (r) { return r.score > 0; });
|
||||
|
||||
rows.sort(function (a, b) { return b.score - a.score || (a.id < b.id ? -1 : 1); });
|
||||
|
||||
var top = rows.slice(0, n || TOP_N).map(function (r) { return r.id; });
|
||||
/* เติมด้วยค่าเริ่มต้นถ้ายังไม่ครบ (ไม่ให้ footer ว่าง) */
|
||||
DEFAULT_IDS.forEach(function (id) {
|
||||
if (top.length < (n || TOP_N) && top.indexOf(id) < 0) top.push(id);
|
||||
});
|
||||
return top.slice(0, n || TOP_N);
|
||||
},
|
||||
|
||||
/* เรนเดอร์รายการใน footer (เรียกหลัง i18n พร้อม — ชื่อสายตามภาษา) */
|
||||
mount: function (ulId, routes) {
|
||||
var ul = document.getElementById(ulId || 'footer-popular-list');
|
||||
if (!ul || !routes || !routes.length) return false;
|
||||
|
||||
var byId = {};
|
||||
routes.forEach(function (r) { byId[String(r.route_id)] = r; });
|
||||
|
||||
var ids = Popular.ranked(TOP_N);
|
||||
ul.innerHTML = '';
|
||||
ids.forEach(function (id) {
|
||||
var r = byId[id];
|
||||
if (!r) return;
|
||||
var li = document.createElement('li');
|
||||
var a = document.createElement('a');
|
||||
a.href = '#/routes/' + id;
|
||||
a.textContent = 'สาย ' + id + (r.route_name_th ? ' · ' + r.route_name_th : '');
|
||||
li.appendChild(a);
|
||||
ul.appendChild(li);
|
||||
});
|
||||
return ul.children.length > 0;
|
||||
},
|
||||
|
||||
/* สำหรับทดสอบ/debug */
|
||||
_score: score,
|
||||
_key: KEY
|
||||
};
|
||||
|
||||
window.Popular = Popular;
|
||||
})();
|
||||
@@ -89,17 +89,40 @@
|
||||
});
|
||||
}
|
||||
|
||||
/* footer "สายที่เปิดดูบ่อย" — โหลด routes.json แล้วให้ Popular จัดอันดับ+วาด
|
||||
(เรียกทุกครั้งที่ render: ตามภาษา + อันดับล่าสุด · ถ้า Popular ไม่มี = ไม่ทำอะไร) */
|
||||
var popularCache = null;
|
||||
function mountPopular() {
|
||||
if (!window.Popular || !document.getElementById('footer-popular-list')) return;
|
||||
var paint = function (routes) { window.Popular.mount('footer-popular-list', routes); };
|
||||
if (popularCache) { paint(popularCache); return; }
|
||||
fetch('../resource/data/routes.json', { cache: 'no-store' })
|
||||
.then(function (r) { return r.ok ? r.json() : null; })
|
||||
.then(function (d) {
|
||||
popularCache = (d && d.routes) || [];
|
||||
if (popularCache.length) paint(popularCache);
|
||||
})
|
||||
.catch(function () { /* ไม่มีข้อมูล → คง li เดิมใน HTML */ });
|
||||
}
|
||||
|
||||
function render() {
|
||||
var route = parseHash();
|
||||
var view = VIEWS[route.name];
|
||||
if (!view) return;
|
||||
|
||||
/* นับว่าเปิดดูสายนี้ 1 ครั้ง — ต้องอยู่ก่อนเช็ค lastKey
|
||||
(เปิดสายเดิมซ้ำ เช่นออกไปหน้าแรกแล้วกลับมา ต้องนับเพิ่มด้วย) */
|
||||
if (window.Popular && route.params && route.params.routeId) {
|
||||
window.Popular.hit(route.params.routeId);
|
||||
}
|
||||
|
||||
var key = route.name + '|' + JSON.stringify(route.params) + '|' + JSON.stringify(route.query);
|
||||
if (key === lastKey) return; // hash เดิม — ไม่ render ซ้ำ
|
||||
lastKey = key;
|
||||
|
||||
window.__route = route; // ให้ script ใน partial อ่าน params ได้
|
||||
|
||||
|
||||
fetch(view.partial, { cache: 'no-store' })
|
||||
.then(function (res) {
|
||||
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||
@@ -116,6 +139,9 @@
|
||||
}
|
||||
document.title = 'Atroute — ' + view.title;
|
||||
window.scrollTo(0, 0);
|
||||
|
||||
/* footer "สายที่เปิดดูบ่อย" — เรนเดอร์ทุกครั้ง (ตามภาษา + อันดับล่าสุด) */
|
||||
mountPopular();
|
||||
})
|
||||
.catch(function () {
|
||||
viewEl.innerHTML =
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
- ขั้นตอนอัปเดต: ดู AGENTS.md หัวข้อ PWA
|
||||
============================================================ */
|
||||
|
||||
const VERSION = "2026.09.27.82"; // ← bump ทุกครั้งที่แก้ SW เอง
|
||||
const VERSION = "2026.09.27.94"; // ← bump ทุกครั้งที่แก้ SW เอง
|
||||
const CACHE = `at-transit-${VERSION}`;
|
||||
|
||||
const PRECACHE = [
|
||||
@@ -30,6 +30,8 @@ const PRECACHE = [
|
||||
"./locales/en.json",
|
||||
"./pwa.js",
|
||||
"./i18n.js",
|
||||
"./popular.js",
|
||||
"./visitors.js",
|
||||
"./router.js",
|
||||
"./partials/home.html",
|
||||
"./partials/home.init.js",
|
||||
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
/* visitors.js — นับผู้เข้าชมจริง (ฝั่งเบราว์เซอร์ ไม่มี backend) + รีเซ็ตด้วยรหัส
|
||||
|
||||
แนวคิด
|
||||
แสดงผล = ฐาน + จำนวนผู้เข้าชมจริง (unique)
|
||||
ฐานเริ่มต้น = 12,834 (แสดงเมื่อยังไม่เคยรีเซ็ต)
|
||||
รีเซ็ต (รหัส) = ล้างฐานทิ้งด้วย → เริ่มนับใหม่จาก 0
|
||||
|
||||
กันจำนวนเฟ้อ 3 ชั้น
|
||||
1. sessionStorage → 1 รอบการเข้าชม (เปิดแท็บใหม่) นับ 1 · กด F5 ไม่นับ
|
||||
2. localStorage → 1 ครั้ง/วัน/เครื่อง (วันเดียวกันนับครั้งเดียว)
|
||||
3. dayKey กำกับ → ล้าง session/incognito เปิดซ้ำวันเดิม = ไม่นับ (เพดาน/วัน)
|
||||
|
||||
ประหยัดพื้นที่
|
||||
เก็บแค่ {"v": <จำนวนจริง>, "d": <วัน YYYY-MM-DD>} ≈ 35 ไบต์ · ไม่เก็บ log/IP/UA
|
||||
|
||||
รีเซ็ต
|
||||
กดที่ตัวเลขผู้เข้าชม 5 ครั้งติด → เปิดช่องกรอกรหัส (ซ่อน ไม่มีปุ่มให้คนอื่นกด)
|
||||
รหัสตรวจแบบ SHA-256 (ไม่เก็บรหัสจริงในโค้ด — เปิด view-source ไม่เจอ)
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var KEY = 'at_visitors'; /* { v: จำนวนจริง, d: 'YYYY-MM-DD' } */
|
||||
var SESSION_KEY = 'at_visitors_seen';
|
||||
var BASE = 12834; /* ฐานตั้งต้น — รีเซ็ตแล้วกลับมาที่นี่ */
|
||||
var TAPS = 5; /* จำนวนครั้งที่ต้องกดตัวเลข */
|
||||
var TAP_WINDOW = 2000; /* ต้องกดรัวภายใน 2 วิต่อครั้ง */
|
||||
|
||||
/* SHA-256 ของรหัสรีเซ็ต — เก็บเฉพาะ hash (ไม่เก็บรหัสจริงในไฟล์นี้) */
|
||||
var PASS_HASH = '4f23cd6ac8e7da56b92974cd0cf146eee9d995208a6645ed17eba91813c1d323';
|
||||
|
||||
function today() {
|
||||
var d = new Date();
|
||||
var m = String(d.getMonth() + 1);
|
||||
var day = String(d.getDate());
|
||||
if (m.length < 2) m = '0' + m;
|
||||
if (day.length < 2) day = '0' + day;
|
||||
return d.getFullYear() + '-' + m + '-' + day;
|
||||
}
|
||||
|
||||
function read() {
|
||||
try {
|
||||
var raw = localStorage.getItem(KEY);
|
||||
var d = raw ? JSON.parse(raw) : null;
|
||||
if (!d || typeof d !== 'object') return { b: null, v: 0, d: '' };
|
||||
return {
|
||||
b: (d.b === undefined || d.b === null) ? null : Math.max(0, Number(d.b) || 0),
|
||||
v: Math.max(0, Number(d.v) || 0),
|
||||
d: String(d.d || '')
|
||||
};
|
||||
} catch (e) { return { b: null, v: 0, d: '' }; }
|
||||
}
|
||||
|
||||
function write(d) {
|
||||
try { localStorage.setItem(KEY, JSON.stringify(d)); } catch (e) { /* เงียบ */ }
|
||||
}
|
||||
|
||||
/* ตรวจว่ารอบการเข้าชมนี้ "ควรนับ" — ผ่านครบ 3 ชั้น */
|
||||
function shouldCount(store) {
|
||||
/* ชั้น 1: sessionStorage — รอบนี้เคยนับแล้ว? (F5 ไม่นับ) */
|
||||
var seen = null;
|
||||
try { seen = sessionStorage.getItem(SESSION_KEY); } catch (e) { /* เงียบ */ }
|
||||
if (seen) return false;
|
||||
|
||||
/* ชั้น 2+3: วันเดียวกันห้ามเพิ่ม (แม้ sessionStorage ถูกล้าง) */
|
||||
if (store.d === today()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function fmt(n) { return Number(n).toLocaleString('en-US'); }
|
||||
|
||||
/* ── รหัส: SHA-256 ผ่าน SubtleCrypto (มีในทุกเบราว์เซอร์สมัยใหม่) ── */
|
||||
function hash(text, cb) {
|
||||
if (window.crypto && crypto.subtle && crypto.subtle.digest) {
|
||||
crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))
|
||||
.then(function (buf) {
|
||||
var b = new Uint8Array(buf), s = '';
|
||||
for (var i = 0; i < b.length; i++) s += ('0' + b[i].toString(16)).slice(-2);
|
||||
cb(s);
|
||||
})
|
||||
.catch(function () { cb(null); });
|
||||
} else {
|
||||
cb(null); /* เบราว์เซอร์เก่า/ไม่มี https → กรุณาใช้ http://localhost */
|
||||
}
|
||||
}
|
||||
|
||||
/* เทียบแบบ constant-time (กัน timing attack) */
|
||||
function safeEqual(a, b) {
|
||||
if (typeof a !== 'string' || typeof b !== 'string' || a.length !== b.length) return false;
|
||||
var diff = 0;
|
||||
for (var i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
||||
return diff === 0;
|
||||
}
|
||||
|
||||
var Visitors = {
|
||||
BASE: BASE, /* ฐานตั้งต้น (ค่าคงที่) — ดู Visitors._base สำหรับฐานที่ใช้จริง */
|
||||
_base: BASE,
|
||||
|
||||
/* เรียกครั้งเดียวตอนโหลดหน้า — นับ (ถ้าควรนับ) แล้วคืนค่าที่จะแสดง */
|
||||
init: function () {
|
||||
var store = read();
|
||||
if (shouldCount(store)) {
|
||||
store.v = (Number(store.v) || 0) + 1;
|
||||
store.d = today();
|
||||
write(store);
|
||||
try { sessionStorage.setItem(SESSION_KEY, '1'); } catch (e) { /* เงียบ */ }
|
||||
}
|
||||
/* ฐาน: ยังไม่เคยรีเซ็ต → BASE · เคยรีเซ็ต → ค่าที่บันทึกไว้ (0) */
|
||||
var base = (store.b === null) ? BASE : store.b;
|
||||
var el = document.getElementById('visitor-count');
|
||||
if (el) el.textContent = fmt(base + store.v);
|
||||
Visitors._base = base;
|
||||
Visitors._store = store;
|
||||
return base + store.v;
|
||||
},
|
||||
|
||||
/* จำนวนจริง (ไม่รวม BASE) */
|
||||
actual: function () { return read().v; },
|
||||
|
||||
/* รีเซ็ต: ล้างฐานทิ้งด้วย → เริ่มนับใหม่จาก 0 (ตามที่เลือก) */
|
||||
reset: function () {
|
||||
write({ b: 0, v: 0, d: today() });
|
||||
/* ไม่ล้าง sessionStorage — กันการนับซ้ำทันทีหลังรีเซ็ตในรอบเดียวกัน */
|
||||
Visitors._base = 0;
|
||||
var el = document.getElementById('visitor-count');
|
||||
if (el) el.textContent = fmt(0);
|
||||
return 0;
|
||||
},
|
||||
|
||||
/* ตรวจรหัสแล้วรีเซ็ต (async — SHA-256) */
|
||||
resetWith: function (pass, done) {
|
||||
hash(String(pass == null ? '' : pass), function (h) {
|
||||
if (!h) { done(false, 'unsupported'); return; }
|
||||
if (!safeEqual(h, PASS_HASH)) { done(false, 'wrong'); return; }
|
||||
Visitors.reset();
|
||||
done(true, 'ok');
|
||||
});
|
||||
},
|
||||
|
||||
_hash: hash,
|
||||
_key: KEY
|
||||
};
|
||||
|
||||
window.Visitors = Visitors;
|
||||
|
||||
/* ── ช่องทางลับ: กดที่ตัวเลข 5 ครั้งติด → เปิดช่องกรอกรหัส ── */
|
||||
function mountTap() {
|
||||
var el = document.getElementById('visitor-count');
|
||||
if (!el) return;
|
||||
|
||||
var taps = 0, timer = null;
|
||||
el.style.cursor = 'pointer';
|
||||
el.addEventListener('click', function () {
|
||||
taps++;
|
||||
if (timer) clearTimeout(timer);
|
||||
timer = setTimeout(function () { taps = 0; }, TAP_WINDOW);
|
||||
if (taps >= TAPS) {
|
||||
taps = 0;
|
||||
clearTimeout(timer);
|
||||
openDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function openDialog() {
|
||||
if (document.querySelector('.mu-vreset')) return;
|
||||
|
||||
var wrap = document.createElement('div');
|
||||
wrap.className = 'mu-vreset';
|
||||
wrap.innerHTML =
|
||||
'<div class="mu-vreset-card" role="dialog" aria-modal="true" aria-labelledby="vreset-title">' +
|
||||
'<h4 id="vreset-title">รีเซ็ตจำนวนผู้เข้าชม</h4>' +
|
||||
'<label for="vreset-pass">รหัสรีเซ็ต</label>' +
|
||||
'<input id="vreset-pass" type="password" autocomplete="off" inputmode="text">' +
|
||||
'<p class="mu-vreset-msg" role="status"></p>' +
|
||||
'<div class="mu-vreset-row">' +
|
||||
'<button type="button" class="mu-vreset-cancel">ยกเลิก</button>' +
|
||||
'<button type="button" class="mu-vreset-ok">รีเซ็ต</button>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
|
||||
var input = wrap.querySelector('#vreset-pass');
|
||||
var msg = wrap.querySelector('.mu-vreset-msg');
|
||||
|
||||
function close() { wrap.remove(); }
|
||||
function submit() {
|
||||
msg.textContent = '';
|
||||
Visitors.resetWith(input.value, function (ok, why) {
|
||||
if (ok) {
|
||||
msg.className = 'mu-vreset-msg is-ok';
|
||||
msg.textContent = 'รีเซ็ตแล้ว — เริ่มนับใหม่จาก 0';
|
||||
input.value = '';
|
||||
setTimeout(close, 1200);
|
||||
} else if (why === 'unsupported') {
|
||||
msg.textContent = 'เบราว์เซอร์ไม่รองรับ — ต้องเปิดผ่าน https หรือ localhost';
|
||||
} else {
|
||||
msg.className = 'mu-vreset-msg is-bad';
|
||||
msg.textContent = 'รหัสไม่ถูกต้อง';
|
||||
input.value = '';
|
||||
input.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
wrap.querySelector('.mu-vreset-ok').addEventListener('click', submit);
|
||||
wrap.querySelector('.mu-vreset-cancel').addEventListener('click', close);
|
||||
wrap.addEventListener('click', function (e) { if (e.target === wrap) close(); });
|
||||
input.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Enter') submit();
|
||||
if (e.key === 'Escape') close();
|
||||
});
|
||||
|
||||
document.body.appendChild(wrap);
|
||||
input.focus();
|
||||
}
|
||||
|
||||
/* ── nับตอนโหลด + ติดช่องทางลับ ── */
|
||||
function boot() {
|
||||
Visitors.init();
|
||||
mountTap();
|
||||
}
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot);
|
||||
else boot();
|
||||
})();
|
||||
Reference in new issue
Block a user