diff --git a/src/Share.svelte b/src/Share.svelte index a061f50..d746673 100644 --- a/src/Share.svelte +++ b/src/Share.svelte @@ -8,12 +8,24 @@ let isOpen = false; let isToastOpen = false; + let isBinary = false; let toastText = ''; const toggle = () => { isOpen = !isOpen; + updateShareLink(); + }; + const doShare = () => { + navigator.clipboard + .writeText(share) + .then(() => (toastText = 'Lien de partage copié dans le presse-papier.')) + .catch(() => (toastText = 'Erreur de copie automatique.')) + .finally((isToastOpen = true)); + }; + + const updateShareLink = () => { const loc = document.location; const search = new URLSearchParams(); const api = calendar.getAPI(); @@ -26,18 +38,21 @@ search.append('d', api.getDate().toISOString()); } - const b64 = window.btoa(search.toString()); + if (isBinary) { + const b64 = window.btoa(search.toString()); - share = `${loc.origin}${loc.pathname}?b64=${b64}`; + share = `${loc.origin}${loc.pathname}?b64=${b64}`; + } else { + share = `${loc.origin}${loc.pathname}${search.toString()}`; + } }; - const doShare = () => { - navigator.clipboard - .writeText(share) - .then(() => (toastText = 'Lien de partage copié dans le presse-papier.')) - .catch(() => (toastText = 'Erreur de copie automatique.')) - .finally((isToastOpen = true)); + const toggleBinary = () => { + isBinary = !isBinary; + updateShareLink(); }; + + $: shareDataIcon = isBinary ? 'code-square' : 'code';
@@ -63,6 +78,10 @@ + + + + Propulsé par le Club Réseau de l'ENS