var e=`[Higan Haozi][upvote-runtime]`;function t(){return Array.from(document.querySelectorAll(`script[data-upvote-runtime]`)).map(t=>{let n=t.dataset.countSelector,r=t.dataset.group,i=t.dataset.nameAttribute,a=t.dataset.networkRequestFailedMsg,o=t.dataset.plural,s=t.dataset.storageKey,c=t.dataset.triggerSelector;return!s||!r||!o||!i||!c||!n||!a?(console.error(`${e} Incomplete upvote runtime config.`,{countSelector:n,group:r,nameAttribute:i,networkRequestFailedMsg:a,plural:o,storageKey:s,triggerSelector:c}),null):{countSelector:n,group:r,nameAttribute:i,networkRequestFailedMsg:a,plural:o,storageKey:s,triggerSelector:c}}).filter(e=>e!==null)}function n(t){try{let e=localStorage.getItem(t);if(!e)return new Set;let n=JSON.parse(e);return Array.isArray(n)?new Set(n.filter(e=>typeof e==`string`&&e.trim()!==``)):new Set}catch(t){return console.error(`${e} Failed to read liked ids from localStorage.`,t),new Set}}function r(t,n){try{localStorage.setItem(t,JSON.stringify(Array.from(n)))}catch(t){console.error(`${e} Failed to persist liked ids to localStorage.`,t)}}function i(e,t){return t.getAttribute(e)||null}function a(e,t){document.querySelectorAll(e.triggerSelector).forEach(n=>{i(e.nameAttribute,n)===t&&(n.style.color=`var(--color-accent)`,n.style.fontWeight=`500`)})}function o(e,t){document.querySelectorAll(e.countSelector).forEach(n=>{if(i(e.nameAttribute,n)!==t)return;let r=Number.parseInt(n.innerText,10);n.innerText=String(Number.isNaN(r)?1:r+1)})}async function s(t,n){try{let e=await fetch(`/apis/api.halo.run/v1alpha1/trackers/upvote`,{body:JSON.stringify({group:t.group,name:n,plural:t.plural}),headers:{"Content-Type":`application/json;charset=UTF-8`},method:`POST`});if(!e.ok)throw Error(`HTTP ${e.status}`);return!0}catch(n){return alert(t.networkRequestFailedMsg),console.error(`${e} Failed to submit upvote.`,n),!1}}var c=t().map(e=>({config:e,likedNames:n(e.storageKey),pendingNames:new Set}));document.addEventListener(`click`,async e=>{let t=e.target instanceof Element?e.target:null;if(t)for(let n of c){let c=t.closest(n.config.triggerSelector);if(!c)continue;let l=i(n.config.nameAttribute,c);if(!l||(e.preventDefault(),n.likedNames.has(l)||n.pendingNames.has(l)))return;n.pendingNames.add(l);let u=await s(n.config,l);if(n.pendingNames.delete(l),!u)return;n.likedNames.add(l),r(n.config.storageKey,n.likedNames),o(n.config,l),a(n.config,l);return}});