adding invites
This commit is contained in:
parent
3e5435668e
commit
3af371e6ab
16 changed files with 670 additions and 30 deletions
|
@ -1,12 +1,13 @@
|
|||
import { Dialog } from "./dialog.js";
|
||||
|
||||
const mobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
||||
export {mobile, getBulkUsers,getBulkInfo,setTheme,Specialuser}
|
||||
export {mobile, getBulkUsers,getBulkInfo,setTheme,Specialuser,getapiurls,adduser}
|
||||
function setTheme(){
|
||||
const name=localStorage.getItem("theme");
|
||||
let name=localStorage.getItem("theme");
|
||||
if(!name){
|
||||
document.body.className="Dark-theme";
|
||||
localStorage.setItem("theme","Dark");
|
||||
name="Dark";
|
||||
}
|
||||
document.body.className=name+"-theme";
|
||||
}
|
||||
|
@ -18,6 +19,7 @@ function getBulkUsers(){
|
|||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
function getBulkInfo(){
|
||||
return JSON.parse(localStorage.getItem("userinfos"));
|
||||
}
|
||||
|
@ -115,12 +117,39 @@ function adduser(user){
|
|||
info.users[user.uid]=user;
|
||||
info.currentuser=user.uid;
|
||||
localStorage.setItem("userinfos",JSON.stringify(info));
|
||||
return user;
|
||||
}
|
||||
const instancein=document.getElementById("instancein");
|
||||
const instancein=document.getElementById("instancein") as HTMLInputElement;
|
||||
let timeout;
|
||||
let instanceinfo;
|
||||
async function checkInstance(e){
|
||||
const verify=document.getElementById("verify");;
|
||||
async function getapiurls(str:string):Promise<{api:string,cdn:string,gateway:string,wellknown:string}|false>{
|
||||
if(str[str.length-1]!=="/"){
|
||||
str+="/"
|
||||
}
|
||||
let api:string;
|
||||
try{
|
||||
const info=await fetch(`${str}/.well-known/spacebar`).then((x) => x.json());
|
||||
api=info.api;
|
||||
}catch{
|
||||
return false
|
||||
}
|
||||
const url = new URL(api);
|
||||
try{
|
||||
|
||||
const info=await fetch(`${api}${url.pathname.includes("api") ? "" : "api"}/policies/instance/domains`).then((x) => x.json());
|
||||
return {
|
||||
api: info.apiEndpoint,
|
||||
gateway: info.gateway,
|
||||
cdn: info.cdn,
|
||||
wellknown: str,
|
||||
};
|
||||
}catch{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
async function checkInstance(e:string){
|
||||
const verify=document.getElementById("verify");
|
||||
try{
|
||||
verify.textContent="Checking Instance";
|
||||
const instanceinfo=await setInstance((instancein as HTMLInputElement).value);
|
||||
|
@ -150,8 +179,8 @@ if(instancein){
|
|||
}else{
|
||||
checkInstance("https://spacebar.chat/");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function login(username:string, password:string, captcha:string){
|
||||
if(captcha===""){
|
||||
|
@ -215,15 +244,27 @@ async function login(username:string, password:string, captcha:string){
|
|||
if(response.message){
|
||||
alert(response.message)
|
||||
}else{
|
||||
adduser({serverurls:JSON.parse(localStorage.getItem("instanceinfo")),email:username,token:response.token});
|
||||
window.location.href = '/channels/@me';
|
||||
console.warn(response);
|
||||
adduser({serverurls:JSON.parse(localStorage.getItem("instanceinfo")),email:username,token:response.token}).username=username;
|
||||
const redir=new URLSearchParams(window.location.search).get("goback");
|
||||
if(redir){
|
||||
window.location.href = redir;
|
||||
}else{
|
||||
window.location.href = '/channels/@me';
|
||||
}
|
||||
}
|
||||
})
|
||||
}]]).show();
|
||||
}else{
|
||||
adduser({serverurls:JSON.parse(localStorage.getItem("instanceinfo")),email:username,token:response.token});
|
||||
window.location.href = '/channels/@me';
|
||||
return response.token;
|
||||
console.warn(response);
|
||||
adduser({serverurls:JSON.parse(localStorage.getItem("instanceinfo")),email:username,token:response.token}).username=username;
|
||||
const redir=new URLSearchParams(window.location.search).get("goback");
|
||||
if(redir){
|
||||
window.location.href = redir;
|
||||
}else{
|
||||
window.location.href = '/channels/@me';
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -292,4 +333,14 @@ if ("serviceWorker" in navigator){
|
|||
})
|
||||
}
|
||||
*/
|
||||
const switchurl=document.getElementById("switch") as HTMLAreaElement;
|
||||
if(switchurl){
|
||||
switchurl.href+=window.location.search;
|
||||
const instance=new URLSearchParams(window.location.search).get("instance");
|
||||
console.log(instance);
|
||||
if(instance){
|
||||
instancein.value=instance;
|
||||
checkInstance("");
|
||||
}
|
||||
}
|
||||
export {checkInstance};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue