var historyCount=8;var favoriteCount=10;var privateCount=10;var generating=false;var apiResetTime=0;var currentToken;function generateReset(){generating=false;generatorHistoryItems=[];generatorFavoriteItems=[];generatorPrivateItems=[];}
function generateInit(){if(license==='premium')historyCount=12;donwloadGenStats();doHistory();favoritesHistory();privatesHistory();}
function updateApiResetTime(){if(apiResetTime&&!apiResetTime.reset){apiResetTime.seconds--;if(apiResetTime.seconds<0){apiResetTime.seconds=59;apiResetTime.minutes--;}
if(apiResetTime.minutes<0){apiResetTime.minutes=59;apiResetTime.hours--;}
if(apiResetTime.hours<0){apiResetTime.reset=true;}
var stamp='';if(apiResetTime.reset){stamp="API Reset";}else{stamp="API Resets In "+(('0'+apiResetTime.hours).slice(-2)+':'+('0'+apiResetTime.minutes).slice(-2)+':'+('0'+apiResetTime.seconds).slice(-2));}
$('#api-reset-timer').text(stamp);}}
function doTimeOut(){setInterval(function(){updateApiResetTime();},1000);}
function onRenewClicked(){if(license!=='premium'){alertify.error("You need Premium to be able to renew tokens! Click here to upgrade.");}else{var win=window.open('https://panel.thealtening.com/#renew','_blank');win.focus();}}
function doGenerate(){if(generating)return;generating=true;generate(function(code,parsed){if(code==200){generatorAddAccount(parsed.username,parsed.token,parsed.skin,parsed.cape,false,true,parsed.info);if(parsed.captcha_next){renderCaptcha();}}else{alert('Error: '+parsed.errorMessage);if(parsed.errorMessage.indexOf('Captcha invalid')!=-1){renderCaptcha();}}
generating=false;});}
function generate(response){var xhttp=new XMLHttpRequest();xhttp.onreadystatechange=function(){if(this.readyState==4){hideCaptcha();var parsed=JSON.parse(xhttp.responseText);response(this.status,parsed);}};xhttp.withCredentials=true;xhttp.open("POST","https://api.thealtening.com/alts/generate",true);xhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");var captchaAnswer=getCaptchaValue();if(captchaAnswer.length==0){alertify.delay(2500).error(`Please complete the captcha before attempting to generating an alt.`);generating=false;return;}
xhttp.send(JSON.stringify({captcha:captchaAnswer}));}
function getCaptchaValue(){try{return grecaptcha.getResponse();}catch(ex){return "-1";}}
function doHistory(){_history(function(code,parsed){if(code==200){apiResetTime=parsed.shift().api_reset;var is_captcha=parsed.shift().is_captcha;if(is_captcha){renderCaptcha();}
updateApiResetTime();doTimeOut();parsed.reverse().forEach(element=>{generatorAddToHistory(element.token,element.name,element.skin,element.cape,element.valid,undefined,element.info);});if(parsed.length>0){var element=parsed.reverse()[0];if(!element.expired)generatorAddAccount(element.name,element.token,element.skin,element.cape,element.valid,undefined,element.info);}}else alert('Error: '+parsed.errorMessage);});}
function _history(response){var xhttp=new XMLHttpRequest();xhttp.onreadystatechange=function(){if(this.readyState==4){var parsed=JSON.parse(xhttp.responseText);response(this.status,parsed);}};xhttp.withCredentials=true;xhttp.open("GET","https://api.thealtening.com/alts/history",true);xhttp.send(null);}
function doAddFavorite(token,add){if(license!="premium"){alertify.error("You need Premium to favorite an account! Click here to upgrade.");return;}
if(generating)return;generating=true;addFavorite(token,add,function(code,parsed){if(code==200){parsed=JSON.parse(parsed);if(add){generatorAddToFavorite(parsed.token,parsed.name,parsed.skin,parsed.cape,parsed.valid,true,parsed.info);alertify.closeLogOnClick(true).success(`Account ${parsed.name} added to favorites.`);}else{generatorRemoveFromFavorite(parsed.token);alertify.closeLogOnClick(true).success(`Account ${parsed.name} removed from favorites.`);}}else if(code==204){alertify.delay(4000).error(`Account already in favorite list.`);}else{parsed=JSON.parse(parsed);alertify.delay(4000).error(`Could not add account to favorites. Details:
`+parsed.errorMessage);}
generating=false;});}
function addFavorite(token,add,response){var xhttp=new XMLHttpRequest();xhttp.onreadystatechange=function(){if(this.readyState==4){response(this.status,this.responseText);}};xhttp.withCredentials=true;xhttp.open("POST","https://api.thealtening.com/alts/favorite",true);xhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhttp.send(JSON.stringify({token:token,add:add}));}
function favoritesHistory(){var xhttp=new XMLHttpRequest();xhttp.onreadystatechange=function(){if(this.readyState==4){var parsed=JSON.parse(xhttp.responseText);var code=this.status;if(code==200){if(Object.keys(parsed).length===0)return;parsed.forEach(element=>{generatorAddToFavorite(element.token,element.name,element.skin,element.cape,element.valid,undefined,element.info);});}else alertify.delay(4000).error(`Could not add account to favorites. Details:
`+parsed.errorMessage);}};xhttp.withCredentials=true;xhttp.open("GET","https://api.thealtening.com/alts/favorites",true);xhttp.send(null);}
function doAddPrivate(token,add){if(license!="premium"){alertify.error("You need Premium to private an account! Click here to upgrade.");return;}
if(generating)return;generating=true;addPrivate(token,add,function(code,parsed){if(code==200){parsed=JSON.parse(parsed);if(add){generatorAddToPrivate(parsed.token,parsed.name,parsed.skin,parsed.cape,parsed.valid,true,parsed.info);alertify.closeLogOnClick(true).success(`Account ${parsed.name} added to privates.`);}else{generatorRemoveFromPrivate(parsed.token);alertify.closeLogOnClick(true).success(`Account ${parsed.name} removed from privates.`);}}else if(code==204){alertify.delay(4000).error(`Account already in private list.`);}else{parsed=JSON.parse(parsed);alertify.delay(4000).error(`Could not add account to privates. Details:
`+parsed.errorMessage);}
generating=false;});}
function addPrivate(token,add,response){var xhttp=new XMLHttpRequest();xhttp.onreadystatechange=function(){if(this.readyState==4){response(this.status,this.responseText);}};xhttp.withCredentials=true;xhttp.open("POST","https://api.thealtening.com/alts/private",true);xhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhttp.send(JSON.stringify({token:token,add:add}));}
function privatesHistory(){var xhttp=new XMLHttpRequest();xhttp.onreadystatechange=function(){if(this.readyState==4){var parsed=JSON.parse(xhttp.responseText);var code=this.status;if(code==200){if(Object.keys(parsed).length===0)return;parsed.forEach(element=>{generatorAddToPrivate(element.token,element.name,element.skin,element.cape,element.valid,undefined,element.info);});}else alertify.delay(4000).error(`Could not add account to privates. Details:
`+parsed.errorMessage);}};xhttp.withCredentials=true;xhttp.open("GET","https://api.thealtening.com/alts/privates",true);xhttp.send(null);}
function donwloadGenStats(){var xhttp=new XMLHttpRequest();xhttp.onreadystatechange=function(){if(this.readyState==4){var parsed=JSON.parse(xhttp.responseText);var code=this.status;if(code==200){$('#gen-stats-lifetime').text(parsed.lifetime);$('#gen-stats-month').text(parsed.month);$('#gen-stats-week').text(parsed.week);$('#gen-stats-day').text(parsed.day);}else alertify.delay(4000).error(`Could not load alt stats. Details:
`+parsed.errorMessage);}};xhttp.withCredentials=true;xhttp.open("GET","https://api.thealtening.com/alts/stats",true);xhttp.send(null);}
function isEmptyObject(obj){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key)){return false;}}
return true;}
function objectSize(obj){var i=0;for(var key in obj){i++}
return i;}
function datediff(first,second){return{days:Math.round((second-first)/(1000*60*60*24)),hours:Math.round((second-first)/(1000*60*60)),minutes:Math.round((second-first)/(1000*60))}}
function generatorAddAccount(username,token,skin,cape,ignoreHistory,inc,info){currentToken=token;$('#generator_username').val(username);$('#generator_token').val(token);$('#generator_display_username').text(username);$('#generator-display-body').attr("src","https://cdn.thealtening.com/skins/body/"+skin+".png");$('#details-button-holder').css("display",'block');$('#details-fav-button').off('click');$('#details-fav-button').on('click',function(){doAddFavorite(token,true);});$('#details-priv-button').off('click');$('#details-priv-button').on('click',function(){doAddPrivate(token,true);});if(typeof info=="string")info=JSON.parse(decodeURIComponent(info));revealInfoBox(info);if(license=='premium'||license=='platinum')revealBanBox(token);if(license=='premium'||license=='platinum')setBanQueueState('none');$('#alt-expired-container').css('display','none');$('#alt-expires-container').css('display','none');var xhttp=new XMLHttpRequest();xhttp.onreadystatechange=function(){if(this.readyState==4){var parsed=true;var parsedData;try{parsedData=JSON.parse(this.responseText);}catch(e){parsed=false;}
if(this.status==200&&parsed){if(currentToken==parsedData.token){if(parsedData.expired===true){$('#alt-expires-container').css('display','none');$('#alt-expired-container').css('display','inline-block');}else{var expiresDate=new Date(parsedData.expires);var expiresCheckInterval=setInterval(function(){if(currentToken!=parsedData.token){clearInterval(expiresCheckInterval);return;}else{var timeDifferenceText='in ';var timeDifferenceValue=datediff(Date.now(),expiresDate);if(timeDifferenceValue.days>0){timeDifferenceText+=timeDifferenceValue.days+` Day${timeDifferenceValue.days>1?'s':''}`}else if(timeDifferenceValue.hours>0){timeDifferenceText+=timeDifferenceValue.hours+` Hour${timeDifferenceValue.hours>1?'s':''}`}else if(timeDifferenceValue.minutes>0){timeDifferenceText+=timeDifferenceValue.minutes+` Minute${timeDifferenceValue.minutes>1?'s':''}`}else{$('#alt-expires-container').css('display','none');$('#alt-expired-container').css('display','inline-block');clearInterval(expiresCheckInterval);return;}
$('#alt-expires-timer-text').text(timeDifferenceText);}},500);setTimeout(function(){$('#alt-expired-container').css('display','none');$('#alt-expires-container').css('display','inline-block');},500);}}}}};xhttp.withCredentials=true;xhttp.open("POST","https://api.thealtening.com/alts/expirationinformation",true);xhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhttp.send(JSON.stringify({token:token}));if(info&&!isEmptyObject(info)){$('#cape-display-text').css('color','#32ccaa');$('#cape-display-text').css('cursor','pointer');$('#cape-display-text-attention').text(objectSize(info));$('#cape-display-text-attention').css('display','inline');var special=false;if(info['hypixel.rank']||info['mineplex.rank']||(cape&&cape!="[premium]"&&cape!="none"))special=true;if(special)$('#cape-display-text-attention').addClass('pulse');else $('#cape-display-text-attention').removeClass('pulse');$('#cape-display-button').unbind('click');$("#cape-display-button").on("click",function(){revealInfoBox(info,true);});}else{$('#cape-display-text').css('color','#32ccaa8c');$('#cape-display-text').css('cursor','default');$('#cape-display-text-attention').css('display','none');$('#cape-display-button').unbind('click');}
$('#bans-display-text').unbind('click');$("#bans-display-text").on("click",function(){revealBanBox(token,true);})
if(inc){$('#gen-stats-day').text(parseInt($('#gen-stats-day').text())+1);$('#gen-stats-week').text(parseInt($('#gen-stats-week').text())+1);$('#gen-stats-month').text(parseInt($('#gen-stats-month').text())+1);$('#gen-stats-lifetime').text(parseInt($('#gen-stats-lifetime').text())+1);}
if(!ignoreHistory)generatorAddToHistory(token,username,skin,cape,true,true,info);if(license=='starter')$("#cape-display-button").on("click",function(){revealInfoBox(info,true);});}
function generatorCopyTokenDetails(mode,id){try{if(mode=='token')clipboard.writeText($('#generator_token').val());if(mode=='name')clipboard.writeText($('#generator_username').val());if(mode=='all')clipboard.writeText($('#generator_token').val()+":anything");$('#'+id).text("Copied!");setTimeout(function(){$('#'+id).text("Copy");},1250);}catch(ex){$('#'+id).text("Error!");setTimeout(function(){$('#'+id).text("Copy");},1250);}}
var generatorHistoryItems=[];function generatorAddToHistory(token,username,skin,cape,valid,animate,info){var tokenRaw=encodeURI(token);var usernameRaw=username;token="hist-"+token.replace('@','').replace('.','').replace('-','');if(generatorHistoryItems.length>=historyCount){var last=generatorHistoryItems.shift();$('#'+last).addClass('animated fadeOutRight');setTimeout(function(){try{var element=document.getElementById(last);element.parentElement.removeChild(element);}catch(ex){setTimeout(function(){var element=document.getElementById(last);element.parentElement.removeChild(element);},1000);}},400);}
generatorHistoryItems.push(token);var cssAdd="";var imgAdd="";var roundAdd="";if(animate)cssAdd=" animated fadeInLeft";if(!valid)username=`${username} (broken)`;if(!valid)imgAdd=" broken-img";if(!valid)roundAdd=" broken-round";setTimeout(function(){$('#window-history-holder').html('