1const menu = document.getElementById("shareMenu"); 2 3document.addEventListener("click", async (e) => { 4 const shareBtn = e.target.closest(".shareButton"); 5 if (!shareBtn) return; 6 7 const title = document.title; 8 const text = document.querySelector(".teaserText")?.textContent?.trim() ?? ""; 9 const url = location.href; 10 11 const shareData = { title, text, url }; 12 13 if (navigator.share) { 14 try { 15 await navigator.share(shareData); 16 } catch (err) { 17 console.log(err); 18 } 19 return; 20 } 21 22 openShareMenu(shareBtn, shareData); 23}); 24 25function openShareMenu(button, { title, text, url }) { 26 const mailto = `mailto:?subject=${encodeURIComponent(title)}&body=${encodeURIComponent(`${title}\n\n${text}\n\n${url}`)}`; 27 const whatsapp = `https://wa.me/?text=${encodeURIComponent(`${title}\n${url}`)}`; 28 const facebook = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}`; 29 30 menu.querySelector('[data-action="email"]').href = mailto; 31 menu.querySelector('[data-action="whatsapp"]').href = whatsapp; 32 menu.querySelector('[data-action="facebook"]').href = facebook; 33 34 const rect = button.getBoundingClientRect(); 35 menu.hidden = false; 36 37 menu.dataset.copyUrl = url; 38} 39 40menu.addEventListener("click", async (e) => { 41 const actionEl = e.target.closest("[data-action]"); 42 if (!actionEl) return; 43 44 const action = actionEl.dataset.action; 45 46 if (action === "copy") { 47 e.preventDefault(); 48 try { 49 await copyToClipboard(menu.dataset.copyUrl); 50 actionEl.textContent = "Copied!"; 51 setTimeout(() => (actionEl.textContent = "Copy link"), 1200); 52 } catch (err) { 53 console.log(err); 54 alert("Could not copy link."); 55 } finally { 56 closeShareMenu(); 57 } 58 } else { 59 closeShareMenu(); 60 } 61}); 62 63document.addEventListener("click", (e) => { 64 if (menu.hidden) return; 65 if (e.target.closest("#shareMenu") || e.target.closest(".shareButton")) return; 66 closeShareMenu(); 67}); 68 69document.addEventListener("keydown", (e) => { 70 if (e.key === "Escape") closeShareMenu(); 71}); 72 73function closeShareMenu() { 74 menu.hidden = true; 75} 76 77async function copyToClipboard(text) { 78 if (navigator.clipboard?.writeText) return navigator.clipboard.writeText(text); 79 80 const ta = document.createElement("textarea"); 81 ta.value = text; 82 ta.setAttribute("readonly", ""); 83 ta.style.position = "absolute"; 84 ta.style.left = "-9999px"; 85 document.body.appendChild(ta); 86 ta.select(); 87// document.execCommand("copy"); 88 document.body.removeChild(ta); 89}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.