var settingsWindowOpen=0;
function initExtra(){initSettings();var c=location.href.match(/boards\.4chan\.org\/(\w+)/)[1];if(gs("4chan_never_show_mobile")){link=document.querySelectorAll("link");len=link.length;for(var d=0;d<len;d++)link[d].getAttribute("href").match("mobile")&&(rem=link[d]).parentNode.removeChild(rem)}mobileSelect=document.getElementById("boardSelectMobile");len=mobileSelect.options.length;for(d=0;d<len;d++)mobileSelect.options[d].value==c&&(mobileSelect.selectedIndex=d);mobileSelect.onchange=function(){boardNew=
this.options[this.selectedIndex].value;if(boardNew==c)return!0;window.location="//boards.4chan.org/"+boardNew+"/"};gs("4chan_enable_backlinking")&&enableBacklinking();gs("4chan_enable_link_preview")&&enableLinkHoverPreview();gs("4chan_enable_quickreply")&&(document.querySelector("form[name=post] #recaptcha_image > img").onload=function(){replaceCaptchas()},enableQuickReply());gs("4chan_show_mobile")&&(document.getElementById("boardNavDesktop").removeAttribute("class"),document.getElementById("boardNavDesktop").setAttribute("style",
"display: none!important;"),document.getElementById("boardNavDesktopFoot").removeAttribute("class"),document.getElementById("boardNavDesktopFoot").setAttribute("style","display: none!important;"),document.getElementById("boardNavMobile").removeAttribute("class"),document.getElementsByClassName("boardBanner")[0].setAttribute("style","margin-top: 40px;"))}
function enableLinkHoverPreview(){a=document.querySelectorAll(".postContainer a.quotelink");len=a.length;for(var c=0;c<len;c++)a[c].onmouseover=function(){showLinkHoverPreview(this)},a[c].onmouseout=function(){hideLinkHoverPreview(this)}}
function doImageExpansion(c){if("img"!=c.target.localName||1==c.button||!c.target.getAttribute("src").match(/(thumbs|images)/))return!0;c.preventDefault();img=c.target;img.removeAttribute("style");src=img.getAttribute("src").match("spoiler.png")?img.getAttribute("src"):img.getAttribute("src").replace("[0-9].","");src.match("/thumb/")||src.match("spoiler.png")?(full=img.parentNode.getAttribute("href"),img.setAttribute("data-thumburl",src),img.setAttribute("src",full),img.setAttribute("style","opacity: 0.5;"),
img.setAttribute("class","expandedImg"),img.onload=function(){this.removeAttribute("style");return!1}):(img.setAttribute("src",img.getAttribute("data-thumburl")),img.removeAttribute("data-thumburl"),img.removeAttribute("class"))}
function enableQuickReply(){style=getActiveStyleSheet();img=style.match(/(Yotsuba B|Burichan)/i)?"//static.4chan.org/image/buttons/burichan/quote.png":"//static.4chan.org/image/buttons/futaba/quote.png";console.log(img);thread=document.querySelectorAll(".thread");threadlen=thread.length;for(var c=0;c<threadlen;c++){elem=thread[c].querySelectorAll(".post .postInfo");len=elem.length;threadId=thread[c].getAttribute("id").match(/(\d+)$/)[1];for(var d=0;d<len;d++)id=elem[d].getAttribute("id").match(/(\d+)$/)[1],
query=elem[d].querySelectorAll(".postNum"),queryLen=query.length-1,query[queryLen].innerHTML+='<a href="javascript:void(0);" class="extButton" id="qr_'+threadId+"_"+id+'"><img src="'+img+'" title="Quick Reply"></a>',document.getElementById("qr_"+threadId+"_"+id).onclick=function(){openQrWindow(this.getAttribute("id"))}}document.onmouseup=enddrag}
function openQrWindow(c){style=getActiveStyleSheet();style.match(/(Yotsuba B|Burichan)/i)?(img="//static.4chan.org/image/buttons/burichan/cross.png",imgFloat="//static.4chan.org/image/buttons/burichan/arrow_right.png"):(img="//static.4chan.org/image/buttons/futaba/cross.png",imgFloat="//static.4chan.org/image/buttons/futaba/arrow_right.png");board=window.location.href.match("/res/")?!1:!0;info=c.match(/qr_(\d+)_(\d+)/);thread=info[1];post=info[2];comment="";if(document.getElementById("qrWindow_"+
thread))return textarea=document.querySelector("#qrWindow_"+thread+" textarea[name=com]"),textarea.value+="\n>>"+post,textarea.focus(),moveCaretToEnd(textarea),!0;comment=">>"+post+"\n";form=document.querySelector("form[name=post]").cloneNode(!0);form.setAttribute("name","qr_"+thread);form.setAttribute("id","qr_"+thread);position=findPos(document.getElementById("p"+post))[1];qrContainer=document.createElement("div");qrContainer.setAttribute("class","reply qrWindow preview draggable");qrContainer.setAttribute("id",
"qrWindow_"+thread);qrTitle=document.createElement("div");qrTitle.setAttribute("class","postblock qrHeader");qrTitle.setAttribute("id","qrHeader_"+thread);qrTitle.appendChild(document.createTextNode("Quick Reply \u2013 Thread No."+thread));qrCloseButton=document.createElement("img");qrCloseButton.setAttribute("src",img);qrCloseButton.setAttribute("id","qrClose_"+thread);qrCloseButton.setAttribute("title","Close");qrFloatButton=document.createElement("img");qrFloatButton.setAttribute("src",imgFloat);
qrFloatButton.setAttribute("id","qrFloat_"+thread);qrFloatButton.setAttribute("title","Scroll With Page");qrButton=document.createElement("span");qrButton.setAttribute("class","qrButtonHolder");qrButton.appendChild(qrFloatButton);qrButton.appendChild(qrCloseButton);qrTitle.appendChild(qrButton);qrForm=document.createElement("div");qrForm.setAttribute("class","qrForm");qrForm.setAttribute("id","qrForm_"+thread);qrMessage=document.createElement("div");qrMessage.setAttribute("id","qrMessage_"+thread);
qrResto=document.createElement("input");qrResto.setAttribute("type","hidden");qrResto.setAttribute("name","resto");qrResto.setAttribute("value",thread);form.appendChild(qrResto);qrForm.appendChild(form);qrContainer.appendChild(qrTitle);qrContainer.appendChild(qrForm);qrContainer.appendChild(qrMessage);document.body.appendChild(qrContainer);elem=document.getElementById("qrWindow_"+thread);elem.setAttribute("style","left: "+(window.innerWidth/2-elem.offsetWidth/2)+"px; top: "+(position+40)+"px;");elem.querySelector('a[title="Get a new challenge"]').setAttribute("href",
"javascript:refreshQrCaptchas();");(rules=document.querySelector("#qrWindow_"+thread+" .rules")).parentNode.removeChild(rules);document.getElementById("qrFloat_"+thread).onclick=function(){style=getActiveStyleSheet();c=this.getAttribute("id").match(/(\d+)$/)[1];qrWindow=document.getElementById("qrWindow_"+c);scrollTop=document.documentElement.scrollTop||document.body.scrollTop;if(this.getAttribute("src").match("arrow_right")){posTop=findPos(qrWindow)[1];calcTop=posTop-scrollTop;newTop=calcTop<0?0:
calcTop;console.log([posTop,findPos(qrWindow),calcTop,newTop,scrollTop]);qrWindow.style.top=newTop+"px";qrWindow.style.position="fixed";this.setAttribute("src",this.getAttribute("src").replace("_right","_left"))}else{posTop=scrollTop+parseInt(qrWindow.style.top.match(/(\d+)/)[1]);qrWindow.style.top=posTop+"px";qrWindow.style.position="absolute";this.setAttribute("src",this.getAttribute("src").replace("_left","_right"))}};document.getElementById("qrClose_"+thread).onclick=function(){closeQrWindow(this.getAttribute("id").match(/(\d+)$/)[1])};
document.getElementById("qr_"+thread).onsubmit=function(d){d.preventDefault();c=this.getAttribute("id").match(/(\d+)$/)[1];form=document.getElementById("qr_"+c);document.getElementById("qrMessage_"+c).innerHTML='<div class="postblock qrMessage">Submitting post... <span id="upload_progress_'+c+'"></span></div>';var d=new FormData(form),e=new XMLHttpRequest;e.open("POST",form.getAttribute("action"));e.onload=function(){this.status==200&&parseResponse(this.responseText,c)};percent=previousPercent=0;
e.upload.onprogress=function(d){if(d.lengthComputable){percent=parseInt((d.loaded/d.total*100).toString().split(".")[0]);if(previousPercent!=percent)document.getElementById("upload_progress_"+c).innerText=percent+"%";previousPercent=percent}};e.send(d);return false};textarea=document.querySelector("#qrWindow_"+thread+" textarea[name=com]");textarea.value=comment;textarea.focus();moveCaretToEnd(textarea)}
function parseResponse(c,d){if(c.match('"errmsg"'))return msg=c.split('"errmsg">')[1].split("</span>")[0],qrError(msg,d,0),!0;if(c.match("success")||c.match("uploaded!"))return thread=c.match(/thread:(\d+)/)[1],document.getElementById("qrMessage_"+thread).innerHTML='<div class="postblock qrMessage">Post submitted!<br />Window will now close.</div>',setTimeout(closeQrWindow,3E3,thread),refreshQrCaptchas(),!0;if(c.match("You are banned! ;_;"))return c.match("heeding this warning")?(warning=c.split(/<br\/><br\/>\n<b>/)[1].split("</b><br/><br/>")[0],
qrError("You were issued a warning<br />Warning reason:<br /><h3>"+warning+"</h3>",d,13)):qrError('You are banned! ;_;<br />Please click <a href="//www.4chan.org/banned">HERE</a> to see the reason.',d,13),!0;c=c.match(/Error: \w+/);qrError(c,d)}function qrError(c,d){document.getElementById("qrMessage_"+d).innerHTML='<div class="postblock qrMessage">'+c+"</div>";refreshQrCaptchas()}captchaInterval=null;function refreshQrCaptchas(c){c&&c.preventDefault();Recaptcha.reload("t")}
function replaceCaptchas(){captcha=document.querySelector("form[name=post] #recaptcha_image > img").getAttribute("src");captchaCode=captcha.split("?c=")[1];captchas=document.querySelectorAll("form:not([name=post]) .recaptchatable");len=captchas.length;for(var c=0;c<len;c++)captchas[c].querySelector("#recaptcha_challenge_field").setAttribute("value",captchaCode),captchas[c].querySelector(".recaptcha_image_cell img").setAttribute("src",captcha)}
function closeQrWindow(c){(elem=document.getElementById("qrWindow_"+c)).parentNode.removeChild(elem)}
function enableBacklinking(){threads=document.querySelectorAll(".thread");threadLen=threads.length;prepend=window.location.href.match("/res/")?"":"res/";for(var c=0;c<threadLen;c++){thread=prepend+threads[c].getAttribute("id").match(/(\d+)$/)[1];elem=threads[c].querySelectorAll("blockquote");len=elem.length;for(var d=0;d<len;d++){id=elem[d].getAttribute("id").match(/(\d+)$/)[1];links=elem[d].querySelectorAll("a.quotelink");alen=links.length;for(var e=0;e<alen;e++)if(link=links[e].getAttribute("href").match(/(\d+)$/))link=
link[1],document.getElementById("p"+link)&&!document.getElementById("bli_"+link+"_"+id)&&(append='<span id="bli_'+link+"_"+id+'"><a href="'+thread+"#p"+id+'" class="quotelink">&gt;&gt;'+id+"</a></span>",document.getElementById("bl_"+link)?aelem="bl_"+link:(append='<div class="backlinkHr"><hr></div><div id="bl_'+link+'" class="backlink"><strong>Replies to this post:</strong><br />'+append+"</div>",aelem="p"+link),document.getElementById(aelem).innerHTML+=append)}}}
function highlightPostHover(c){c.className+=" highlight"}function removePostHover(c){c.className=c.className.replace(/ highlight$/,"")}
function showLinkHoverPreview(c){id=c.getAttribute("href");thread=id.match(/([0-9]+)#p/)[1];post=id.match(/#p([0-9]+)/)[1];if(!id.match(thread+"#p")||!document.getElementById("p"+post))return!0;postdiv=document.getElementById("p"+post);postHeight=postdiv.offsetHeight;postPos=findPos(postdiv)[1];windowPos=document.documentElement.scrollTop||document.body.scrollTop;windowPosBot=windowPos+window.innerHeight;if(postPos<windowPos){if(!(windowPos-postPos>postHeight/2))return highlightPostHover(postdiv),
!0}else if(!(windowPosBot-postPos<postHeight/2))return highlightPostHover(postdiv),!0;clone=document.getElementById("p"+post).cloneNode(!0);clone.setAttribute("id","");clone.setAttribute("class","");div=document.createElement("div");div.setAttribute("id","hp"+post);div.setAttribute("class","post reply posthover desktop preview");div.appendChild(clone);document.body.appendChild(div);gs("4chan_enable_backlinking")&&document.querySelector("#hp"+post+" hr")&&((b=document.querySelector("#hp"+post+" hr")).parentNode.removeChild(b),
(b=document.querySelector("#hp"+post+" div.backlink")).parentNode.removeChild(b));newElem=document.getElementById("hp"+post);linkOffset=findPos(c);linkWidth=c.offsetWidth;eheight=newElem.offsetHeight;ewidth=newElem.offsetWidth;win=[window.innerWidth,window.innerHeight];linkOffset.left+linkWidth+ewidth>win[0]-30?(toppos=linkOffset[1]-eheight/2,left=linkOffset[0]-ewidth-30):(toppos=linkOffset[1]-eheight/2,left=linkOffset[0]+linkWidth);newElem.setAttribute("style","top: "+toppos+"px; left: "+left+"px; position: absolute;")}
function findPos(c){var d=toppos=0;if(c.offsetParent){do d+=c.offsetLeft,toppos+=c.offsetTop;while(c=c.offsetParent);return[d,toppos]}}
function initSettings(){settingsLink=document.getElementById("settingsWindowLink");settingsLinkBot=document.getElementById("settingsWindowLinkBot");settingsLinkMobile=document.getElementById("settingsWindowLinkMobile");settingsLink.onclick=function(){if(1==settingsWindowOpen)return closeSettingsWindow(),!1;document.getElementById("settingsBox").setAttribute("style","display: block; top: 20px;");settingsWindowOpen=1};settingsLinkMobile.onclick=function(){if(1==settingsWindowOpen)return closeSettingsWindow(),
!1;document.getElementById("settingsBox").setAttribute("style","display: block; position: fixed; top: 30px;");settingsWindowOpen=1};settingsLinkBot.onclick=function(){if(1==settingsWindowOpen)return closeSettingsWindow(),!1;pos=findPos(document.getElementById("navbotr"));document.getElementById("settingsBox").setAttribute("style","display: block; top: "+(pos[1]-250)+"px;");settingsWindowOpen=1};!0!=gs("4chan_settings")&&(ss("4chan_settings",!0),ss("4chan_enable_image_expansion",!1),ss("4chan_enable_link_preview",
!1),ss("4chan_enable_backlinking",!1),ss("4chan_enable_quickreply",!1),ss("4chan_show_mobile",!1),ss("4chan_never_show_mobile",!1));document.getElementById("settingsImageExpansion").checked=gs("4chan_enable_image_expansion");document.getElementById("settingsLinkPreview").checked=gs("4chan_enable_link_preview");document.getElementById("settingsEnableBacklinking").checked=gs("4chan_enable_backlinking");document.getElementById("settingsAlwaysShowMobile").checked=gs("4chan_show_mobile");document.getElementById("settingsEnableQuickReply").checked=
gs("4chan_enable_quickreply");document.getElementById("settingsNeverShowMobile").checked=gs("4chan_never_show_mobile")}
function saveSettings(){ss("4chan_enable_image_expansion",document.getElementById("settingsImageExpansion").checked);ss("4chan_enable_link_preview",document.getElementById("settingsLinkPreview").checked);ss("4chan_enable_backlinking",document.getElementById("settingsEnableBacklinking").checked);ss("4chan_show_mobile",document.getElementById("settingsAlwaysShowMobile").checked);ss("4chan_enable_quickreply",document.getElementById("settingsEnableQuickReply").checked);ss("4chan_never_show_mobile",document.getElementById("settingsNeverShowMobile").checked);
location.reload(!0)}function closeSettingsWindow(){document.getElementById("settingsBox").style.display="none";settingsWindowOpen=0}function gs(c){return"true"==localStorage.getItem(c)?!0:!1}function disableMobile(){ss("4chan_never_show_mobile","true");location.reload(!0)}function ss(c,d){localStorage.setItem(c,d)}
function hideLinkHoverPreview(c){id=c.getAttribute("href");thread=id.match(/([0-9]+)#p/)[1];post=id.match(/#p([0-9]+)/)[1];if(!id.match(thread+"#p")||!document.getElementById("p"+post))return!0;removePostHover(document.getElementById("p"+post));if(!document.getElementById("hp"+post))return!0;(popup=document.getElementById("hp"+post)).parentNode.removeChild(popup)}var dragging=!1,currentDraggingObject=null,curleft,curtop;
function drag(c){if(!0==dragging)return currentDraggingObject.style.left=curleft+c.clientX-x+"px",currentDraggingObject.style.top=curtop+c.clientY-y+"px",!1}function enddrag(){dragging=!1}
function begindrag(c){for(elem=c.target;"body"!=elem.tagName&&!(null!=elem.className&&elem.className.match("draggable"));)elem=elem.parentNode;if(null==elem.className)return!1;elem.className.match("draggable")&&(dragging=!0,currentDraggingObject=elem,curleft=parseInt(elem.style.left+0),curtop=parseInt(elem.style.top),x=c.clientX,y=c.clientY,document.onmousemove=function(c){drag(c);return!1})}
function moveCaretToEnd(c){"number"==typeof c.selectionStart?c.selectionStart=c.selectionEnd=c.value.length:"undefined"!=typeof c.createTextRange&&(c.focus(),c=c.createTextRange(),c.collapse(!1),c.select())}document.onselectstart=function(){return!dragging};document.onmousedown=function(c){if(gs("4chan_enable_quickreply"))if(c.target.getAttribute("id"))if(c.target.getAttribute("id").match("qrHeader"))begindrag(c);else return!0;else return!0;return!dragging};
document.onclick=function(c){if(dragging)return!1;1==settingsWindowOpen&&("settingsBoxContent"!=c.target.parentNode.parentNode.getAttribute("id")&&"settingsBox"!=c.target.parentNode.parentNode.getAttribute("id")&&"settingsBox"!=c.target.getAttribute("id")&&"settingsWindowLink"!=c.target.getAttribute("id")&&"settingsWindowLinkBot"!=c.target.getAttribute("id")&&"settingsWindowLinkMobile"!=c.target.getAttribute("id")&&"settingsBoxContent"!=c.target.getAttribute("id"))&&closeSettingsWindow();gs("4chan_enable_image_expansion")&&
doImageExpansion(c);return!dragging};