Adds semi-broken account switcher
This commit is contained in:
parent
16694653b5
commit
03173a35e4
8 changed files with 130 additions and 45 deletions
|
@ -29,7 +29,6 @@ class channel{
|
||||||
this.type=JSON.type;
|
this.type=JSON.type;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.headers=this.owner.headers;
|
this.headers=this.owner.headers;
|
||||||
console.log(this.headers)
|
|
||||||
this.messages=[];
|
this.messages=[];
|
||||||
this.name=JSON.name;
|
this.name=JSON.name;
|
||||||
this.id=JSON.id;
|
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",{
|
await fetch(info.api.toString()+"/channels/"+this.id+"/messages?before="+this.messages[this.messages.length-1].id+"&limit=100",{
|
||||||
method:"GET",
|
method:"GET",
|
||||||
headers:{Authorization:token}
|
headers:this.headers
|
||||||
}).then((j)=>{return j.json()}).then(function(responce){
|
}).then((j)=>{return j.json()}).then(responce=>{
|
||||||
//messages.innerHTML = '';
|
//messages.innerHTML = '';
|
||||||
//responce.reverse()
|
//responce.reverse()
|
||||||
let next
|
let next
|
||||||
|
@ -449,7 +448,7 @@ class channel{
|
||||||
this.typing=new Date().getTime()+6000;
|
this.typing=new Date().getTime()+6000;
|
||||||
fetch(info.api.toString()+"/channels/"+this.id+"/typing",{
|
fetch(info.api.toString()+"/channels/"+this.id+"/typing",{
|
||||||
method:"POST",
|
method:"POST",
|
||||||
headers:{Authorization:token}
|
headers:this.headers
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
messageCreate(messagep,focus){
|
messageCreate(messagep,focus){
|
||||||
|
|
|
@ -3,7 +3,7 @@ class dirrect extends guild{
|
||||||
super(-1);
|
super(-1);
|
||||||
console.log(JSON);
|
console.log(JSON);
|
||||||
this.owner=owner;
|
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){
|
if(!this.owner){
|
||||||
console.error("Owner was not included, please fix")
|
console.error("Owner was not included, please fix")
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ class group extends channel{
|
||||||
document.getElementById("channelname").innerText="@"+this.name;
|
document.getElementById("channelname").innerText="@"+this.name;
|
||||||
}
|
}
|
||||||
messageCreate(messagep,focus){
|
messageCreate(messagep,focus){
|
||||||
const messagez=new cmessage(messagep.d);
|
const messagez=new cmessage(messagep.d,this);
|
||||||
this.lastmessageid=messagez.id;
|
this.lastmessageid=messagez.id;
|
||||||
if(messagez.author===this.owner.owner.user){
|
if(messagez.author===this.owner.owner.user){
|
||||||
this.lastreadmessageid=messagez.id;
|
this.lastreadmessageid=messagez.id;
|
||||||
|
|
|
@ -32,7 +32,7 @@ class guild{
|
||||||
}
|
}
|
||||||
console.log(JSON);
|
console.log(JSON);
|
||||||
this.owner=owner;
|
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){
|
if(!this.owner){
|
||||||
console.error("Owner was not included, please fix")
|
console.error("Owner was not included, please fix")
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ class guild{
|
||||||
return this.member.hasRole(r);
|
return this.member.hasRole(r);
|
||||||
}
|
}
|
||||||
loadChannel(ID){
|
loadChannel(ID){
|
||||||
if(ID){
|
if(ID&&this.channelids[ID]){
|
||||||
this.channelids[ID].getHTML();
|
this.channelids[ID].getHTML();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<script src="/fullscreen.js"></script>
|
<script src="/fullscreen.js"></script>
|
||||||
|
|
||||||
<div id="loading" class="loading"><div id="centerdiv"><img src="/bitmap.svg" width="1in" height="1in"><h1>Jank Client is loading</h1><h2>This shouldn't take long</h2></div></div>
|
<div id="loading" class="loading"><div id="centerdiv"><img src="/bitmap.svg" width="1in" height="1in"><h1>Jank Client is loading</h1><h2>This shouldn't take long</h2></div></div>
|
||||||
<table id="page">
|
<table id="page" cellspacing="0" cellpadding="0">
|
||||||
<tr>
|
<tr>
|
||||||
<td rowspan="2" id="neunence">
|
<td rowspan="2" id="neunence">
|
||||||
<div id="servers"></div>
|
<div id="servers"></div>
|
||||||
|
|
|
@ -14,12 +14,11 @@ const users=getBulkUsers();
|
||||||
if(!users.currentuser){
|
if(!users.currentuser){
|
||||||
window.location.href = '/login.html';
|
window.location.href = '/login.html';
|
||||||
}
|
}
|
||||||
const info=users.users[users.currentuser].serverurls;
|
var info=users.users[users.currentuser].serverurls;
|
||||||
console.log(users)
|
|
||||||
let token=users.users[users.currentuser].token;
|
let token=users.users[users.currentuser].token;
|
||||||
let READY;
|
let READY;
|
||||||
|
|
||||||
let thisuser=new localuser({token:token});
|
let thisuser=new localuser(users.users[users.currentuser]);
|
||||||
thisuser.initwebsocket().then(_=>{
|
thisuser.initwebsocket().then(_=>{
|
||||||
thisuser.loaduser();
|
thisuser.loaduser();
|
||||||
thisuser.init();
|
thisuser.init();
|
||||||
|
@ -27,7 +26,80 @@ thisuser.initwebsocket().then(_=>{
|
||||||
document.getElementById("loading").classList.remove("loading");
|
document.getElementById("loading").classList.remove("loading");
|
||||||
console.log("done 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="";
|
var currentmenu="";
|
||||||
document.addEventListener('click', function(event) {
|
document.addEventListener('click', function(event) {
|
||||||
if(currentmenu==""){
|
if(currentmenu==""){
|
||||||
|
@ -183,10 +255,7 @@ async function enter(event){
|
||||||
if(editing){
|
if(editing){
|
||||||
fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages/"+editing,{
|
fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages/"+editing,{
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: thisuser.headers,
|
||||||
"Content-type": "application/json; charset=UTF-8",
|
|
||||||
Authorization:token
|
|
||||||
},
|
|
||||||
body:JSON.stringify({content:typebox.value})
|
body:JSON.stringify({content:typebox.value})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -217,10 +286,7 @@ async function enter(event){
|
||||||
console.log(body)
|
console.log(body)
|
||||||
fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages",{
|
fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages",{
|
||||||
method:"POST",
|
method:"POST",
|
||||||
headers:{
|
headers:thisuser.headers,
|
||||||
"Content-type": "application/json; charset=UTF-8",
|
|
||||||
Authorization:token,
|
|
||||||
},
|
|
||||||
body:JSON.stringify(body)
|
body:JSON.stringify(body)
|
||||||
}).then(
|
}).then(
|
||||||
function(out){
|
function(out){
|
||||||
|
@ -247,9 +313,7 @@ async function enter(event){
|
||||||
console.log((await fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages", {
|
console.log((await fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages", {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
headers:{
|
headers:{"Authorization":thisuser.token}
|
||||||
"Authorization":token,
|
|
||||||
}
|
|
||||||
})));
|
})));
|
||||||
//fetch("/sendimagemessage",{body:formData,method:"POST"})
|
//fetch("/sendimagemessage",{body:formData,method:"POST"})
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,9 @@ class localuser{
|
||||||
constructor(userinfo){
|
constructor(userinfo){
|
||||||
this.token=userinfo.token;
|
this.token=userinfo.token;
|
||||||
this.userinfo=userinfo;
|
this.userinfo=userinfo;
|
||||||
|
this.serverurls=this.userinfo.serverurls;
|
||||||
this.initialized=false;
|
this.initialized=false;
|
||||||
|
this.headers={"Content-type": "application/json; charset=UTF-8",Authorization:this.userinfo.token};
|
||||||
}
|
}
|
||||||
gottenReady(ready){
|
gottenReady(ready){
|
||||||
this.initialized=true;
|
this.initialized=true;
|
||||||
|
@ -10,6 +12,8 @@ class localuser{
|
||||||
this.guilds=[];
|
this.guilds=[];
|
||||||
this.guildids={};
|
this.guildids={};
|
||||||
this.user=new user(ready.d.user);
|
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.status=this.ready.d.user_settings.status;
|
||||||
this.channelfocus=null;
|
this.channelfocus=null;
|
||||||
this.lookingguild=null;
|
this.lookingguild=null;
|
||||||
|
@ -29,7 +33,6 @@ class localuser{
|
||||||
this.guildids[temp.guild_id].giveMember(temp);
|
this.guildids[temp.guild_id].giveMember(temp);
|
||||||
}
|
}
|
||||||
for(const thing of ready.d.read_state.entries){
|
for(const thing of ready.d.read_state.entries){
|
||||||
console.log(thing)
|
|
||||||
const guild=this.resolveGuildidFromChannelID(thing.id)
|
const guild=this.resolveGuildidFromChannelID(thing.id)
|
||||||
if(guild===undefined){
|
if(guild===undefined){
|
||||||
continue
|
continue
|
||||||
|
@ -57,7 +60,7 @@ class localuser{
|
||||||
async initwebsocket(){
|
async initwebsocket(){
|
||||||
let returny=null
|
let returny=null
|
||||||
const promise=new Promise((res)=>{returny=res});
|
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) => {
|
this.ws.addEventListener('open', (event) => {
|
||||||
console.log('WebSocket connected');
|
console.log('WebSocket connected');
|
||||||
this.ws.send(JSON.stringify({
|
this.ws.send(JSON.stringify({
|
||||||
|
@ -228,7 +231,10 @@ class localuser{
|
||||||
return this.lookingguild.isAdmin();
|
return this.lookingguild.isAdmin();
|
||||||
}
|
}
|
||||||
loadGuild(id){
|
loadGuild(id){
|
||||||
const guild=this.guildids[id];
|
let guild=this.guildids[id];
|
||||||
|
if(!guild){
|
||||||
|
guild=this.guildids["@me"];
|
||||||
|
}
|
||||||
this.lookingguild=guild;
|
this.lookingguild=guild;
|
||||||
document.getElementById("serverName").innerText=guild.properties.name;
|
document.getElementById("serverName").innerText=guild.properties.name;
|
||||||
//console.log(this.guildids,id)
|
//console.log(this.guildids,id)
|
||||||
|
@ -344,10 +350,7 @@ class localuser{
|
||||||
}
|
}
|
||||||
fetch(info.api.toString()+"/v9/invites/"+parsed,{
|
fetch(info.api.toString()+"/v9/invites/"+parsed,{
|
||||||
method:"POST",
|
method:"POST",
|
||||||
headers:{
|
headers:this.headers,
|
||||||
"Content-type": "application/json; charset=UTF-8",
|
|
||||||
Authorization:token
|
|
||||||
},
|
|
||||||
}).then(r=>r.json()).then(_=>{
|
}).then(r=>r.json()).then(_=>{
|
||||||
console.log(_);
|
console.log(_);
|
||||||
if(_.message){
|
if(_.message){
|
||||||
|
@ -411,10 +414,7 @@ class localuser{
|
||||||
reader.onload = function () {
|
reader.onload = function () {
|
||||||
fetch(info.api.toString()+"/v9/users/@me",{
|
fetch(info.api.toString()+"/v9/users/@me",{
|
||||||
method:"PATCH",
|
method:"PATCH",
|
||||||
headers:{
|
headers:this.headers,
|
||||||
"Content-type": "application/json; charset=UTF-8",
|
|
||||||
Authorization:token
|
|
||||||
},
|
|
||||||
body:JSON.stringify({
|
body:JSON.stringify({
|
||||||
avatar:reader.result,
|
avatar:reader.result,
|
||||||
})
|
})
|
||||||
|
@ -426,10 +426,7 @@ class localuser{
|
||||||
updatepronouns(pronouns){
|
updatepronouns(pronouns){
|
||||||
fetch(info.api.toString()+"/v9/users/@me/profile",{
|
fetch(info.api.toString()+"/v9/users/@me/profile",{
|
||||||
method:"PATCH",
|
method:"PATCH",
|
||||||
headers:{
|
headers:this.headers,
|
||||||
"Content-type": "application/json; charset=UTF-8",
|
|
||||||
Authorization:token
|
|
||||||
},
|
|
||||||
body:JSON.stringify({
|
body:JSON.stringify({
|
||||||
pronouns:pronouns,
|
pronouns:pronouns,
|
||||||
})
|
})
|
||||||
|
@ -438,10 +435,7 @@ class localuser{
|
||||||
updatebio(bio){
|
updatebio(bio){
|
||||||
fetch(info.api.toString()+"/v9/users/@me/profile",{
|
fetch(info.api.toString()+"/v9/users/@me/profile",{
|
||||||
method:"PATCH",
|
method:"PATCH",
|
||||||
headers:{
|
headers:this.headers,
|
||||||
"Content-type": "application/json; charset=UTF-8",
|
|
||||||
Authorization:token
|
|
||||||
},
|
|
||||||
body:JSON.stringify({
|
body:JSON.stringify({
|
||||||
bio:bio,
|
bio:bio,
|
||||||
})
|
})
|
||||||
|
|
|
@ -34,7 +34,6 @@ function setDefaults(){
|
||||||
setDefaults();
|
setDefaults();
|
||||||
class specialuser{
|
class specialuser{
|
||||||
constructor(json){
|
constructor(json){
|
||||||
console.log(json)
|
|
||||||
if(typeof json==="specialuser"){
|
if(typeof json==="specialuser"){
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
@ -52,6 +51,7 @@ class specialuser{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set pfpsrc(e){
|
set pfpsrc(e){
|
||||||
|
console.log("this ran fr")
|
||||||
this.json.pfpsrc=e;
|
this.json.pfpsrc=e;
|
||||||
this.updateLocal();
|
this.updateLocal();
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ class specialuser{
|
||||||
set username(e){
|
set username(e){
|
||||||
this.json.username=e;
|
this.json.username=e;
|
||||||
this.updateLocal();
|
this.updateLocal();
|
||||||
}
|
}
|
||||||
get username(){
|
get username(){
|
||||||
return this.json.username;
|
return this.json.username;
|
||||||
}
|
}
|
||||||
|
|
|
@ -562,6 +562,7 @@ textarea {
|
||||||
#userdock {
|
#userdock {
|
||||||
background-color: var(--user-dock-bg);
|
background-color: var(--user-dock-bg);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
#settings {
|
#settings {
|
||||||
|
@ -579,8 +580,10 @@ textarea {
|
||||||
}
|
}
|
||||||
|
|
||||||
#userinfo {
|
#userinfo {
|
||||||
|
position:relative;
|
||||||
background-color: var(--user-info-bg);
|
background-color: var(--user-info-bg);
|
||||||
border-radius: .1in;
|
border-radius: .1in;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.servernamediv {
|
.servernamediv {
|
||||||
|
@ -773,4 +776,29 @@ span {
|
||||||
}
|
}
|
||||||
.tabbed-head td button{
|
.tabbed-head td button{
|
||||||
min-width:1.5in;
|
min-width:1.5in;
|
||||||
}
|
}
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue