Share button via the Web Share API

Apple offers no content-accepting Notes URL scheme; the native share
sheet is the real path — Notes, Messages, Mail, one tap. Button only
appears where navigator.share exists (Safari, iOS, Android).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-07 13:37:21 -04:00
parent 5c87d827e6
commit 7ff10af066
+15
View File
@@ -291,6 +291,7 @@ Double-click any word to look it up on the right."></textarea>
<button class="btn primary" id="copyBtn">Copy to clipboard</button>
<button class="btn" id="exportBtn" title="Download this draft as a color-coded PNG">Save PNG</button>
<button class="btn" id="downloadBtn" title="Download this draft as a plain text file">Save TXT</button>
<button class="btn" id="shareBtn" title="Share via the system sheet — Notes, Messages, anywhere" hidden>Share</button>
<label class="mtoggle" title="Color-code rhyme families"><input type="checkbox" id="rhymeToggle" checked> rhyme</label>
<label class="mtoggle" title="Underline words that share an initial sound"><input type="checkbox" id="allitToggle"> alliteration</label>
<label class="mtoggle" title="Sheet music for your flow — syllable emphasis dots under each word"><input type="checkbox" id="stressToggle"> rhythm</label>
@@ -1134,6 +1135,20 @@ function draftFilename(){
return (((doc && doc.title && doc.title !== 'Untitled') ? doc.title : 'rhymepad')
.replace(/[^\w\- ]+/g, '').trim() || 'rhymepad') + '.txt';
}
const shareBtn = document.getElementById('shareBtn');
if(navigator.share){
shareBtn.hidden = false;
shareBtn.addEventListener('click', async ()=>{
if(!editor.value.trim()) return;
const doc = docsState.docs.find(d=>d.id===docsState.current);
try{
await navigator.share({
title: (doc && doc.title !== 'Untitled') ? doc.title : 'RhymePad draft',
text: editor.value,
});
}catch(e){ /* user closed the sheet */ }
});
}
document.getElementById('downloadBtn').addEventListener('click', ()=>{
if(!editor.value.trim()) return;
const a = document.createElement('a');