import { simpleNotification } from '../z_comps/notify.js'; const url = window.location.href; const url_encoded = encodeURIComponent(url); // Función reutilizable para abrir ventanas de compartir function openShareWindow(shareUrl) { window.open(shareUrl, '_blank', 'width=600,height=400,noopener,noreferrer'); } // Copiar al portapapeles const btn_copy = document.querySelector("button.copy"); if (btn_copy) { btn_copy.addEventListener("click", async () => { try { await navigator.clipboard.writeText(url); simpleNotification("URL Copiada", "URL copiada", "success"); } catch (err) { console.error('Error al copiar: ', err); } }); } // LinkedIn const btn_in = document.querySelector("button.in"); if (btn_in) { btn_in.addEventListener("click", () => { const linkedInUrl = `https://www.linkedin.com/sharing/share-offsite/?url=${url_encoded}`; openShareWindow(linkedInUrl); }); } // Facebook const btn_fb = document.querySelector("button.fb"); if (btn_fb) { btn_fb.addEventListener("click", () => { const fbShareUrl = `https://www.facebook.com/sharer/sharer.php?u=${url_encoded}`; openShareWindow(fbShareUrl); }); } // X / Twitter const btn_x = document.querySelector("button.tw"); if (btn_x) { btn_x.addEventListener("click", () => { const tweetText = encodeURIComponent("Mira este post interesante:"); const xShareUrl = `https://twitter.com/intent/tweet?url=${url_encoded}&text=${tweetText}`; openShareWindow(xShareUrl); }); }