import{d as $,e as n,get as M,PopStateHandlers as _,post as k,setLastLocation as x}from"/static/js/utils/utils.js?v=c676bb123f83b0ed";import{jsx as D}from"/static/js/utils/utils.js?v=c676bb123f83b0ed";// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later
function z(){let o=n("next"),a=n("upvote"),u=n("downvote"),l=n("report"),g=[n("top").getAttribute("quote-id")],d=[o.getAttribute("quote-id")],r=location.search,i=(()=>{let e=new URLSearchParams(r).get("keys");return e!=null&&e.length?e.length===4?e.toUpperCase():(alert("Invalid keys given, using default."),"WASD"):"WASD"})();n("wasd").innerText="".concat(i[0]," (Witzig), ").concat(i[2]," (Nicht Witzig), ")+"".concat(i[1]," (Vorheriges) und ").concat(i[3]," (Nächstes)"),$.onkeydown=e=>{switch(e.code){case"Key".concat(i[0]):a.click();break;case"Key".concat(i[1]):history.back();break;case"Key".concat(i[2]):u.click();break;case"Key".concat(i[3]):o.click()}};let p=n("share"),b=n("download"),A=n("author"),c=n("quote"),h=n("real-author-name"),v=n("rating-text"),T=n("rating-img-container");o.removeAttribute("href");function E(e){p.href="/zitate/share/".concat(e).concat(r),b.href="/zitate/".concat(e,".gif").concat(r);let[t,s]=e.split("-",2);c.href="/zitate/info/z/".concat(t).concat(r),A.href="/zitate/info/a/".concat(s).concat(r),g[0]=e}function L(e){if(e=e.toString(),v.replaceChildren(e),["---","???","0"].includes(e)){T.replaceChildren("");return}let t=Number.parseInt(e),s="rating-img ".concat(t>0?"witzig":"nicht-witzig");T.replaceChildren(...Array.from({length:Math.min(4,Math.abs(t))},()=>1).map(()=>D("div",{className:s})))}function P(e){function t(s,H,m){s.disabled=!1,e===H||e===m?(s.setAttribute("voted",m),s.value="0"):(s.removeAttribute("voted"),s.value=m)}t(a,1,"1"),t(u,-1,"-1")}function f(e){if(e.status)return console.error(e),e.status in[429,420]&&alert(e.reason),!1;if(e.id){if(E(e.id),d[0]=e.next,c.innerText="»".concat(e.quote,"«"),A.innerText="- ".concat(e.author),h.innerText=e.real_author,h.href="/zitate/info/a/".concat(e.real_author_id).concat(r),l!=null&&l.href){let t=new URLSearchParams(r);t.set("subject","Das falsche Zitat ".concat(e.id," hat ein Problem")),t.set("message","".concat(c.innerText," ").concat(h.innerText)),l.href="/kontakt?".concat(t.toString())}return L(e.rating),P(e.vote),!0}return!1}_.quotes=e=>{e.state&&f(e.state)},o.onclick=()=>M("/api/zitate/".concat(d[0]),r,e=>{f(e)&&(e.stateType="quotes",e.url="/zitate/".concat(e.id).concat(r),history.pushState(e,"Falsche Zitate",e.url),x(e.url))});let y=e=>k("/api/zitate/".concat(g[0]),{vote:e},t=>void f(t));for(let e of[a,u])e.type="button",e.onclick=()=>{a.disabled=!0,u.disabled=!0,y(e.value).then(()=>{a.disabled=!1,u.disabled=!1}).catch(()=>{a.disabled=!1,u.disabled=!1})}}for(let o of $.getElementsByClassName("auto-submit-element"))o.onchange=()=>{o.form.submit()};z();
// @license-end
//# sourceMappingURL=quotes.js.map
