Files
slump-x-land-studio/static/review-share.js
T

19 lines
853 B
JavaScript

for (const box of document.querySelectorAll('[data-share]')) {
const link = box.querySelector('input');
const share = box.querySelector('[data-share-button]');
const copy = box.querySelector('[data-copy-button]');
const status = box.querySelector('[data-share-status]');
if (navigator.share) {
share.hidden = false;
share.addEventListener('click', async () => {
try {await navigator.share({title: document.title, url: link.value});}
catch (error) {if (error.name !== 'AbortError') status.textContent = 'Use the link to share this review.';}
});
}
copy.hidden = false;
copy.addEventListener('click', async () => {
try {await navigator.clipboard.writeText(link.value); status.textContent = 'Review link copied.';}
catch {link.focus(); link.select(); status.textContent = 'Copy the selected link.';}
});
}