diff --git a/ui/_shared.css b/ui/_shared.css index d83ce71..e8764a7 100644 --- a/ui/_shared.css +++ b/ui/_shared.css @@ -681,3 +681,66 @@ body:has(.mu-site-footer) .mu-footer { display: none; } .mu-loadbar { display: none; } } +/* ============================================================ + ปุ่ม "แชร์หน้านี้" — พอร์ตจาก web-at-transit (variant ghost) + ใช้ได้ทุกหน้า: ปุ่ม id="share-btn" + ข้อความ id="share-status" + ============================================================ */ +.mu-share-row { + display: flex; + flex-direction: column; + align-items: flex-end; + gap: 8px; + margin: 22px 0 44px; +} +.mu-share-btn { + display: inline-flex; + align-items: center; + justify-content: center; + gap: 6px; + min-height: 44px; + padding: 10px 18px; + border: 1px solid var(--c-border); + border-radius: var(--radius); + background: var(--c-surface); + color: var(--c-brand-ink); + font-family: inherit; + font-size: .85rem; + font-weight: 700; + line-height: 1; + cursor: pointer; + transition: border-color .15s ease, background .15s ease, transform .1s ease; +} +.mu-share-btn:hover { border-color: #d8c9f2; background: var(--c-surface-2); } +.mu-share-btn:active { transform: translateY(1px); } +.mu-share-btn:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; } +.mu-share-btn .ic { width: 16px; height: 16px; } +.mu-share-status { + margin: 0; + font-size: .85rem; + line-height: 1.7; + color: var(--c-ink-2); + text-align: right; +} +.mu-share-status:empty { display: none; } +.mu-share-url { + display: inline-block; + padding: 2px 8px; + border: 1px solid var(--c-border); + border-radius: 8px; + background: var(--c-surface-2); + font-family: ui-monospace, "IBM Plex Mono", monospace; + font-size: .8rem; +} +.mu-share-line { + display: inline-block; + margin-left: 6px; + font-weight: 700; + color: #06c755; + text-decoration: none; +} +.mu-share-line:hover { text-decoration: underline; } +@media (max-width: 560px) { + .mu-share-row { align-items: stretch; } + .mu-share-btn { justify-content: center; } + .mu-share-status { text-align: left; } +} diff --git a/ui/index.html b/ui/index.html index 4ed88da..38a7960 100644 --- a/ui/index.html +++ b/ui/index.html @@ -19,16 +19,16 @@
' + esc(url) + ' ' +
+ '' +
+ esc(t('share.line', 'แชร์ผ่าน LINE')) + '';
+ }
+
+ btn.addEventListener('click', function () {
+ var url = shortUrl();
+
+ if (navigator.share) {
+ navigator.share({ title: document.title, url: url }).catch(function () {});
+ }
+
+ if (navigator.clipboard && navigator.clipboard.writeText) {
+ navigator.clipboard.writeText(url).then(function () {
+ paint(t('share.copied', 'คัดลอกลิงก์แล้ว'));
+ }).catch(function () {
+ paint(t('share.short', 'ลิงก์สั้น'));
+ });
+ } else {
+ paint(t('share.short', 'ลิงก์สั้น'));
+ }
+ });
+ }
+
+ window.AtShareInit = bind;
+ bind();
+
+ /* router inject partial ใหม่ทุกครั้งที่เปลี่ยนหน้า → ผูกปุ่มให้เอง */
+ (function watch() {
+ var host = document.getElementById('view');
+ if (!host || !window.MutationObserver) return;
+ var queued = 0;
+ new MutationObserver(function (list) {
+ for (var i = 0; i < list.length; i++) {
+ if (list[i].addedNodes && list[i].addedNodes.length) {
+ if (queued) return;
+ queued = 1;
+ setTimeout(function () { queued = 0; bind(); }, 60);
+ return;
+ }
+ }
+ }).observe(host, { childList: true, subtree: true });
+ })();
+ window.addEventListener('langchange', function () {
+ var btn = document.getElementById('share-btn');
+ if (btn) delete btn.dataset.bound;
+ bind();
+ });
+})();
diff --git a/ui/sw.js b/ui/sw.js
index 5b04714..e15a72f 100644
--- a/ui/sw.js
+++ b/ui/sw.js
@@ -13,7 +13,7 @@
- ขั้นตอนอัปเดต: ดู AGENTS.md หัวข้อ PWA
============================================================ */
-const VERSION = "2026.09.27.123"; // ← bump ทุกครั้งที่แก้ SW เอง
+const VERSION = "2026.09.27.124"; // ← bump ทุกครั้งที่แก้ SW เอง
const CACHE = `at-transit-${VERSION}`;
const PRECACHE = [
@@ -33,6 +33,7 @@ const PRECACHE = [
"./popular.js",
"./analytics.js",
"./theme.js",
+ "./share.js",
"./theme.css",
"./router.js",
"./motion.js",
diff --git a/ui/version.json b/ui/version.json
index 203e69c..c6a5533 100644
--- a/ui/version.json
+++ b/ui/version.json
@@ -1 +1 @@
-{"version": "2026.09.27.123"}
+{"version": "2026.09.27.124"}