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 if (!menu) return; 23 openShareMenu(shareBtn, shareData); 24}); 25 26function openShareMenu(button, { title, text, url }) { 27 if (!menu) return; 28 29 const mailto = `mailto:?subject=${encodeURIComponent(title)}&body=${encodeURIComponent(`${title}\n\n${text}\n\n${url}`)}`; 30 const whatsapp = `https://wa.me/?text=${encodeURIComponent(`${title}\n${url}`)}`; 31 const facebook = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}`; 32 33 menu.querySelector('[data-action="email"]').href = mailto; 34 menu.querySelector('[data-action="whatsapp"]').href = whatsapp; 35 menu.querySelector('[data-action="facebook"]').href = facebook; 36 37 const rect = button.getBoundingClientRect(); 38 menu.hidden = false; 39 40 menu.dataset.copyUrl = url; 41} 42 43if (menu) { 44 menu.addEventListener("click", async (e) => { 45 const actionEl = e.target.closest("[data-action]"); 46 if (!actionEl) return; 47 48 const action = actionEl.dataset.action; 49 50 if (action === "copy") { 51 e.preventDefault(); 52 try { 53 await copyToClipboard(menu.dataset.copyUrl); 54 actionEl.textContent = "Copied!"; 55 setTimeout(() => (actionEl.textContent = "Copy link"), 1200); 56 } catch (err) { 57 console.log(err); 58 alert("Could not copy link."); 59 } finally { 60 closeShareMenu(); 61 } 62 } else { 63 closeShareMenu(); 64 } 65 }); 66 67 document.addEventListener("click", (e) => { 68 if (menu.hidden) return; 69 if (e.target.closest("#shareMenu") || e.target.closest(".shareButton")) return; 70 closeShareMenu(); 71 }); 72 73 document.addEventListener("keydown", (e) => { 74 if (e.key === "Escape") closeShareMenu(); 75 }); 76} 77 78function closeShareMenu() { 79 if (!menu) return; 80 menu.hidden = true; 81} 82 83async function copyToClipboard(text) { 84 if (navigator.clipboard?.writeText) return navigator.clipboard.writeText(text); 85 86 const ta = document.createElement("textarea"); 87 ta.value = text; 88 ta.setAttribute("readonly", ""); 89 ta.style.position = "absolute"; 90 ta.style.left = "-9999px"; 91 document.body.appendChild(ta); 92 ta.select(); 93// document.execCommand("copy"); 94 document.body.removeChild(ta); 95}
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.