chrome.storage.local.get(["uni_code"],function(a){void 0!==a.uni_code&&a.uni_code&&""!=a.uni_code&&loginByUniCode(a.uni_code)});function loginByUniCode(a){$.ajax({method:"POST",url:endpoint+"loginByUniCode",data:{uni_code:a},success:function(c,b,e){1==c.status&&Store.set({login:c.token})},statusCode:{500:function(c){},401:function(){},422:function(c){}}})}
function pn(a="Something went wrong!",c="error"){(new Noty({type:c,layout:"topRight",theme:"sunset",timeout:3E3,closeWith:["click","button"],text:a})).show()}
$(document).ready(function(){$(document).on("click",".forgot-password",function(){$("form input").val("");$(".forgot-password").text("Login").addClass("login-form-a").removeClass("forgot-password");$("form").slideUp();$(".td-forgot").slideDown()});$(document).on("click",".login-form-a",function(){$("form input").val("");$(".login-form-a").text("Forgot password").removeClass("login-form-a").addClass("forgot-password");$("form").slideUp();$(".td-login").slideDown()});$(document).on("click",".sign-up-btn",
function(){$("form input").val("");$(".sign-up-btn").text("Login").addClass("login-form").removeClass("sign-up-btn");$("form").slideUp();$("form").slideUp();$(".td-register").slideDown()});$(document).on("click",".login-form",function(){$("form input").val("");$(".login-form").text("Sign Up").removeClass("login-form").addClass("sign-up-btn");$("form").slideUp();$(".td-login").slideDown()});$(".login-btn").click(function(){$("form.td-login").submit()});$(".td-login").validate({rules:{password:"required",
email:{required:!0,email:!0}},submitHandler:function(a){let c=document.querySelector(".td-login #email").value.trim();a=document.querySelector(".td-login #password").value.trim();$(".login-btn").prop("disabled",!0);$(".login-btn").text("Please wait");$.ajax({method:"POST",url:endpoint+"loginext",data:{email:c,password:a,number:chrome.runtime.getManifest().version},success:function(b,e,d){$(".login-btn").prop("disabled",!1);$(".login-btn").text("Login");0==b.status?(Store.set({login:!1}),pn(b.message,
"error"),-1<b.message.indexOf("unverified")&&($(".login-jug form").slideUp(),$(".login-jug form.td-re-verify-email #email").val(c),$("form.td-re-verify-email").slideDown(),$(".re-verify-email-btn-1").show(),$(".re-verify-email-btn-2").hide())):autoLoginUser(b)},statusCode:{500:function(b){Store.set({login:!1});pn("","error")},401:function(){Store.set({login:!1});pn("","error")},422:function(b){Store.set({login:!1});$(".login-btn").prop("disabled",!1);$(".login-btn").text("Login");pn(b.responseJSON.error,
"error")}}})}});$(".register-btn").click(function(){$("form.td-register").submit()});$(".td-register").validate({rules:{name:"required",password:"required",company:"required",email:{required:!0,email:!0}},submitHandler:function(a){let c=document.querySelector(".td-register #email").value.trim();a=document.querySelector(".td-register #password").value.trim();let b=document.querySelector(".td-register #name").value.trim(),e=document.querySelector(".td-register #company").value.trim();$(".register-btn").prop("disabled",
!0);$(".register-btn").text("Please wait");$.ajax({method:"POST",url:endpoint+"adduser",data:{name:b,email:c,password:a,company:e,number:chrome.runtime.getManifest().version},success:function(d,f,h){$(".register-btn").prop("disabled",!1);$(".register-btn").text("Submit");if(0==d.status)Store.set({login:!1}),pn(d.message,"error");else if(1==d.status){Store.set({login:!1});$(".td-email-verify #email").val(c);$(".sign-up-btn").text("Login").addClass("login-form").removeClass("sign-up-btn");pn(d.message,
"success");$(".td-register").slideUp();$(".td-email-verify").slideDown();for(let g=45;0<=g;g--)setTimeout(()=>{45==g?$(".get-re-otp").prop("disabled",!1).text("Resend Code"):$(".get-re-otp").prop("disabled",!0).text("Resend Code in "+(45-g)+"s")},1E3*g)}},statusCode:{500:function(d){Store.set({login:!1});pn("","error")},401:function(){Store.set({login:!1});pn("","error")},404:function(){Store.set({login:!1});pn("Api not found.","error")},422:function(d){Store.set({login:!1});$(".register-btn").prop("disabled",
!1);$(".register-btn").text("Submit");pn(d.responseJSON.error,"error")}}})}});$(document).on("click",".get-re-otp",function(){$(".get-re-otp").prop("disabled",!0);let a=document.querySelector(".td-register #email").value.trim();$.ajax({method:"POST",url:endpoint+"getemailpinresend",data:{email:a,number:chrome.runtime.getManifest().version},success:function(c,b,e){$(".get-re-otp").prop("disabled",!1);if(1==c.status){pn(c.message,"success");for(let d=45;0<=d;d--)setTimeout(()=>{45==d?$(".get-re-otp").prop("disabled",
!1).text("Resend Code"):$(".get-re-otp").prop("disabled",!0).text("Resend Code in "+(45-d)+"s")},1E3*d)}else Store.set({login:!1}),pn(c.message,"error")},statusCode:{500:function(c){Store.set({login:!1});pn("","error")},401:function(){Store.set({login:!1});pn("","error")},422:function(c){Store.set({login:!1});$(".login-btn").prop("disabled",!1);$(".login-btn").text("Login");pn(c.responseJSON.error,"error")}}})});$(".forgot-btn, .resend-forgot-password").click(function(){$("form.td-forgot").submit()});
$(".td-forgot").validate({rules:{email:{required:!0,email:!0}},submitHandler:function(a){let c=document.querySelector(".td-forgot #email").value.trim();$(".forgot-btn").prop("disabled",!0);$(".forgot-btn").text("Please wait");$.ajax({method:"POST",url:endpoint+"sendPin",data:{email:c,number:chrome.runtime.getManifest().version},success:function(b,e,d){$(".forgot-btn").prop("disabled",!1);$(".forgot-btn").text("Send");if(0==b.status)Store.set({login:!1}),pn(b.message,"error");else{$("form.td-forgot").slideUp();
$("form.td-set-new-password").slideDown();$("form.td-set-new-password #email").val(c);pn(b.message,"success");$(".resend-forgot-password").text("Resend Code in 45s");for(let f=45;0<=f;f--)setTimeout(()=>{45==f?$(".resend-forgot-password").prop("disabled",!1).text("Resend Code"):$(".resend-forgot-password").prop("disabled",!0).text("Resend Code in "+(45-f)+"s")},1E3*f)}},statusCode:{500:function(b){Store.set({login:!1});pn("","error")},401:function(){Store.set({login:!1});pn("","error")},422:function(b){Store.set({login:!1});
$(".login-btn").prop("disabled",!1);$(".login-btn").text("Login");pn(b.responseJSON.error,"error")}}})}});$(".setnew-password-btn").click(function(){$("form.td-set-new-password").submit()});$(".td-set-new-password").validate({rules:{pin:"required",password:{required:!0,minlength:6},email:{required:!0,email:!0}},submitHandler:function(a){a=document.querySelector(".td-set-new-password #email").value.trim();let c=document.querySelector(".td-set-new-password #pin").value.trim(),b=document.querySelector(".td-set-new-password #password").value.trim();
$(".setnew-password-btn").prop("disabled",!0);$(".setnew-password-btn").text("Please wait");$.ajax({method:"POST",url:endpoint+"verifypin",data:{email:a,pin:c,password:b,number:chrome.runtime.getManifest().version},success:function(e,d,f){$(".setnew-password-btn").prop("disabled",!1);$(".setnew-password-btn").text("Set as new password");0==e.status?(Store.set({login:!1}),pn(e.message,"error")):(document.querySelector(".td-forgot #email").value="",$("form.td-forgot").slideDown(),$("form.td-set-new-password").slideUp(),
$("form.td-set-new-password #email").val(""),pn(e.message,"success"))},statusCode:{500:function(e){Store.set({login:!1});pn("","error")},401:function(){Store.set({login:!1});pn("","error")},422:function(e){Store.set({login:!1});$(".login-btn").prop("disabled",!1);$(".login-btn").text("Login");pn(e.responseJSON.error,"error")}}})}});$(".verify-email-btn").click(function(){$("form.td-email-verify").submit()});$(".td-email-verify").validate({rules:{pin:"required",email:{required:!0,email:!0}},submitHandler:function(a){a=
document.querySelector(".td-email-verify #email").value.trim();let c=document.querySelector(".td-email-verify #pin").value.trim();$(".verify-email-btn").prop("disabled",!0);$(".verify-email-btn").text("Please wait");$.ajax({method:"POST",url:endpoint+"verifyemailpin",data:{email:a,pin:c,number:chrome.runtime.getManifest().version},success:function(b,e,d){$(".verify-email-btn").prop("disabled",!1);$(".verify-email-btn").text("Verify");0==b.status?(Store.set({login:!1}),pn(b.message,"error")):($("form.td-email-verify").slideUp(),
$("form.td-login").slideDown(),$("form input").val(""),$(".login-form").text("Sign Up").removeClass("login-form").addClass("sign-up-btn"),pn(b.message,"success"),autoLoginUser(b))},statusCode:{500:function(b){Store.set({login:!1});pn("","error")},401:function(){Store.set({login:!1});pn("","error")},422:function(b){Store.set({login:!1})}}})}});$(document).on("click",".re-verify-email-btn-1",function(){$(".re-verify-email-btn-1").text("Please wait");$(".re-verify-email-btn-1").prop("disabled",!0);$.ajax({method:"POST",
url:endpoint+"getemailpin",data:{email:$(".td-re-verify-email #email").val().trim(),number:chrome.runtime.getManifest().version},success:function(a,c,b){$(".re-verify-email-btn-1").prop("disabled",!1);$(".re-verify-email-btn-1").hide();1==a.status?(pn(a.message,"success"),$(".repin-group").show(),$(".re-verify-email-btn-2").show()):(Store.set({login:!1}),pn(a.message,"error"))},statusCode:{500:function(a){Store.set({login:!1});pn("","error")},401:function(){Store.set({login:!1});pn("","error")},422:function(a){Store.set({login:!1});
$(".login-btn").prop("disabled",!1);$(".login-btn").text("Login");pn(a.responseJSON.error,"error")}}})});$(document).on("click",".re-verify-email-btn-2",function(){$(".re-verify-email-btn-2").text("Please wait");$(".re-verify-email-btn-2").prop("disabled",!0);$.ajax({method:"POST",url:endpoint+"verifyemailpin2",data:{email:$(".td-re-verify-email #email").val().trim(),pin:$(".td-re-verify-email #repin").val().trim(),number:chrome.runtime.getManifest().version},success:function(a,c,b){$(".re-verify-email-btn-2").prop("disabled",
!1);1==a.status?($(".re-verify-email-btn-1").show(),$(".re-verify-email-btn-2").hide(),$(".td-re-verify-email").slideUp(),$(".td-login").slideDown(),pn(a.message,"success"),$(".repin-group").hide(),$(".login-btn").click()):(Store.set({login:!1}),pn(a.message,"error"))},statusCode:{500:function(a){Store.set({login:!1});pn("","error")},401:function(){Store.set({login:!1});pn("","error")},422:function(a){Store.set({login:!1});$(".login-btn").prop("disabled",!1);$(".login-btn").text("Login");pn(a.responseJSON.error,
"error")}}})})});function autoLoginUser(a){Store.set({login:a.token});Store.set({name:a.data.name});Store.set({email:a.data.email});Store.set({uni_code:a.data.uni_code});Store.set({company:a.data.company});Store.set({bio:a.data.bio});setTimeout(()=>{chrome.runtime.sendMessage({prefeed:!0})},100);pn(a.message,"success");setTimeout(()=>{window.location.href=chrome.runtime.getURL("src/index.html")},1200);Store.set({image:a.data.image})};
