aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/components/ScheduleTable.astro
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/ScheduleTable.astro')
-rw-r--r--src/components/ScheduleTable.astro18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/components/ScheduleTable.astro b/src/components/ScheduleTable.astro
index 2ce073b..1e23000 100644
--- a/src/components/ScheduleTable.astro
+++ b/src/components/ScheduleTable.astro
@@ -61,7 +61,7 @@ const dateHtml = (html: string) =>
const KINDS: { kind: string; label: string }[] = [
{ kind: 'x', label: 'Xでシェア' },
- { kind: 'copy', label: '共有用の文面をコピー' },
+ { kind: 'share', label: '共有する' },
];
function attachButtons() {
@@ -125,7 +125,19 @@ const dateHtml = (html: string) =>
return;
}
- // コピー:Instagram・Facebookなど、文面を直接渡せないSNSにも貼れる
+ // 共有:端末の共有メニュー(Instagram・メール・メモなど)を開く。
+ // 非対応のブラウザでは、文面をコピーして貼り付けられるようにする。
+ const share = (navigator as Navigator & { share?: (data: ShareData) => Promise<void> })
+ .share;
+ if (share) {
+ try {
+ await share.call(navigator, { text, url });
+ } catch {
+ // キャンセルされた場合は何もしない
+ }
+ return;
+ }
+
try {
await navigator.clipboard.writeText(`${text}\n${url}`);
const original = button.title;
@@ -138,7 +150,7 @@ const dateHtml = (html: string) =>
button.setAttribute('aria-label', original);
}, 1500);
} catch {
- window.alert('このブラウザではコピーできませんでした。文面を選択してコピーしてください。');
+ window.alert('このブラウザでは共有メニューもコピーも使えません。文面を選択してコピーしてください。');
}
});