',t.dataset.pootAutoplay="0",sessionStorage.setItem("pootAutoplay","0")):(t.innerHTML='',t.dataset.pootAutoplay="1",sessionStorage.setItem("pootAutoplay","1"))},refreshContent:function(o,e=!1){let n=document.getElementById("poot-content"),t={pootStack:POOT.pootStack,pootId:o,pootToken:POOT.pootToken};fetch("/view/v1/content/"+o,{method:"post",body:JSON.stringify(t)}).then(function(t){return t.json()}).then(function(t){n.innerHTML=atob(t.content),document.title=t.metadata.title,POOT.id=o,POOT.pootInit(),e||history.pushState(null,null,POOT.id)})},vote:function(i,t){POOT.pootStack.push(i),postData={id:i,vote:t,pootStack:POOT.pootStack,pootToken:POOT.pootToken},fetch("/api/v1/vote/"+i+"/"+t,{method:"post",body:JSON.stringify(postData)}).then(function(t){return t.json()}).then(function(t){let o=document.getElementById("poot-graph"),e=document.getElementById("poot-vote-wrapper"),n=document.getElementById("poot-score-"+i);e.innerHTML=''+t.data.pootMessage+"
",o.innerHTML=atob(t.data.pootGraph),n.getAttribute("data-score")!==t.data.pootVal&&(n.innerHTML=t.data.pootVal+"%"),"0"==t.data.nextPootId?(window.location.href="/",POOT.pootStack=[]):setTimeout(function(){POOT.refreshContent(t.data.nextPootId)},1500)})},pootInit:function(){let t=document.getElementById("poot-vote-button-yes"),o=document.getElementById("poot-vote-button-no"),n=document.getElementById("poot-audio-id-"+POOT.id),i=document.getElementById("poot-audio-icon-id-"+POOT.id),e=document.getElementById("poot-audio"),d=document.querySelectorAll("[data-poot-id]");if(d.forEach(function(t){let o=t.dataset.pootId,e=document.getElementById("poot-audio-img-id-"+o);n=document.getElementById("poot-audio-id-"+o),i=document.getElementById("poot-audio-icon-id-"+o),i.onclick=function(){n.play()},e.onclick=function(){n.play()}}),t&&o&&(t.onclick=function(){POOT.vote(POOT.id,1)},o.onclick=function(){POOT.vote(POOT.id,0)},"1"==e.dataset.pootAutoplay)){let t=document.getElementById("poot-audio-id-"+POOT.id).play();void 0!==t&&t.then(t=>{}).catch(t=>{})}}};window.addEventListener("DOMContentLoaded",POOT.initialInit);