analytics: privacy-first search stats (Umami-style), #/stats page
- ui/analytics.js: cookie-less local-first tracker (localStorage), DNT/GPC honoured, opt-out switch, term sanitiser (email/@handle/long digits stripped), 900ms debounce, caps 300 terms / 200 views / 120 days - optional Umami-compatible beacon (window.AT_ANALYTICS endpoint+siteId), disabled by default: no third-party requests unless the owner configures it - #/stats view: KPIs, 14-day CSS bar chart, top terms, top route/stop pages, no-result terms, privacy panel, JSON export, clear, opt-out - hooks: busStop search apply(), stopDetail route filter, hashchange pageviews - i18n th/en (395 keys each), credits section, sw.js precache + VERSION 2026.09.27.105
This commit is contained in:
1 parent
5381e0690a
commit
2504c39305
11 files changed
+850
-13
No files matched your search
@@ -159,6 +159,15 @@
|
||||
var searching = !!f.value;
|
||||
var limit = (searching || state.showAll) ? filtered.length : PREVIEW_LIMIT;
|
||||
|
||||
/* สถิติคำค้น (เฉพาะตอนมีคำจริง · Analytics ทำ debounce 900ms ให้เอง) */
|
||||
if (searching && window.Analytics) {
|
||||
window.Analytics.search({
|
||||
q: f.value,
|
||||
scope: state.mode === MODE_CODE ? 'code' : 'place',
|
||||
results: filtered.length
|
||||
});
|
||||
}
|
||||
|
||||
var cards = [].filter.call(host.children, function (el) { return el.tagName === 'LI' && el.hasAttribute('data-idx'); });
|
||||
var shown = 0;
|
||||
Array.prototype.forEach.call(cards, function (li) {
|
||||
|
||||
@@ -72,5 +72,14 @@
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="mu-credit-section">
|
||||
<h2><span data-i18n="credits.analyticsTitle">สถิติ — แนวคิดจาก Umami</span></h2>
|
||||
<p class="src"><span data-i18n="credits.src">แหล่งที่มา:</span> <a href="https://github.com/umami-software/umami" rel="noopener">github.com/umami-software/umami</a> · <span data-i18n="credits.lic">ใบอนุญาต:</span> <a href="https://github.com/umami-software/umami/blob/master/LICENSE" rel="noopener">MIT License</a></p>
|
||||
<ul>
|
||||
<li><span data-i18n="credits.analyticsBody">ระบบสถิติของเว็บนี้เขียนเองใน</span> <code>ui/analytics.js</code> <span data-i18n="credits.analyticsBody2">(ไม่มี dependency) — ยืมเฉพาะแนวคิด privacy-first และรูปแบบ payload ของ Umami (/api/send) ไม่ได้คัดลอกโค้ดของ Umami มาใช้</span></li>
|
||||
<li data-i18n="credits.analyticsLocal">ข้อมูลสถิติเก็บในเบราว์เซอร์ของผู้ใช้เท่านั้น (localStorage) — ดู/ล้างได้ที่หน้า “สถิติ”</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
@@ -0,0 +1,153 @@
|
||||
<style>
|
||||
.mu-page { background: linear-gradient(180deg, #fcfbff 0%, #f5f9ff 100%); }
|
||||
.st-wrap { max-width: 62rem; margin: 0 auto; padding: 32px 20px 64px; }
|
||||
.st-hero { margin-bottom: 22px; }
|
||||
.st-hero h1 { margin: 0 0 8px; font-size: clamp(1.5rem, 1.2rem + 1.4vw, 1.9rem); color: #1f2a44; letter-spacing: -.01em; }
|
||||
.st-hero p { margin: 0; color: #66728f; font-size: .92rem; line-height: 1.65; max-width: 62ch; }
|
||||
|
||||
.st-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
|
||||
.st-kpi { background: #fff; border: 1px solid #e7e0f6; border-radius: 14px; padding: 14px 16px; min-width: 0; }
|
||||
.st-kpi b { display: block; font-size: 1.55rem; line-height: 1.2; color: #1f2a44; font-variant-numeric: tabular-nums; }
|
||||
.st-kpi span { display: block; margin-top: 4px; font-size: .76rem; font-weight: 700; color: #6f7b95; letter-spacing: .01em; }
|
||||
|
||||
.st-card { background: #fff; border: 1px solid #e7e0f6; border-radius: 16px; padding: 18px 20px; margin-top: 16px; }
|
||||
.st-card h2 { margin: 0 0 4px; font-size: 1rem; color: #1f2a44; }
|
||||
.st-card .lead { margin: 0 0 14px; color: #6f7b95; font-size: .84rem; line-height: 1.6; }
|
||||
.st-grid2 { display: grid; gap: 16px; margin-top: 16px; }
|
||||
.st-grid2 > .st-card { margin-top: 0; }
|
||||
|
||||
/* กราฟแท่ง 14 วัน — CSS ล้วน ไม่มีไลบรารี */
|
||||
.st-chart { display: flex; align-items: flex-end; gap: 5px; height: 128px; padding-top: 10px; }
|
||||
.st-bar { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; }
|
||||
.st-bar i, .st-bar u { display: block; border-radius: 4px 4px 0 0; min-height: 2px; }
|
||||
.st-bar i { background: linear-gradient(180deg, #b694f6, #7a4cc0); }
|
||||
.st-bar u { background: #e9dffb; }
|
||||
.st-bar em { font-style: normal; font-size: .6rem; color: #8a93a8; text-align: center; margin-top: 4px; white-space: nowrap; }
|
||||
.st-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; font-size: .76rem; color: #6f7b95; }
|
||||
.st-legend b { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
|
||||
|
||||
.st-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
|
||||
.st-table th { text-align: left; padding: 0 8px 6px 0; font-size: .7rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #8a93a8; border-bottom: 1px solid #efe9fb; }
|
||||
.st-table td { padding: 8px 8px 8px 0; border-bottom: 1px solid #f5f1fc; color: #3a4462; vertical-align: top; }
|
||||
.st-table tr:last-child td { border-bottom: 0; }
|
||||
.st-table .num { width: 3.5rem; text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; color: #1f2a44; }
|
||||
.st-table .when { color: #8a93a8; font-size: .74rem; white-space: nowrap; }
|
||||
.st-table .term { font-weight: 700; color: #1f2a44; word-break: break-word; }
|
||||
.st-table a { color: #7a4cc0; text-decoration: none; font-weight: 600; }
|
||||
.st-table a:hover { text-decoration: underline; }
|
||||
|
||||
.st-empty { margin: 0; padding: 14px 0 4px; color: #8a93a8; font-size: .86rem; }
|
||||
|
||||
.st-list { margin: 0 0 14px; padding-left: 1.15rem; color: #3a4462; font-size: .88rem; line-height: 1.75; }
|
||||
.st-toggle { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid #e7e0f6; border-radius: 12px; background: #fbf9ff; font-size: .88rem; color: #3a4462; cursor: pointer; }
|
||||
.st-toggle input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: #7a4cc0; flex: none; }
|
||||
.st-toggle strong { display: block; color: #1f2a44; font-size: .9rem; margin-bottom: 2px; }
|
||||
.st-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
|
||||
.st-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 9px 16px; border-radius: 10px; border: 1px solid #ddcff5; background: #fff; color: #7a4cc0; font: inherit; font-size: .86rem; font-weight: 700; cursor: pointer; }
|
||||
.st-btn:hover { background: #f7f2ff; }
|
||||
.st-btn.is-solid { background: #7a4cc0; border-color: #7a4cc0; color: #fff; }
|
||||
.st-btn.is-solid:hover { background: #6a3fb0; }
|
||||
.st-btn.is-danger { border-color: #f0c9c9; color: #b3261e; }
|
||||
.st-btn.is-danger:hover { background: #fdf3f3; }
|
||||
.st-note { margin: 12px 0 0; font-size: .78rem; color: #8a93a8; }
|
||||
.st-status { margin: 10px 0 0; min-height: 18px; font-size: .82rem; color: #1f7a3d; }
|
||||
|
||||
@media (min-width: 520px) { .st-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
|
||||
@media (min-width: 768px) { .st-grid2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .st-wrap { padding: 40px 28px 72px; } }
|
||||
</style>
|
||||
|
||||
<main class="mu-page">
|
||||
<div class="st-wrap">
|
||||
<div class="st-hero">
|
||||
<p class="mu-breadcrumb"><a href="#/" data-i18n="credits.breadHome">หน้าแรก</a>/ <span data-i18n="nav.stats">สถิติ</span></p>
|
||||
<h1 data-i18n="stats.title">สถิติการค้นหาในเครื่องนี้</h1>
|
||||
<p data-i18n="stats.lead">เก็บเฉพาะจำนวนครั้งและคำที่ค้น — ไม่มีคุกกี้ ไม่มีรหัสผู้ใช้ ไม่เก็บ IP และไม่ส่งออกนอกเครื่อง เว้นแต่เจ้าของเว็บจะตั้งค่าเชื่อม Umami เอง</p>
|
||||
</div>
|
||||
|
||||
<section class="st-kpis" aria-label="สรุปตัวเลข">
|
||||
<div class="st-kpi"><b id="st-kpi-views">0</b><span data-i18n="stats.kpi.views">ครั้งที่เปิดหน้า</span></div>
|
||||
<div class="st-kpi"><b id="st-kpi-searches">0</b><span data-i18n="stats.kpi.searches">ครั้งที่ค้นหา</span></div>
|
||||
<div class="st-kpi"><b id="st-kpi-terms">0</b><span data-i18n="stats.kpi.terms">คำค้นต่างกัน</span></div>
|
||||
<div class="st-kpi"><b id="st-kpi-nores">0</b><span data-i18n="stats.kpi.noResult">ค้นแล้วไม่พบ</span></div>
|
||||
</section>
|
||||
|
||||
<section class="st-card">
|
||||
<h2 data-i18n="stats.chart.title">14 วันล่าสุด</h2>
|
||||
<p class="lead" data-i18n="stats.chart.lead">แท่งเข้ม = เปิดหน้า · แท่งอ่อน = ค้นหา</p>
|
||||
<div class="st-chart" id="st-chart" role="img" aria-label="กราฟ 14 วันล่าสุด"></div>
|
||||
<div class="st-legend">
|
||||
<span><b style="background:linear-gradient(180deg,#b694f6,#7a4cc0)"></b><span data-i18n="stats.kpi.views">ครั้งที่เปิดหน้า</span></span>
|
||||
<span><b style="background:#e9dffb"></b><span data-i18n="stats.kpi.searches">ครั้งที่ค้นหา</span></span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="st-grid2">
|
||||
<section class="st-card">
|
||||
<h2 data-i18n="stats.terms.title">คำที่ค้นมากที่สุด</h2>
|
||||
<p class="lead" data-i18n="stats.terms.lead">คำถูกทำให้ปลอดภัยแล้ว — ตัดอีเมล เบอร์โทร และเลขยาวออกก่อนบันทึก</p>
|
||||
<table class="st-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-i18n="stats.col.term">คำค้น</th>
|
||||
<th class="num" data-i18n="stats.col.count">ครั้ง</th>
|
||||
<th data-i18n="stats.col.last">ล่าสุด</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="st-terms"></tbody>
|
||||
</table>
|
||||
<p class="st-empty" id="st-terms-empty" hidden data-i18n="stats.terms.empty">ยังไม่มีคำค้นในเครื่องนี้ — ลองค้นหาป้ายที่หน้า “ป้ายหยุดรถ” แล้วกลับมาดู</p>
|
||||
</section>
|
||||
|
||||
<section class="st-card">
|
||||
<h2 data-i18n="stats.views.title">หน้าที่ถูกเปิดบ่อย</h2>
|
||||
<p class="lead" data-i18n="stats.views.lead">นับเฉพาะรายละเอียดสายรถและรายละเอียดป้าย (ไม่ผูกกับผู้ใช้)</p>
|
||||
<table class="st-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-i18n="stats.col.target">หน้า</th>
|
||||
<th class="num" data-i18n="stats.col.count">ครั้ง</th>
|
||||
<th data-i18n="stats.col.last">ล่าสุด</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="st-views"></tbody>
|
||||
</table>
|
||||
<p class="st-empty" id="st-views-empty" hidden data-i18n="stats.views.empty">ยังไม่มีข้อมูล — เปิดรายละเอียดสายหรือป้ายสักครั้ง</p>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="st-card" id="st-nores-card" hidden>
|
||||
<h2 data-i18n="stats.noresult.title">ค้นแล้วไม่พบ</h2>
|
||||
<p class="lead" data-i18n="stats.noresult.lead">สัญญาณว่าข้อมูลยังขาด — คำเหล่านี้ควรมีในระบบถ้าเป็นเส้นทางจริง</p>
|
||||
<table class="st-table">
|
||||
<thead>
|
||||
<tr><th data-i18n="stats.col.term">คำค้น</th><th class="num" data-i18n="stats.col.count">ครั้ง</th><th data-i18n="stats.col.last">ล่าสุด</th></tr>
|
||||
</thead>
|
||||
<tbody id="st-nores"></tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section class="st-card">
|
||||
<h2 data-i18n="stats.privacy.title">ความเป็นส่วนตัว</h2>
|
||||
<ul class="st-list">
|
||||
<li data-i18n="stats.privacy.collect">เก็บ: จำนวนเปิดหน้า · คำที่ค้น (ตัดข้อมูลส่วนตัวออก) · จำนวนครั้งที่ค้นไม่พบ · เวลาล่าสุด</li>
|
||||
<li data-i18n="stats.privacy.reject">ไม่เก็บ: IP · User-Agent · ตำแหน่ง · คุกกี้ · รหัสเครื่อง · ประวัติข้ามเว็บ</li>
|
||||
<li data-i18n="stats.privacy.local">ข้อมูลอยู่ใน localStorage ของเบราว์เซอร์นี้เท่านั้น — ล้างได้ทุกเมื่อ</li>
|
||||
</ul>
|
||||
<label class="st-toggle" for="st-optout">
|
||||
<input type="checkbox" id="st-optout">
|
||||
<span>
|
||||
<strong data-i18n="stats.privacy.optoutTitle">ปิดการเก็บสถิติในเครื่องนี้</strong>
|
||||
<span data-i18n="stats.privacy.optoutLead">เปิดสวิตช์นี้ = หยุดบันทึกทันที (ยังดูตัวเลขเดิมได้) · ระบบเคารพ Do Not Track / GPC อยู่แล้ว</span>
|
||||
</span>
|
||||
</label>
|
||||
<div class="st-actions">
|
||||
<button type="button" class="st-btn is-solid" id="st-export" data-i18n="stats.btn.export">ดาวน์โหลดข้อมูล (JSON)</button>
|
||||
<button type="button" class="st-btn is-danger" id="st-clear" data-i18n="stats.btn.clear">ล้างข้อมูลในเครื่อง</button>
|
||||
</div>
|
||||
<p class="st-status" id="st-status" role="status" aria-live="polite"></p>
|
||||
<p class="st-note"><span data-i18n="stats.since">เริ่มเก็บเมื่อ</span>: <span id="st-since">—</span></p>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script src="./partials/stats.init.js"></script>
|
||||
@@ -0,0 +1,238 @@
|
||||
/* stats.init.js — หน้า #/stats : อ่านรายงานจาก Analytics แล้ววาด (ไม่มีการยิงเน็ต) */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var $ = function (id) { return document.getElementById(id); };
|
||||
var A = window.Analytics;
|
||||
if (!A) {
|
||||
var host = document.querySelector('.st-wrap');
|
||||
if (host) host.innerHTML = '<p class="st-empty">analytics.js ยังไม่ถูกโหลด</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
function t(key, vars) {
|
||||
return window.I18N ? window.I18N.t(key, vars) : key;
|
||||
}
|
||||
|
||||
function num(n) {
|
||||
try { return (Number(n) || 0).toLocaleString('th-TH'); } catch (e) { return String(n || 0); }
|
||||
}
|
||||
|
||||
function when(ts) {
|
||||
if (!ts) return '—';
|
||||
var d = new Date(ts);
|
||||
var p = function (v) { return ('0' + v).slice(-2); };
|
||||
var now = new Date();
|
||||
var sameDay = d.toDateString() === now.toDateString();
|
||||
var hm = p(d.getHours()) + ':' + p(d.getMinutes());
|
||||
return sameDay ? hm : (p(d.getDate()) + '/' + p(d.getMonth() + 1) + ' ' + hm);
|
||||
}
|
||||
|
||||
function short(s, n) {
|
||||
s = String(s || '');
|
||||
return s.length > n ? s.slice(0, n - 1) + '…' : s;
|
||||
}
|
||||
|
||||
/* ---------- KPI ---------- */
|
||||
function renderKpis(r) {
|
||||
$('st-kpi-views').textContent = num(r.totals.pageviews);
|
||||
$('st-kpi-searches').textContent = num(r.totals.searches);
|
||||
$('st-kpi-terms').textContent = num(r.totals.terms);
|
||||
$('st-kpi-nores').textContent = num(r.totals.noResult);
|
||||
$('st-since').textContent = r.since ? new Date(r.since).toLocaleDateString('th-TH', { year: 'numeric', month: 'short', day: 'numeric' }) : '—';
|
||||
}
|
||||
|
||||
/* ---------- กราฟ 14 วัน ---------- */
|
||||
function renderChart(r) {
|
||||
var host = $('st-chart');
|
||||
if (!host) return;
|
||||
host.innerHTML = '';
|
||||
|
||||
/* เติมวันที่ขาดให้ครบ 14 วัน (วันไหนไม่มีข้อมูล = 0) */
|
||||
var byDate = {};
|
||||
r.days.forEach(function (d) { byDate[d.date] = d; });
|
||||
var series = [];
|
||||
var today = new Date();
|
||||
today.setHours(12, 0, 0, 0);
|
||||
for (var i = 13; i >= 0; i--) {
|
||||
var d = new Date(today.getTime() - i * 86400000);
|
||||
var k = d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2);
|
||||
series.push({ date: k, day: d.getDate(), pv: (byDate[k] && byDate[k].pageviews) || 0, q: (byDate[k] && byDate[k].searches) || 0 });
|
||||
}
|
||||
|
||||
var max = 1;
|
||||
series.forEach(function (s) { max = Math.max(max, s.pv, s.q); });
|
||||
|
||||
series.forEach(function (s, idx) {
|
||||
var col = document.createElement('div');
|
||||
col.className = 'st-bar';
|
||||
col.title = s.date + ' · ' + num(s.pv) + ' / ' + num(s.q);
|
||||
|
||||
var pv = document.createElement('i');
|
||||
pv.style.height = Math.round((s.pv / max) * 92) + 'px';
|
||||
var q = document.createElement('u');
|
||||
q.style.height = Math.round((s.q / max) * 92) + 'px';
|
||||
|
||||
var lab = document.createElement('em');
|
||||
lab.textContent = s.day;
|
||||
if (idx % 2 === 1 && series.length > 8) lab.style.opacity = '0'; /* เว้นวรรคให้อ่านง่ายบนมือถือ */
|
||||
|
||||
col.appendChild(pv);
|
||||
col.appendChild(q);
|
||||
col.appendChild(lab);
|
||||
host.appendChild(col);
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- ตารางคำค้น / หน้า ---------- */
|
||||
function emptyRow(tbody, colSpan, text) {
|
||||
tbody.innerHTML = '';
|
||||
var tr = document.createElement('tr');
|
||||
var td = document.createElement('td');
|
||||
td.colSpan = colSpan;
|
||||
td.className = 'st-empty';
|
||||
td.textContent = text;
|
||||
tr.appendChild(td);
|
||||
tbody.appendChild(tr);
|
||||
}
|
||||
|
||||
function renderTerms(r) {
|
||||
var body = $('st-terms');
|
||||
var empty = $('st-terms-empty');
|
||||
body.innerHTML = '';
|
||||
if (!r.topTerms.length) { empty.hidden = false; return; }
|
||||
empty.hidden = true;
|
||||
|
||||
r.topTerms.forEach(function (row) {
|
||||
var tr = document.createElement('tr');
|
||||
var td1 = document.createElement('td');
|
||||
td1.className = 'term';
|
||||
td1.textContent = short(row.term, 42);
|
||||
td1.title = row.term;
|
||||
|
||||
var td2 = document.createElement('td');
|
||||
td2.className = 'num';
|
||||
td2.textContent = num(row.count);
|
||||
|
||||
var td3 = document.createElement('td');
|
||||
td3.className = 'when';
|
||||
td3.textContent = when(row.last);
|
||||
|
||||
tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3);
|
||||
body.appendChild(tr);
|
||||
});
|
||||
}
|
||||
|
||||
function renderViews(r) {
|
||||
var body = $('st-views');
|
||||
var empty = $('st-views-empty');
|
||||
body.innerHTML = '';
|
||||
if (!r.topViews.length) { empty.hidden = false; return; }
|
||||
empty.hidden = true;
|
||||
|
||||
r.topViews.forEach(function (row) {
|
||||
var tr = document.createElement('tr');
|
||||
|
||||
var td1 = document.createElement('td');
|
||||
var a = document.createElement('a');
|
||||
a.href = row.kind === 'route' ? ('#/routes/' + encodeURIComponent(row.id)) : ('#/stops/' + encodeURIComponent(row.id));
|
||||
a.textContent = row.kind === 'route'
|
||||
? t('common.routePrefix', { n: row.id })
|
||||
: t('stats.views.stopPrefix', { code: row.id });
|
||||
td1.appendChild(a);
|
||||
|
||||
var td2 = document.createElement('td');
|
||||
td2.className = 'num';
|
||||
td2.textContent = num(row.count);
|
||||
|
||||
var td3 = document.createElement('td');
|
||||
td3.className = 'when';
|
||||
td3.textContent = when(row.last);
|
||||
|
||||
tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3);
|
||||
body.appendChild(tr);
|
||||
});
|
||||
}
|
||||
|
||||
function renderNoResult(r) {
|
||||
var card = $('st-nores-card');
|
||||
if (!card) return;
|
||||
if (!r.topEmpty.length) { card.hidden = true; return; }
|
||||
card.hidden = false;
|
||||
var body = $('st-nores');
|
||||
body.innerHTML = '';
|
||||
r.topEmpty.forEach(function (row) {
|
||||
var tr = document.createElement('tr');
|
||||
var td1 = document.createElement('td');
|
||||
td1.className = 'term';
|
||||
td1.textContent = short(row.term, 42);
|
||||
td1.title = row.term;
|
||||
var td2 = document.createElement('td');
|
||||
td2.className = 'num';
|
||||
td2.textContent = num(row.count);
|
||||
var td3 = document.createElement('td');
|
||||
td3.className = 'when';
|
||||
td3.textContent = when(row.last);
|
||||
tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3);
|
||||
body.appendChild(tr);
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- สวิตช์ / ปุ่ม ---------- */
|
||||
function status(msg) {
|
||||
var el = $('st-status');
|
||||
if (el) el.textContent = msg || '';
|
||||
}
|
||||
|
||||
function wire() {
|
||||
var opt = $('st-optout');
|
||||
if (opt) {
|
||||
opt.checked = !A.tracking();
|
||||
opt.addEventListener('change', function () {
|
||||
A.optOut(opt.checked);
|
||||
status(opt.checked ? t('stats.privacy.off') : t('stats.privacy.on'));
|
||||
});
|
||||
}
|
||||
|
||||
var exp = $('st-export');
|
||||
if (exp) {
|
||||
exp.addEventListener('click', function () {
|
||||
var d = new Date();
|
||||
var name = 'atroute-stats-' + d.getFullYear() + ('0' + (d.getMonth() + 1)).slice(-2) + ('0' + d.getDate()).slice(-2) + '.json';
|
||||
var blob = new Blob([A.exportJSON()], { type: 'application/json' });
|
||||
var url = URL.createObjectURL(blob);
|
||||
var a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = name;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
setTimeout(function () { URL.revokeObjectURL(url); }, 1500);
|
||||
status(t('stats.export.done'));
|
||||
});
|
||||
}
|
||||
|
||||
var clr = $('st-clear');
|
||||
if (clr) {
|
||||
clr.addEventListener('click', function () {
|
||||
if (!window.confirm(t('stats.clear.confirm'))) return;
|
||||
A.clear();
|
||||
render();
|
||||
status(t('stats.clear.done'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- วาดทั้งหมด ---------- */
|
||||
function render() {
|
||||
var r = A.report();
|
||||
renderKpis(r);
|
||||
renderChart(r);
|
||||
renderTerms(r);
|
||||
renderViews(r);
|
||||
renderNoResult(r);
|
||||
}
|
||||
|
||||
render();
|
||||
wire();
|
||||
})();
|
||||
@@ -333,6 +333,11 @@
|
||||
if (ok) shown++;
|
||||
});
|
||||
setCount(shown, items.length);
|
||||
|
||||
/* สถิติคำค้นในหน้ารายละเอียดป้าย (debounce อยู่ใน Analytics) */
|
||||
if (kw.length >= 2 && window.Analytics) {
|
||||
window.Analytics.search({ q: kw, scope: 'stop', results: shown });
|
||||
}
|
||||
}
|
||||
function setupFilter() {
|
||||
var input = $('mu-route-filter');
|
||||
|
||||
Reference in new issue
Block a user