Web Share API というのがあるんだなあ、ということで付けてみた。ファイルもこれで共有できるみたい。知らなかった。
Firefox は未対応。あとmacOSの共有はあんまり意味ないので、SNSの共有ボタンをまるごと代替できるものではないようだ。
customElements.define('web-share-button', class extends HTMLElement {
connectedCallback() {
const title = this.getAttribute('title');
const url = this.getAttribute('url');
if (!navigator.share) {
this.style.display = 'none';
return;
}
// Web Share API 対応: ボタンを表示
const button = document.createElement('button');
button.className = 'share-button';
button.textContent = '共有';
button.addEventListener('click', async () => {
try {
await navigator.share({ title, url });
} catch (err) {
if (err.name !== 'AbortError') {
console.error('共有エラー:', err);
}
}
});
this.appendChild(button);
}
});
https://github.com/cho45/ticker-generator でも対応させてみた。
こんな感じ。Android の「共有」のペインの最上位、DMとかチャットとかが表示されて消せないのがひどい。このためだけにゲストモード設定が必要になる pic.twitter.com/cfmiz7I0Zj
— ショ糖 (@cho45) January 9, 2026
