function mastodonShareButtonClick(e) { const btn = e.target; let href = document.URL; let title = document.title; if ('data-title' in btn.attributes && 'data-href' in btn.attributes) { href = btn.attributes['data-href'].value; title = btn.attributes['data-title'].value; } const sharingText = "Partager " + href + "Veuillez entrer l\'URL de votre instance Mastodon (par exemple mastodon.social) pour le partage"; const mastodonInstance = prompt(sharingText); if (mastodonInstance == null) { return; } if (mastodonInstance.indexOf('/') === -1) { window.open('https://' + mastodonInstance + '/share?text=' + encodeURIComponent(title) + ' ' + encodeURIComponent(href), "_blank"); } else { alert(""); } } addEventListener('DOMContentLoaded', () => { const buttons = document.querySelectorAll('button.mastodon-share'); buttons.forEach((btn) => { btn.innerHTML = 'Mastodon'; btn.addEventListener('click', mastodonShareButtonClick); }) })