diff --git a/webpage/channel.js b/webpage/channel.js index 51a0825..9776b20 100644 --- a/webpage/channel.js +++ b/webpage/channel.js @@ -189,7 +189,7 @@ class channel{ if(!this.hasunreads){ return; } - fetch("https://old.server.spacebar.chat/api/v9/channels/"+this.id+"/messages/"+this.lastmessageid+"/ack",{ + fetch(info.api.toString()+"/v9/channels/"+this.id+"/messages/"+this.lastmessageid+"/ack",{ method:"POST", headers:{"Content-type": "application/json; charset=UTF-8",Authorization:token}, body:JSON.stringify({}) @@ -259,7 +259,7 @@ class channel{ return div; } createChannel(name,type){ - fetch("https://api.old.server.spacebar.chat/api/guilds/"+this.owner.id+"/channels",{ + fetch(info.api.toString()+"/guilds/"+this.owner.id+"/channels",{ method:"Post", headers:{"Content-type": "application/json; charset=UTF-8",Authorization:token}, body:JSON.stringify({ @@ -283,7 +283,7 @@ class channel{ ["mdbox","Channel topic:",this.topic,function(){topic=this.value}], ["checkbox","NSFW Channel",this.nsfw,function(){nsfw=this.checked}], ["button","","submit",function(){ - fetch("https://api.old.server.spacebar.chat/api/v9/channels/"+thisid,{ + fetch(info.api.toString()+"/v9/channels/"+thisid,{ method:"PATCH", headers:{"Content-type": "application/json; charset=UTF-8",Authorization:token}, body:JSON.stringify({ @@ -307,7 +307,7 @@ class channel{ console.log(full) } deleteChannel(){ - fetch("https://api.old.server.spacebar.chat/api/v9/channels/"+this.id,{ + fetch(info.api.toString()+"/v9/channels/"+this.id,{ method:"DELETE", headers:{"Content-type": "application/json; charset=UTF-8",Authorization:token} }) @@ -321,7 +321,7 @@ class channel{ } putmessages(){ const out=this; - fetch("https://api.old.server.spacebar.chat/api/channels/"+this.id+"/messages?limit=100",{ + fetch(info.api.toString()+"/channels/"+this.id+"/messages?limit=100",{ method: 'GET', headers: {Authorization:token}, }).then((j)=>{return j.json()}).then(function(responce){ @@ -353,7 +353,7 @@ class channel{ } const out=this; - await fetch("https://api.old.server.spacebar.chat/api/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", headers:{Authorization:token} }).then((j)=>{return j.json()}).then(function(responce){ @@ -419,7 +419,7 @@ class channel{ return; } this.typing=new Date().getTime()+6000; - fetch("https://api.old.server.spacebar.chat/api/channels/"+this.id+"/typing",{ + fetch(info.api.toString()+"/channels/"+this.id+"/typing",{ method:"POST", headers:{Authorization:token} }) diff --git a/webpage/guild.js b/webpage/guild.js index d5d15c1..ed28b2d 100644 --- a/webpage/guild.js +++ b/webpage/guild.js @@ -73,14 +73,14 @@ class guild{ if(serverbug){ for(const thing of build){ console.log(build,thing) - fetch("https://api.old.server.spacebar.chat/api/v9/guilds/"+this.id+"/channels",{ + fetch(info.api.toString()+"/v9/guilds/"+this.id+"/channels",{ method:"PATCH", headers:{"Content-type": "application/json; charset=UTF-8",Authorization:token}, body:JSON.stringify([thing]) }); } }else{ - fetch("https://api.old.server.spacebar.chat/api/v9/guilds/"+this.id+"/channels",{ + fetch(info.api.toString()+"/v9/guilds/"+this.id+"/channels",{ method:"PATCH", headers:{"Content-type": "application/json; charset=UTF-8",Authorization:token}, body:JSON.stringify(build) @@ -214,7 +214,7 @@ class guild{ this.channels=build; } createChannel(name,type){ - fetch("https://api.old.server.spacebar.chat/api/guilds/"+this.id+"/channels",{ + fetch(info.api.toString()+"/guilds/"+this.id+"/channels",{ method:"Post", headers:{"Content-type": "application/json; charset=UTF-8",Authorization:token}, body:JSON.stringify({name: name, type: type}) diff --git a/webpage/index.js b/webpage/index.js index e718f9f..fdea7ca 100644 --- a/webpage/index.js +++ b/webpage/index.js @@ -1,3 +1,8 @@ +const info=JSON.parse(localStorage.getItem("instanceinfo")); +info.api=new URL(info.api); +info.cdn=new URL(info.cdn); +info.gateway=new URL(info.gateway); +info.wellknown=new URL(info.wellknown); function setDynamicHeight() { var servertdHeight = document.getElementById('servertd').offsetHeight+document.getElementById('typebox').offsetHeight+document.getElementById('pasteimage').offsetHeight; document.documentElement.style.setProperty('--servertd-height', servertdHeight + 'px'); @@ -200,7 +205,7 @@ function makemenu(divmessage,x,y){ const dmbutton=createbutton("Message user",null,function(){ console.log(this) - fetch("https://old.server.spacebar.chat/api/v9/users/@me/channels", + fetch(info.api.toString()+"/v9/users/@me/channels", {method:"POST", body:JSON.stringify({"recipients":[this.all.author.id]}), headers: {"Content-type": "application/json; charset=UTF-8",Authorization:token} @@ -306,7 +311,7 @@ async function enter(event){ if(event.key === "Enter"&&!event.shiftKey){ event.preventDefault(); if(editing){ - fetch("https://api.old.server.spacebar.chat/api/channels/"+window.location.pathname.split("/")[3]+"/messages/"+editing,{ + fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages/"+editing,{ method: "PATCH", headers: { "Content-type": "application/json; charset=UTF-8", @@ -340,7 +345,7 @@ async function enter(event){ body.message_reference=replyjson; } console.log(body) - fetch("https://api.old.server.spacebar.chat/api/channels/"+window.location.pathname.split("/")[3]+"/messages",{ + fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages",{ method:"POST", headers:{ "Content-type": "application/json; charset=UTF-8", @@ -369,7 +374,7 @@ async function enter(event){ } const data=formData.entries() console.log(data.next(),data.next(),data.next()) - console.log((await fetch("https://api.old.server.spacebar.chat/api/channels/"+window.location.pathname.split("/")[3]+"/messages", { + console.log((await fetch(info.api.toString()+"/channels/"+window.location.pathname.split("/")[3]+"/messages", { method: 'POST', body: formData, headers:{ @@ -395,7 +400,7 @@ let thisuser=null; function initwebsocket(){ - ws = new WebSocket('wss://gateway.old.server.spacebar.chat/?v=9&encoding=json'); + ws = new WebSocket(info.gateway.toString()); ws.addEventListener('open', (event) => { console.log('WebSocket connected'); @@ -649,10 +654,7 @@ function genusersettings(){ }) } setTheme(); -function setTheme(){ - const name=localStorage.getItem("theme"); - document.body.className=name+"-theme"; -} + function userSettings(){ usersettings.show(); } diff --git a/webpage/localuser.js b/webpage/localuser.js index fa6710e..302b923 100644 --- a/webpage/localuser.js +++ b/webpage/localuser.js @@ -121,7 +121,7 @@ class localuser{ if(thing.properties.icon!=null){ const img=document.createElement("img"); img.classList.add("pfp","servericon") - img.src="https://cdn.old.server.spacebar.chat/icons/"+thing.properties.id+"/"+thing.properties.icon+".png"; + img.src=info.cdn.toString()+"icons/"+thing.properties.id+"/"+thing.properties.icon+".png"; divy.appendChild(img) img.all=thing; img.onclick=function(){ @@ -193,7 +193,7 @@ class localuser{ var reader = new FileReader(); reader.readAsDataURL(file); reader.onload = function () { - fetch("https://old.server.spacebar.chat/api/v9/users/@me",{ + fetch(info.api.toString()+"/v9/users/@me",{ method:"PATCH", headers:{ "Content-type": "application/json; charset=UTF-8", @@ -208,7 +208,7 @@ class localuser{ } updatepronouns(pronouns){ - fetch("https://old.server.spacebar.chat/api/v9/users/@me/profile",{ + fetch(info.api.toString()+"/v9/users/@me/profile",{ method:"PATCH", headers:{ "Content-type": "application/json; charset=UTF-8", @@ -220,7 +220,7 @@ class localuser{ }); } updatebio(bio){ - fetch("https://old.server.spacebar.chat/api/v9/users/@me/profile",{ + fetch(info.api.toString()+"/v9/users/@me/profile",{ method:"PATCH", headers:{ "Content-type": "application/json; charset=UTF-8", diff --git a/webpage/login.html b/webpage/login.html index 98304d2..31980aa 100644 --- a/webpage/login.html +++ b/webpage/login.html @@ -5,6 +5,10 @@