rittenhop-dev/content/public/comment-counts.min.js
2024-09-23 19:40:12 -04:00

1 line
1.4 KiB
JavaScript

!async function(){const t={},e=new Set,o=document.querySelector("[data-ghost-comments-counts-api]").dataset.ghostCommentsCountsApi,n=function(o){(o.querySelectorAll?.("[data-ghost-comment-count]")||[]).forEach((o=>{t[o.dataset.ghostCommentCount]||e.add(o.dataset.ghostCommentCount)}))},a=async function(){const n=Array.from(e);if(e.clear(),!n.length)return;const a=await fetch(`${o}?ids=${n.join(",")}`,{method:"GET",headers:{Accept:"application/json","Content-Type":"application/json"}});if(200!==a.status)return;const s=await a.json();for(const[e,o]of Object.entries(s))t[e]=o;!function(){for(const[e,o]of Object.entries(t))document.querySelectorAll(`[data-ghost-comment-count="${e}"]`).forEach((t=>{let e=t.dataset.ghostCommentCountEmpty;if(1===o&&(e=t.dataset.ghostCommentCountSingular?`${o} ${t.dataset.ghostCommentCountSingular}`:o),o>1&&(e=t.dataset.ghostCommentCountPlural?`${o} ${t.dataset.ghostCommentCountPlural}`:o),e)if("false"!==t.dataset.ghostCommentCountAutowrap){const o=document.createElement(t.dataset.ghostCommentCountTag);t.dataset.ghostCommentCountClassName&&o.classList.add(t.dataset.ghostCommentCountClassName),o.textContent=e,t.insertAdjacentElement("afterend",o)}else t.insertAdjacentText("afterend",e);t.remove()}))}()};new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{n(t),function(){let t}()}))}))})).observe(document.body,{subtree:!0,childList:!0}),n(document.body),a()}();