import{d as $,e as n,get as H,PopStateHandlers as M,post as _,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 s=n("next"),a=n("upvote"),u=n("downvote"),l=n("report"),d=[n("top").getAttribute("quote-id")],c=[s.getAttribute("quote-id")],r=location.search,o=(()=>{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(o[0]," (Witzig), ").concat(o[2]," (Nicht Witzig), ")+"".concat(o[1]," (Vorheriges) und ").concat(o[3]," (Nächstes)"),$.onkeydown=e=>{switch(e.code){case"Key".concat(o[0]):a.click();break;case"Key".concat(o[1]):history.back();break;case"Key".concat(o[2]):u.click();break;case"Key".concat(o[3]):s.click()}};let p=n("share"),b=n("download"),A=n("author"),h=n("quote"),f=n("real-author-name"),v=n("rating-text"),T=n("rating-img-container");s.removeAttribute("href");function E(e){p.href="/zitate/share/".concat(e).concat(r),b.href="/zitate/".concat(e,".gif").concat(r);let[t,i]=e.split("-",2);h.href="/zitate/info/z/".concat(t).concat(r),A.href="/zitate/info/a/".concat(i).concat(r),d[0]=e}function L(e){if(e=e.toString(),v.replaceChildren(e),["---","???","0"].includes(e)){T.replaceChildren("");return}let t=Number.parseInt(e),i="rating-img ".concat(t>0?"witzig":"nicht-witzig");T.replaceChildren(...Array.from({length:Math.min(4,Math.abs(t))},()=>1).map(()=>D("div",{className:i})))}function P(e){function t(i,y,g){i.disabled=!1,e===y||e===g?(i.setAttribute("voted",g),i.value="0"):(i.removeAttribute("voted"),i.value=g)}t(a,1,"1"),t(u,-1,"-1")}function m(e){if(e.status)return console.error(e),e.status in[429,420]&&alert(e.reason),!1;if(e.id){if(E(e.id),c[0]=e.next,h.innerText="»".concat(e.quote,"«"),A.innerText="- ".concat(e.author),f.innerText=e.real_author,f.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(h.innerText," ").concat(f.innerText)),l.href="/kontakt?".concat(t.toString())}return L(e.rating),P(e.vote),!0}return!1}M.quotes=e=>{e.state&&m(e.state)},s.onclick=()=>H("/api/zitate/".concat(c[0]).replace(/\/$/,""),r,e=>{if(![200,420,429,void 0].includes(e.status)){c[0]===""?alert("Zitat konnte nicht abgerufen werden."):(c[0]="",s.click());return}m(e)&&(e.stateType="quotes",e.url="/zitate/".concat(e.id).concat(r),history.pushState(e,"Falsche Zitate",e.url),x(e.url))});let k=e=>_("/api/zitate/".concat(d[0]),{vote:e},t=>void m(t));for(let e of[a,u])e.type="button",e.onclick=()=>{a.disabled=!0,u.disabled=!0,k(e.value).then(()=>{a.disabled=!1,u.disabled=!1}).catch(()=>{a.disabled=!1,u.disabled=!1})}}for(let s of $.getElementsByClassName("auto-submit-element"))s.onchange=()=>{s.form.submit()};z();
// @license-end
//# sourceMappingURL=quotes.js.map
