-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiine.mini.js
More file actions
1 lines (1 loc) · 3.68 KB
/
Copy pathiine.mini.js
File metadata and controls
1 lines (1 loc) · 3.68 KB
1
(()=>{const p="https://vhiweeypifbwacashxjz.supabase.co",b="sb_publishable_EoB7MFJhCmb6PiAk-GPJ4w_PGhQ44Ru",g="heart",v="Send your appreciation",m={heart:"Send a heart",thumbs_up:"Send a thumbs up",upvote:"Send an upvote"},y={heart:'<svg width="16" height="16" viewBox="0 0 48 48" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="4" aria-hidden="true"><path d="M15 8C8.925 8 4 12.925 4 19c0 11 13 21 20 23.326C31 40 44 30 44 19c0-6.075-4.925-11-11-11c-3.72 0-7.01 1.847-9 4.674A10.99 10.99 0 0 0 15 8"/></svg>',thumbs_up:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"></path></svg>',upvote:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 17l-6-6-6 6"/><path d="M18 11l-6-6-6 6"/></svg>'},f=e=>" "+e,w=(e,t)=>{var a=e.querySelector("svg");a&&("upvote"===(e.closest(".iine-button")?.dataset.icon||g)?a.setAttribute("stroke-width",t?"3":"2"):a.querySelectorAll("path, polygon, circle").forEach(e=>{e.setAttribute("fill",t?"currentColor":"none")}))};document.addEventListener("DOMContentLoaded",()=>{const n=document.querySelectorAll(".iine-button");if(0!==n.length){var e=Array.from(n).map(e=>e.dataset.slug||window.location.pathname);const o=[...new Set(e)],h=new Map;(async()=>{if(0!==o.length)try{var e=await fetch(p+"/rest/v1/rpc/get_hits",{method:"POST",headers:{"Content-Type":"application/json",apikey:b,Authorization:"Bearer "+b},body:JSON.stringify({page_slugs:o})});if(!e.ok)throw new Error("Failed to fetch counts");var t=await e.json();if(t&&"object"==typeof t&&!t.error)for(const r in t){var a=t[r];h.set(r,"number"==typeof a?a:0)}}catch(e){console.error("Error fetching iine counts:",e)}await 0,n.forEach(t=>{const a=t.dataset.slug||window.location.pathname,r="iine-clicked-"+a;let n=t.querySelector(".icon"),o=t.querySelector(".counter"),i=(n||(t.textContent="",(n=document.createElement("span")).className="icon",t.appendChild(n)),o||((o=document.createElement("span")).className="counter",t.appendChild(o)),h.get(a)||0);o.textContent=f(i);const s=t.dataset.icon||g;t.getAttribute("aria-label")||(c=t,e=s,c=c.dataset.ariaLabel||c.dataset.label||m[e]||v,t.setAttribute("aria-label",c),t.setAttribute("title",c)),t.removeAttribute("aria-hidden");var e=!!localStorage.getItem(r);t.setAttribute("aria-pressed",e.toString());const d="iine-description-"+a.replace(/\W/g,"-");var c=document.getElementById(d);c||((c=document.createElement("span")).id=d,c.style.display="none",c.textContent="Already clicked.",document.body.appendChild(c)),y[s]?n.innerHTML=y[s]:n.textContent=s,localStorage.getItem(r)&&(t.classList.add("clicked"),t.setAttribute("aria-disabled","true"),t.setAttribute("aria-describedby",d),y[s])&&w(n,!0);const l=async e=>{localStorage.getItem(r)||"true"===t.getAttribute("aria-disabled")||(e&&e.preventDefault(),t.setAttribute("aria-disabled","true"),localStorage.setItem(r,"true"),i++,t.classList.add("clicked"),t.setAttribute("aria-pressed","true"),t.setAttribute("aria-describedby",d),o.textContent=f(i),y[s]&&w(n,!0),fetch(p+"/rest/v1/rpc/increment_hits",{method:"POST",headers:{"Content-Type":"application/json",apikey:b,Authorization:"Bearer "+b},body:JSON.stringify({page_slug:a})}).catch(e=>{console.error("Failed to increment page hits:",e)}))};var u=t.closest("form");u?u.addEventListener("submit",e=>{e.preventDefault(),l(e)}):t.addEventListener("click",l),t.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),l(e))})})})()}})})();