diff --git a/webpage/channel.js b/webpage/channel.js index 59a427a..3cc8f74 100644 --- a/webpage/channel.js +++ b/webpage/channel.js @@ -29,7 +29,6 @@ class channel{ this.type=JSON.type; this.owner=owner; this.headers=this.owner.headers; - console.log(this.headers) this.messages=[]; this.name=JSON.name; this.id=JSON.id; @@ -383,8 +382,8 @@ class channel{ await fetch(info.api.toString()+"/channels/"+this.id+"/messages?before="+this.messages[this.messages.length-1].id+"&limit=100",{ method:"GET", - headers:{Authorization:token} - }).then((j)=>{return j.json()}).then(function(responce){ + headers:this.headers + }).then((j)=>{return j.json()}).then(responce=>{ //messages.innerHTML = ''; //responce.reverse() let next @@ -449,7 +448,7 @@ class channel{ this.typing=new Date().getTime()+6000; fetch(info.api.toString()+"/channels/"+this.id+"/typing",{ method:"POST", - headers:{Authorization:token} + headers:this.headers }) } messageCreate(messagep,focus){ diff --git a/webpage/dirrect.js b/webpage/dirrect.js index b45a45e..4143a1f 100644 --- a/webpage/dirrect.js +++ b/webpage/dirrect.js @@ -3,7 +3,7 @@ class dirrect extends guild{ super(-1); console.log(JSON); this.owner=owner; - this.headers={"Content-type": "application/json; charset=UTF-8",Authorization:this.owner.userinfo.token}; + this.headers=this.owner.headers; if(!this.owner){ console.error("Owner was not included, please fix") } @@ -99,7 +99,7 @@ class group extends channel{ document.getElementById("channelname").innerText="@"+this.name; } messageCreate(messagep,focus){ - const messagez=new cmessage(messagep.d); + const messagez=new cmessage(messagep.d,this); this.lastmessageid=messagez.id; if(messagez.author===this.owner.owner.user){ this.lastreadmessageid=messagez.id; diff --git a/webpage/guild.js b/webpage/guild.js index 3245680..ba6a226 100644 --- a/webpage/guild.js +++ b/webpage/guild.js @@ -32,7 +32,7 @@ class guild{ } console.log(JSON); this.owner=owner; - this.headers={"Content-type": "application/json; charset=UTF-8",Authorization:this.owner.userinfo.token}; + this.headers=this.owner.headers; if(!this.owner){ console.error("Owner was not included, please fix") } @@ -202,7 +202,7 @@ class guild{ return this.member.hasRole(r); } loadChannel(ID){ - if(ID){ + if(ID&&this.channelids[ID]){ this.channelids[ID].getHTML(); return; } diff --git a/webpage/index.html b/webpage/index.html index b855ca2..e5cc364 100644 --- a/webpage/index.html +++ b/webpage/index.html @@ -23,7 +23,7 @@
diff --git a/webpage/index.js b/webpage/index.js index 6f840c9..9787740 100644 --- a/webpage/index.js +++ b/webpage/index.js @@ -14,12 +14,11 @@ const users=getBulkUsers(); if(!users.currentuser){ window.location.href = '/login.html'; } -const info=users.users[users.currentuser].serverurls; -console.log(users) +var info=users.users[users.currentuser].serverurls; let token=users.users[users.currentuser].token; let READY; -let thisuser=new localuser({token:token}); +let thisuser=new localuser(users.users[users.currentuser]); thisuser.initwebsocket().then(_=>{ thisuser.loaduser(); thisuser.init(); @@ -27,7 +26,80 @@ thisuser.initwebsocket().then(_=>{ document.getElementById("loading").classList.remove("loading"); console.log("done loading") }); +{ + const userinfo=document.getElementById("userinfo"); + const userdock=document.getElementById("userdock"); + userinfo.addEventListener("click",function(event){ + const table=document.createElement("table"); + for(const thing of Object.values(users.users)){ + console.log(thing.pfpsrc) + const tr=document.createElement("tr"); + const td=document.createElement("td"); + const userinfo=document.createElement("table"); + userinfo.classList.add("switchtable"); + const row=document.createElement("tr"); + userinfo.append(row) + const pfpcell=document.createElement("td"); + row.append(pfpcell); + const pfp=document.createElement("img"); + pfpcell.append(pfp); + + const usertd=document.createElement("td") + row.append(usertd); + const user=document.createElement("div"); + usertd.append(user); + user.append(thing.username); + user.append(document.createElement("br")); + const span=document.createElement("span"); + span.textContent=thing.serverurls.wellknown.hostname; + user.append(span); + span.classList.add("serverURL") + + pfp.src=thing.pfpsrc; + pfp.classList.add("pfp"); + td.append(userinfo) + + tr.append(td); + table.append(tr); + tr.addEventListener("click",_=>{ + thisuser.unload(); + document.getElementById("loading").classList.remove("doneloading"); + document.getElementById("loading").classList.add("loading"); + thisuser=new localuser(thing); + window.info =thing.serverurls; + users.currentuser=thing.uid; + localStorage.setItem("userinfos",JSON.stringify(users)); + thisuser.initwebsocket().then(_=>{ + thisuser.loaduser(); + thisuser.init(); + document.getElementById("loading").classList.add("doneloading"); + document.getElementById("loading").classList.remove("loading"); + console.log("done loading") + + }); + }) + } + { + const tr=document.createElement("tr"); + const td=document.createElement("td"); + tr.append(td); + td.append("Switch accounts ⇌"); + td.addEventListener("click",_=>{ + window.location.href="/login.html"; + }) + table.append(tr); + } + table.classList.add("accountSwitcher"); + if(currentmenu!=""){ + currentmenu.remove(); + } + currentmenu=table; + console.log(table); + userdock.append(table); + event.stopImmediatePropagation(); + }) +} var currentmenu=""; document.addEventListener('click', function(event) { if(currentmenu==""){ @@ -183,10 +255,7 @@ async function enter(event){ if(editing){ fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages/"+editing,{ method: "PATCH", - headers: { - "Content-type": "application/json; charset=UTF-8", - Authorization:token - }, + headers: thisuser.headers, body:JSON.stringify({content:typebox.value}) }) @@ -217,10 +286,7 @@ async function enter(event){ console.log(body) fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages",{ method:"POST", - headers:{ - "Content-type": "application/json; charset=UTF-8", - Authorization:token, - }, + headers:thisuser.headers, body:JSON.stringify(body) }).then( function(out){ @@ -247,9 +313,7 @@ async function enter(event){ console.log((await fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages", { method: 'POST', body: formData, - headers:{ - "Authorization":token, - } + headers:{"Authorization":thisuser.token} }))); //fetch("/sendimagemessage",{body:formData,method:"POST"}) diff --git a/webpage/localuser.js b/webpage/localuser.js index 60ec0b2..d9e97b3 100644 --- a/webpage/localuser.js +++ b/webpage/localuser.js @@ -2,7 +2,9 @@ class localuser{ constructor(userinfo){ this.token=userinfo.token; this.userinfo=userinfo; + this.serverurls=this.userinfo.serverurls; this.initialized=false; + this.headers={"Content-type": "application/json; charset=UTF-8",Authorization:this.userinfo.token}; } gottenReady(ready){ this.initialized=true; @@ -10,6 +12,8 @@ class localuser{ this.guilds=[]; this.guildids={}; this.user=new user(ready.d.user); + this.userinfo.username=this.user.username; + this.userinfo.pfpsrc=this.user.getpfpsrc(); this.status=this.ready.d.user_settings.status; this.channelfocus=null; this.lookingguild=null; @@ -29,7 +33,6 @@ class localuser{ this.guildids[temp.guild_id].giveMember(temp); } for(const thing of ready.d.read_state.entries){ - console.log(thing) const guild=this.resolveGuildidFromChannelID(thing.id) if(guild===undefined){ continue @@ -57,7 +60,7 @@ class localuser{ async initwebsocket(){ let returny=null const promise=new Promise((res)=>{returny=res}); - this.ws = new WebSocket(info.gateway.toString()); + this.ws = new WebSocket(this.serverurls.gateway.toString()); this.ws.addEventListener('open', (event) => { console.log('WebSocket connected'); this.ws.send(JSON.stringify({ @@ -228,7 +231,10 @@ class localuser{ return this.lookingguild.isAdmin(); } loadGuild(id){ - const guild=this.guildids[id]; + let guild=this.guildids[id]; + if(!guild){ + guild=this.guildids["@me"]; + } this.lookingguild=guild; document.getElementById("serverName").innerText=guild.properties.name; //console.log(this.guildids,id) @@ -344,10 +350,7 @@ class localuser{ } fetch(info.api.toString()+"/v9/invites/"+parsed,{ method:"POST", - headers:{ - "Content-type": "application/json; charset=UTF-8", - Authorization:token - }, + headers:this.headers, }).then(r=>r.json()).then(_=>{ console.log(_); if(_.message){ @@ -411,10 +414,7 @@ class localuser{ reader.onload = function () { fetch(info.api.toString()+"/v9/users/@me",{ method:"PATCH", - headers:{ - "Content-type": "application/json; charset=UTF-8", - Authorization:token - }, + headers:this.headers, body:JSON.stringify({ avatar:reader.result, }) @@ -426,10 +426,7 @@ class localuser{ updatepronouns(pronouns){ fetch(info.api.toString()+"/v9/users/@me/profile",{ method:"PATCH", - headers:{ - "Content-type": "application/json; charset=UTF-8", - Authorization:token - }, + headers:this.headers, body:JSON.stringify({ pronouns:pronouns, }) @@ -438,10 +435,7 @@ class localuser{ updatebio(bio){ fetch(info.api.toString()+"/v9/users/@me/profile",{ method:"PATCH", - headers:{ - "Content-type": "application/json; charset=UTF-8", - Authorization:token - }, + headers:this.headers, body:JSON.stringify({ bio:bio, }) diff --git a/webpage/login.js b/webpage/login.js index 2b697d6..bf86316 100644 --- a/webpage/login.js +++ b/webpage/login.js @@ -34,7 +34,6 @@ function setDefaults(){ setDefaults(); class specialuser{ constructor(json){ - console.log(json) if(typeof json==="specialuser"){ return json; } @@ -52,6 +51,7 @@ class specialuser{ } } set pfpsrc(e){ + console.log("this ran fr") this.json.pfpsrc=e; this.updateLocal(); } @@ -61,7 +61,7 @@ class specialuser{ set username(e){ this.json.username=e; this.updateLocal(); - } + } get username(){ return this.json.username; } diff --git a/webpage/style.css b/webpage/style.css index 19d16c1..867ef41 100644 --- a/webpage/style.css +++ b/webpage/style.css @@ -562,6 +562,7 @@ textarea { #userdock { background-color: var(--user-dock-bg); width: 100%; + position: relative; } #settings { @@ -579,8 +580,10 @@ textarea { } #userinfo { + position:relative; background-color: var(--user-info-bg); border-radius: .1in; + cursor: pointer; } .servernamediv { @@ -773,4 +776,29 @@ span { } .tabbed-head td button{ min-width:1.5in; -} \ No newline at end of file +} +.accountSwitcher{ + background:var(--profile-bg); + cursor:pointer; + position:absolute; + top:0px; + transform: translate(0, -100%); + width:100%; +} +.accountSwitcher tr{ + transition: background .3s; + background:var(--profile-bg); +} +.accountSwitcher tr:hover{ + background:var(--profile-info-bg); +} +.switchtable tr{ + background-color:transparent; +} +.serverURL{ + color: var(--pronouns); + word-wrap: normal; + word-break: normal; + white-space: nowrap; + font-size: .125in; +} |