Spaces:
Running

uas-eus-webhook / shared /js /share.js
uas-deploy
deploy 2026-12-02T15:07:30Z
03c9ca7
Raw History Blame Contribute Delete
2.35 kB
/* Share buttons β€” zero external scripts, just share URLs + navigator.share + clipboard.
Mount into any container: <div class="share" data-share></div> */
(function () {
function enc(s) { return encodeURIComponent(s); }
window.Share = {
mountAll() {
document.querySelectorAll('[data-share]').forEach(function (el) {
var url = location.href, title = document.title;
var text = (window.I18N && I18N.t('share.title')) || 'Share';
var items = [];
if (navigator.share) items.push({ label: 'β†— ' + text, fn: function () { navigator.share({ title: title, url: url }).catch(function () {}); } });
items.push({ label: '𝕏', url: 'https://twitter.com/intent/tweet?url=' + enc(url) + '&text=' + enc(title) });
items.push({ label: 'in', url: 'https://www.linkedin.com/sharing/share-offsite/?url=' + enc(url) });
items.push({ label: '✈ telegram', url: 'https://t.me/share/url?url=' + enc(url) + '&text=' + enc(title) });
items.push({ label: 'βœ† whatsapp', url: 'https://wa.me/?text=' + enc(title + ' ' + url) });
items.push({ label: '🐘 mastodon', url: 'https://mastodon.social/share?text=' + enc(title + ' ' + url) });
items.push({ label: 'βœ‰ email', url: 'mailto:?subject=' + enc(title) + '&body=' + enc(url) });
items.push({ label: 'πŸ”—', fn: function () {
(navigator.clipboard ? navigator.clipboard.writeText(url) : Promise.reject()).then(function () {
el.querySelector('[data-copy]').textContent = 'βœ“';
}).catch(function () {
var t = document.createElement('input'); t.value = url; document.body.appendChild(t);
t.select(); try { document.execCommand('copy'); } catch (e) {} t.remove();
});
}, copy: true });
el.innerHTML = '';
items.forEach(function (it) {
var a = document.createElement(it.url ? 'a' : 'button');
a.textContent = it.label;
a.className = 'share-btn';
if (it.copy) a.setAttribute('data-copy', '');
if (it.url) { a.href = it.url; a.target = '_blank'; a.rel = 'noopener nofollow'; }
else a.addEventListener('click', it.fn);
el.appendChild(a);
});
});
}
};
window.addEventListener('DOMContentLoaded', function () { Share.mountAll(); });
})();