/*! butterfly 2018-09-12 */ (function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w=[].indexOf||function(a){for(var b=0,c=this.length;b=0&&c++,e="normal";break;case"csi":if("?>!$\" '".indexOf(b)>=0)break;if("0"<=b&&b<="9")break;if(";"===b)break;e="normal";break;case"osc":""!==b&&""!==b||(""===b&&c++,e="normal")}return d},s=function(a,b){var c;return c=function(d){var e,f,h;if(e=g(d.data.slice(1)),null===b||b.test(e))return butterfly.body.classList.remove("alarm"),f="Butterfly ["+butterfly.title+"]",a?(h=new Notification(f,{body:e,icon:"/static/images/favicon.png"}),h.onclick=function(){return window.focus(),h.close()}):alert(f+"\n"+e),butterfly.ws.shell.removeEventListener("message",c)},butterfly.ws.shell.addEventListener("message",c),butterfly.body.classList.add("alarm")},f=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},document.addEventListener("keydown",function(a){var b;if(!a.altKey||65!==a.keyCode)return!0;if(b=null,a.shiftKey){if(b=prompt("Ring alarm when encountering the following text: (can be a regexp)"),!b)return;b=new RegExp(b)}return Notification&&"default"===Notification.permission?Notification.requestPermission(function(){return s("granted"===Notification.permission,b)}):s("granted"===Notification.permission,b),f(a)}),addEventListener("copy",h=function(a){var b,c,d,e,f,g,h;for(document.getElementsByTagName("body")[0].contentEditable=!1,butterfly.bell("copied"),a.clipboardData.clearData(),h=getSelection().toString().replace(/\u00A0/g," ").replace(/\u2007/g," "),b="",g=h.split("\n"),d=0,e=g.length;d-1))return a.returnValue="This terminal is active and not in session. Are you sure you want to kill it?"}),Terminal.on("change",function(a){if(w.call(a.classList,"extended")>=0)return a.addEventListener("click",function(a){return function(){var b,c;return w.call(a.classList,"expanded")>=0?a.classList.remove("expanded"):(c=a.getBoundingClientRect().height,a.classList.add("expanded"),b=a.getBoundingClientRect().height,document.body.scrollTop+=b-c)}}(a))}),v=function(a,b){var c,d,e,f,g;for(f=a.childNodes,g=[],d=0,e=f.length;d$&').replace(c,'$1$2').replace(b,'$&')},t={"&":"&","<":"<",">":">"},j=function(a){return a.replace(/[&<>]/g,function(a){return t[a]||a})},Terminal.on("change",function(a){return v(a,function(){var a,b,c;if(3===this.nodeType&&(c=this.nodeValue,a=l(j(c)),a!==c))return b=document.createElement("span"),b.innerHTML=a,this.parentElement.replaceChild(b,this),!0})}),i=!1,e=!1,addEventListener("touchstart",function(a){return 2===a.touches.length?i=!0:3===a.touches.length?(i=!1,e=!0):4===a.touches.length?(i=!0,e=!0):void 0}),window.mobileKeydown=function(a){var b,c,d;return!(!i&&!e)&&(c=i,b=e,d=a.keyCode,a.keyCode>=97&&a.keyCode<=122&&(d-=32),a=new KeyboardEvent("keydown",{ctrlKey:c,altKey:b,keyCode:d}),i=e=!1,setTimeout(function(){return window.dispatchEvent(a)},0),!0)},document.addEventListener("keydown",function(a){return!a.altKey||79!==a.keyCode||(open(location.origin),f(a))}),u=null,o=1e3,k=100,m=function(){var a,b,c,d,e,f;if(butterfly.term.childElementCount>o+butterfly.rows){for(a=document.getElementById("packed"),e=document.createDocumentFragment("fragment"),b=c=0,f=o;0<=f?c<=f:c>=f;b=0<=f?++c:--c)e.appendChild(butterfly.term.firstChild);return d=document.createElement("div"),d.classList.add("pack"),d.appendChild(e),a.appendChild(d),a.childElementCount>k&&a.firstChild.remove(),u=setTimeout(m)}},Terminal.on("refresh",function(){return u&&clearTimeout(u),m()}),Terminal.on("clear",function(){var a,b;return b=document.createElement("div"),b.id="packed",a=document.getElementById("packed"),butterfly.body.replaceChild(b,a)}),a=function(){function a(){this.el=document.getElementById("popup"),this.bound_click_maybe_close=this.click_maybe_close.bind(this),this.bound_key_maybe_close=this.key_maybe_close.bind(this)}return a.prototype.open=function(a){return this.el.innerHTML=a,this.el.classList.remove("hidden"),addEventListener("click",this.bound_click_maybe_close),addEventListener("keydown",this.bound_key_maybe_close)},a.prototype.close=function(){return removeEventListener("click",this.bound_click_maybe_close),removeEventListener("keydown",this.bound_key_maybe_close),this.el.classList.add("hidden"),this.el.innerHTML=""},a.prototype.click_maybe_close=function(a){var b;for(b=a.target;b.parentElement;){if(Array.prototype.slice.call(this.el.children).indexOf(b)>-1)return!0;b=b.parentElement}return this.close(),f(a)},a.prototype.key_maybe_close=function(a){return 27!==a.keyCode||(this.close(),f(a))},a}(),p=new a,r=null,f=function(a){return a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,!1},q=function(a){var b;for(b=a.previousSibling,b||(b=a.parentNode.previousSibling),b||(b=a.parentNode.parentNode.previousSibling);b.lastChild;)b=b.lastChild;return b},n=function(a){var b;for(b=a.nextSibling,b||(b=a.parentNode.nextSibling),b||(b=a.parentNode.parentNode.nextSibling);null!=b?b.firstChild:void 0;)b=b.firstChild;return b},b=function(){function a(){butterfly.body.classList.add("selection"),this.selection=getSelection()}return a.prototype.reset=function(){var a,b,c;for(this.selection=getSelection(),a=document.createRange(),a.setStart(this.selection.anchorNode,this.selection.anchorOffset),a.setEnd(this.selection.focusNode,this.selection.focusOffset),this.start={node:this.selection.anchorNode,offset:this.selection.anchorOffset},this.end={node:this.selection.focusNode,offset:this.selection.focusOffset},a.collapsed&&(b=[this.end,this.start],this.start=b[0],this.end=b[1]),this.startLine=this.start.node;!this.startLine.classList||w.call(this.startLine.classList,"line")<0;)this.startLine=this.startLine.parentNode;for(this.endLine=this.end.node,c=[];!this.endLine.classList||w.call(this.endLine.classList,"line")<0;)c.push(this.endLine=this.endLine.parentNode);return c},a.prototype.clear=function(){return this.selection.removeAllRanges()},a.prototype.destroy=function(){return butterfly.body.classList.remove("selection"),this.clear()},a.prototype.text=function(){return this.selection.toString().replace(/\u00A0/g," ").replace(/\u2007/g," ")},a.prototype.up=function(){return this.go(-1)},a.prototype.down=function(){return this.go(1)},a.prototype.go=function(a){var b;if(b=Array.prototype.indexOf.call(butterfly.term.childNodes,this.startLine)+a,0<=b&&b0;)if(f[--d].match(b))return{node:e,offset:d+1};e=q(e),f=null!=e?e.textContent:void 0,d=f.length}else for(;e;){for(;d=0)return!0;if(a.shiftKey&&13===a.keyCode&&!r&&!getSelection().isCollapsed)return butterfly.send(getSelection().toString()),getSelection().removeAllRanges(),f(a);if(r){if(r.reset(),!a.ctrlKey&&a.shiftKey&&37<=(e=a.keyCode)&&e<=40)return!0;if(a.shiftKey&&a.ctrlKey)38===a.keyCode?r.up():40===a.keyCode&&r.down();else if(39===a.keyCode)r.shrinkLeft();else if(38===a.keyCode)r.expandLeft();else if(37===a.keyCode)r.shrinkRight();else{if(40!==a.keyCode)return f(a);r.expandRight()}return null!=r&&r.apply(),f(a)}return!(!r&&a.ctrlKey&&a.shiftKey&&38===a.keyCode)||(c=Math.max(butterfly.term.childElementCount-butterfly.rows,0),r=new b,r.selectLine(c+butterfly.y-1),r.apply(),f(a))}),document.addEventListener("keyup",function(a){var b,c;if(b=a.keyCode,w.call([16,17,18,19],b)>=0)return!0;if(r){if(13===a.keyCode)return butterfly.send(r.text()),r.destroy(),r=null,f(a);if(c=a.keyCode,w.call([37,38,39,40],c)<0)return r.destroy(),r=null,!0}return!0}),document.addEventListener("dblclick",function(a){var b,c,d,e,f;if(!(a.ctrlKey||a.altkey||(f=getSelection(),f.isCollapsed||f.toString().match(/\s/)))){for(e=document.createRange(),e.setStart(f.anchorNode,f.anchorOffset),e.setEnd(f.focusNode,f.focusOffset),e.collapsed&&(f.removeAllRanges(),d=document.createRange(),d.setStart(f.focusNode,f.focusOffset),d.setEnd(f.anchorNode,f.anchorOffset),f.addRange(d));!f.toString().match(/\s/)&&f.toString();)f.modify("extend","forward","character");for(f.modify("extend","backward","character"),b=f.anchorNode,c=f.anchorOffset,f.collapseToEnd(),f.extend(b,c);!f.toString().match(/\s/)&&f.toString();)f.modify("extend","backward","character");return f.modify("extend","forward","character")}}),document.addEventListener("keydown",function(a){var b;return!a.altKey||69!==a.keyCode||(b=new XMLHttpRequest,b.addEventListener("load",function(){var a,b,c,d,e,f;if(e=JSON.parse(this.responseText),c="
",c+="

Session list

",0===e.sessions.length)c+="No current session for user "+e.user;else{for(c+="
    ",d=e.sessions,a=0,b=d.length;a'+f+"";c+="
"}return c+="
",p.open(c)}),b.open("GET","/sessions/list.json"),b.send(),f(a))}),c=function(a){var b;return document.getElementById("style").setAttribute("href",a),b=document.createElement("img"),b.onerror=function(){return setTimeout(function(){return"undefined"!=typeof butterfly&&null!==butterfly?butterfly.resize():void 0},250)},b.src=a},d="undefined"!=typeof localStorage&&null!==localStorage?localStorage.getItem("theme"):void 0,d&&c(d),this.set_theme=function(a){if(d=a,"undefined"!=typeof localStorage&&null!==localStorage&&localStorage.setItem("theme",a),a)return c(a)},document.addEventListener("keydown",function(a){var b,e;return!a.altKey||83!==a.keyCode||(a.shiftKey?(e=document.getElementById("style").getAttribute("href"),e=e.split("?")[0],c(e+"?"+(new Date).getTime()),f(a)):(b=new XMLHttpRequest,b.addEventListener("load",function(){var a,b,c,e,f,g,h,i,j,k,l,m;if(i=JSON.parse(this.responseText),a=i.builtin_themes,l=i.themes,b='
\n

Pick a theme:

\n