fix url bugs and improve account switcher

This commit is contained in:
MathMan05 2024-08-11 15:16:49 -05:00
parent 0fe2966ad1
commit 5148e1b77b
19 changed files with 186 additions and 175 deletions

View file

@ -361,7 +361,7 @@ class Channel {
if (!this.hasunreads) { if (!this.hasunreads) {
return; return;
} }
fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages/" + this.lastmessageid + "/ack", { fetch(this.info.api + "/channels/" + this.snowflake + "/messages/" + this.lastmessageid + "/ack", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify({}) body: JSON.stringify({})
@ -429,7 +429,7 @@ class Channel {
return div; return div;
} }
createChannel(name, type) { createChannel(name, type) {
fetch(this.info.api.toString() + "/guilds/" + this.guild.id + "/channels", { fetch(this.info.api + "/guilds/" + this.guild.id + "/channels", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -452,7 +452,7 @@ class Channel {
["mdbox", "Channel topic:", this.topic, function () { topic = this.value; }], ["mdbox", "Channel topic:", this.topic, function () { topic = this.value; }],
["checkbox", "NSFW Channel", this.nsfw, function () { nsfw = this.checked; }], ["checkbox", "NSFW Channel", this.nsfw, function () { nsfw = this.checked; }],
["button", "", "submit", () => { ["button", "", "submit", () => {
fetch(this.info.api.toString() + "/channels/" + thisid, { fetch(this.info.api + "/channels/" + thisid, {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -475,7 +475,7 @@ class Channel {
console.log(full); console.log(full);
} }
deleteChannel() { deleteChannel() {
fetch(this.info.api.toString() + "/channels/" + this.snowflake, { fetch(this.info.api + "/channels/" + this.snowflake, {
method: "DELETE", method: "DELETE",
headers: this.headers headers: this.headers
}); });
@ -518,7 +518,7 @@ class Channel {
return snowflake.getObject(); return snowflake.getObject();
} }
else { else {
const gety = await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages?limit=1&around=" + id, { headers: this.headers }); const gety = await fetch(this.info.api + "/channels/" + this.snowflake + "/messages?limit=1&around=" + id, { headers: this.headers });
const json = await gety.json(); const json = await gety.json();
return new Message(json[0], this); return new Message(json[0], this);
} }
@ -554,7 +554,7 @@ class Channel {
return; return;
} }
; ;
const j = await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages?limit=100", { const j = await fetch(this.info.api + "/channels/" + this.snowflake + "/messages?limit=100", {
headers: this.headers, headers: this.headers,
}); });
const response = await j.json(); const response = await j.json();
@ -591,7 +591,7 @@ class Channel {
if (id === this.lastmessage.id) { if (id === this.lastmessage.id) {
return; return;
} }
await fetch(this.info.api.toString() + "/channels/" + this.id + "/messages?limit=100&after=" + id, { await fetch(this.info.api + "/channels/" + this.id + "/messages?limit=100&after=" + id, {
headers: this.headers headers: this.headers
}).then((j) => { return j.json(); }).then(response => { }).then((j) => { return j.json(); }).then(response => {
let previd = SnowFlake.getSnowFlakeFromID(id, Message); let previd = SnowFlake.getSnowFlakeFromID(id, Message);
@ -622,7 +622,7 @@ class Channel {
if (this.topid && id === this.topid.id) { if (this.topid && id === this.topid.id) {
return; return;
} }
await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages?before=" + id + "&limit=100", { await fetch(this.info.api + "/channels/" + this.snowflake + "/messages?before=" + id + "&limit=100", {
headers: this.headers headers: this.headers
}).then((j) => { return j.json(); }).then((response) => { }).then((j) => { return j.json(); }).then((response) => {
if (response.length < 100) { if (response.length < 100) {
@ -725,7 +725,7 @@ class Channel {
return; return;
} }
this.typing = new Date().getTime() + 6000; this.typing = new Date().getTime() + 6000;
fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/typing", { fetch(this.info.api + "/channels/" + this.snowflake + "/typing", {
method: "POST", method: "POST",
headers: this.headers headers: this.headers
}); });
@ -768,7 +768,7 @@ class Channel {
body.message_reference = replyjson; body.message_reference = replyjson;
} }
console.log(body); console.log(body);
return await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages", { return await fetch(this.info.api + "/channels/" + this.snowflake + "/messages", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify(body) body: JSON.stringify(body)
@ -789,7 +789,7 @@ class Channel {
console.log(attachments[i]); console.log(attachments[i]);
formData.append("files[" + i + "]", attachments[i]); formData.append("files[" + i + "]", attachments[i]);
} }
return await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages", { return await fetch(this.info.api + "/channels/" + this.snowflake + "/messages", {
method: 'POST', method: 'POST',
body: formData, body: formData,
headers: { "Authorization": this.headers.Authorization } headers: { "Authorization": this.headers.Authorization }
@ -877,7 +877,7 @@ class Channel {
} }
} }
async addRoleToPerms(role) { async addRoleToPerms(role) {
await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/permissions/" + role.snowflake, { await fetch(this.info.api + "/channels/" + this.snowflake + "/permissions/" + role.snowflake, {
method: "PUT", method: "PUT",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -895,7 +895,7 @@ class Channel {
const permission = this.permission_overwrites.get(id); const permission = this.permission_overwrites.get(id);
permission.allow = perms.allow; permission.allow = perms.allow;
permission.deny = perms.deny; permission.deny = perms.deny;
await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/permissions/" + id, { await fetch(this.info.api + "/channels/" + this.snowflake + "/permissions/" + id, {
method: "PUT", method: "PUT",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({

View file

@ -117,7 +117,7 @@ class Guild {
noti noti
], ],
["button", "", "submit", _ => { ["button", "", "submit", _ => {
fetch(this.info.api.toString() + "/v9/users/@me/guilds/settings", { fetch(this.info.api + "/v9/users/@me/guilds/settings", {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -161,7 +161,7 @@ class Guild {
full.show(); full.show();
} }
async leave() { async leave() {
return fetch(this.info.api.toString() + "/users/@me/guilds/" + this.snowflake, { return fetch(this.info.api + "/users/@me/guilds/" + this.snowflake, {
method: "DELETE", method: "DELETE",
headers: this.headers headers: this.headers
}); });
@ -211,7 +211,7 @@ class Guild {
if (serverbug) { if (serverbug) {
for (const thing of build) { for (const thing of build) {
console.log(build, thing); console.log(build, thing);
fetch(this.info.api.toString() + "/v9/guilds/" + this.snowflake + "/channels", { fetch(this.info.api + "/v9/guilds/" + this.snowflake + "/channels", {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify([thing]) body: JSON.stringify([thing])
@ -219,7 +219,7 @@ class Guild {
} }
} }
else { else {
fetch(this.info.api.toString() + "/v9/guilds/" + this.snowflake + "/channels", { fetch(this.info.api + "/v9/guilds/" + this.snowflake + "/channels", {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify(build) body: JSON.stringify(build)
@ -245,7 +245,7 @@ class Guild {
if (this.properties.icon != null) { if (this.properties.icon != null) {
const img = document.createElement("img"); const img = document.createElement("img");
img.classList.add("pfp", "servericon"); img.classList.add("pfp", "servericon");
img.src = this.info.cdn.toString() + "/icons/" + this.properties.id + "/" + this.properties.icon + ".png"; img.src = this.info.cdn + "/icons/" + this.properties.id + "/" + this.properties.icon + ".png";
divy.appendChild(img); divy.appendChild(img);
img.onclick = () => { img.onclick = () => {
console.log(this.loadGuild); console.log(this.loadGuild);
@ -311,7 +311,7 @@ class Guild {
full.show(); full.show();
} }
async delete() { async delete() {
return fetch(this.info.api.toString() + "/guilds/" + this.snowflake + "/delete", { return fetch(this.info.api + "/guilds/" + this.snowflake + "/delete", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
}); });
@ -364,7 +364,7 @@ class Guild {
} }
} }
this.unreads(); this.unreads();
fetch(this.info.api.toString() + "/v9/read-states/ack-bulk", { fetch(this.info.api + "/v9/read-states/ack-bulk", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify(build) body: JSON.stringify(build)
@ -487,14 +487,14 @@ class Guild {
this.printServers(); this.printServers();
} }
createChannel(name, type) { createChannel(name, type) {
fetch(this.info.api.toString() + "/guilds/" + this.snowflake + "/channels", { fetch(this.info.api + "/guilds/" + this.snowflake + "/channels", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ name: name, type: type }) body: JSON.stringify({ name: name, type: type })
}); });
} }
async createRole(name) { async createRole(name) {
const fetched = await fetch(this.info.api.toString() + "/guilds/" + this.snowflake + "roles", { const fetched = await fetch(this.info.api + "/guilds/" + this.snowflake + "roles", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -513,7 +513,7 @@ class Guild {
const role = this.roleids[id]; const role = this.roleids[id];
role.permissions.allow = perms.allow; role.permissions.allow = perms.allow;
role.permissions.deny = perms.deny; role.permissions.deny = perms.deny;
await fetch(this.info.api.toString() + "/guilds/" + this.snowflake + "/roles/" + this.snowflake, { await fetch(this.info.api + "/guilds/" + this.snowflake + "/roles/" + this.snowflake, {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({

View file

@ -26,36 +26,27 @@ thisuser.initwebsocket().then(_ => {
const userinfo = document.getElementById("userinfo"); const userinfo = document.getElementById("userinfo");
const userdock = document.getElementById("userdock"); const userdock = document.getElementById("userdock");
userinfo.addEventListener("click", function (event) { userinfo.addEventListener("click", function (event) {
const table = document.createElement("table"); const table = document.createElement("div");
for (const thing of Object.values(users.users)) { for (const thing of Object.values(users.users)) {
const specialuser = thing; const specialuser = thing;
console.log(specialuser.pfpsrc); console.log(specialuser.pfpsrc);
const tr = document.createElement("tr"); const userinfo = document.createElement("div");
const td = document.createElement("td"); userinfo.classList.add("flexltr", "switchtable");
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"); const pfp = document.createElement("img");
pfpcell.append(pfp); userinfo.append(pfp);
const usertd = document.createElement("td");
row.append(usertd);
const user = document.createElement("div"); const user = document.createElement("div");
usertd.append(user); userinfo.append(user);
user.append(specialuser.username); user.append(specialuser.username);
user.append(document.createElement("br")); user.append(document.createElement("br"));
const span = document.createElement("span"); const span = document.createElement("span");
span.textContent = specialuser.serverurls.wellknown.hostname; span.textContent = specialuser.serverurls.wellknown.replace("https://", "").replace("http://", "");
user.append(span); user.append(span);
user.classList.add("userinfo");
span.classList.add("serverURL"); span.classList.add("serverURL");
pfp.src = specialuser.pfpsrc; pfp.src = specialuser.pfpsrc;
pfp.classList.add("pfp"); pfp.classList.add("pfp");
td.append(userinfo); table.append(userinfo);
tr.append(td); userinfo.addEventListener("click", _ => {
table.append(tr);
tr.addEventListener("click", _ => {
thisuser.unload(); thisuser.unload();
document.getElementById("loading").classList.remove("doneloading"); document.getElementById("loading").classList.remove("doneloading");
document.getElementById("loading").classList.add("loading"); document.getElementById("loading").classList.add("loading");
@ -72,14 +63,13 @@ thisuser.initwebsocket().then(_ => {
}); });
} }
{ {
const tr = document.createElement("tr"); const td = document.createElement("div");
const td = document.createElement("td"); td.classList.add("switchtable");
tr.append(td);
td.append("Switch accounts ⇌"); td.append("Switch accounts ⇌");
td.addEventListener("click", _ => { td.addEventListener("click", _ => {
window.location.href = "/login.html"; window.location.href = "/login.html";
}); });
table.append(tr); table.append(td);
} }
table.classList.add("accountSwitcher"); table.classList.add("accountSwitcher");
if (Contextmenu.currentmenu != "") { if (Contextmenu.currentmenu != "") {
@ -87,7 +77,7 @@ thisuser.initwebsocket().then(_ => {
} }
Contextmenu.currentmenu = table; Contextmenu.currentmenu = table;
console.log(table); console.log(table);
userdock.before(table); document.body.append(table);
event.stopImmediatePropagation(); event.stopImmediatePropagation();
}); });
} }

View file

@ -469,7 +469,7 @@ class Localuser {
else { else {
parsed = inviteurl; parsed = inviteurl;
} }
fetch(this.info.api.toString() + "/v9/invites/" + parsed, { fetch(this.info.api + "/v9/invites/" + parsed, {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
}).then(r => r.json()).then(_ => { }).then(r => r.json()).then(_ => {
@ -492,7 +492,7 @@ class Localuser {
content.textContent = "Loading..."; content.textContent = "Loading...";
const full = new Fullscreen(["html", content]); const full = new Fullscreen(["html", content]);
full.show(); full.show();
const res = await fetch(this.info.api.toString() + "/v9/discoverable-guilds?limit=50", { const res = await fetch(this.info.api + "/v9/discoverable-guilds?limit=50", {
headers: this.headers headers: this.headers
}); });
const json = await res.json(); const json = await res.json();
@ -509,7 +509,7 @@ class Localuser {
const banner = document.createElement("img"); const banner = document.createElement("img");
banner.classList.add("banner"); banner.classList.add("banner");
banner.crossOrigin = "anonymous"; banner.crossOrigin = "anonymous";
banner.src = this.info.cdn.toString() + "icons/" + guild.id + "/" + guild.banner + ".png?size=256"; banner.src = this.info.cdn + "icons/" + guild.id + "/" + guild.banner + ".png?size=256";
banner.alt = ""; banner.alt = "";
content.appendChild(banner); content.appendChild(banner);
} }
@ -518,7 +518,7 @@ class Localuser {
const img = document.createElement("img"); const img = document.createElement("img");
img.classList.add("icon"); img.classList.add("icon");
img.crossOrigin = "anonymous"; img.crossOrigin = "anonymous";
img.src = this.info.cdn.toString() + (guild.icon ? ("/icons/" + guild.id + "/" + guild.icon + ".png?size=48") : "/embed/avatars/3.png"); img.src = this.info.cdn + (guild.icon ? ("/icons/" + guild.id + "/" + guild.icon + ".png?size=48") : "/embed/avatars/3.png");
img.alt = ""; img.alt = "";
nameContainer.appendChild(img); nameContainer.appendChild(img);
const name = document.createElement("h3"); const name = document.createElement("h3");
@ -529,7 +529,7 @@ class Localuser {
desc.textContent = guild.description; desc.textContent = guild.description;
content.appendChild(desc); content.appendChild(desc);
content.addEventListener("click", async () => { content.addEventListener("click", async () => {
const joinRes = await fetch(this.info.api.toString() + "/v9/guilds/" + guild.id + "/members/@me", { const joinRes = await fetch(this.info.api + "/v9/guilds/" + guild.id + "/members/@me", {
method: "PUT", method: "PUT",
headers: this.headers headers: this.headers
}); });
@ -588,7 +588,7 @@ class Localuser {
var reader = new FileReader(); var reader = new FileReader();
reader.readAsDataURL(file); reader.readAsDataURL(file);
reader.onload = () => { reader.onload = () => {
fetch(this.info.api.toString() + "/users/@me", { fetch(this.info.api + "/users/@me", {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -598,7 +598,7 @@ class Localuser {
}; };
} }
updatepronouns(pronouns) { updatepronouns(pronouns) {
fetch(this.info.api.toString() + "/users/@me/profile", { fetch(this.info.api + "/users/@me/profile", {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -607,7 +607,7 @@ class Localuser {
}); });
} }
updatebio(bio) { updatebio(bio) {
fetch(this.info.api.toString() + "/v9/users/@me/profile", { fetch(this.info.api + "/v9/users/@me/profile", {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -730,7 +730,7 @@ class Localuser {
const security = settings.addButton("Account Security"); const security = settings.addButton("Account Security");
if (this.mfa_enabled) { if (this.mfa_enabled) {
security.addTextInput("Disable 2FA, totp code:", _ => { security.addTextInput("Disable 2FA, totp code:", _ => {
fetch(this.info.api.toString() + "/users/@me/mfa/totp/disable", { fetch(this.info.api + "/users/@me/mfa/totp/disable", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -762,7 +762,7 @@ class Localuser {
["textbox", "Account password:", "", function () { password = this.value; }], ["textbox", "Account password:", "", function () { password = this.value; }],
["textbox", "Code:", "", function () { code = this.value; }], ["textbox", "Code:", "", function () { code = this.value; }],
["button", "", "Submit", () => { ["button", "", "Submit", () => {
fetch(this.info.api.toString() + "/users/@me/mfa/totp/enable/", { fetch(this.info.api + "/users/@me/mfa/totp/enable/", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -800,7 +800,7 @@ class Localuser {
connectionContainer connectionContainer
], () => { }, async () => { ], () => { }, async () => {
connectionContainer.innerHTML = ""; connectionContainer.innerHTML = "";
const res = await fetch(this.info.api.toString() + "/v9/connections", { const res = await fetch(this.info.api + "/v9/connections", {
headers: this.headers headers: this.headers
}); });
const json = await res.json(); const json = await res.json();
@ -810,7 +810,7 @@ class Localuser {
container.textContent = key.charAt(0).toUpperCase() + key.slice(1); container.textContent = key.charAt(0).toUpperCase() + key.slice(1);
if (connection.enabled) { if (connection.enabled) {
container.addEventListener("click", async () => { container.addEventListener("click", async () => {
const connectionRes = await fetch(this.info.api.toString() + "/v9/connections/" + key + "/authorize", { const connectionRes = await fetch(this.info.api + "/v9/connections/" + key + "/authorize", {
headers: this.headers headers: this.headers
}); });
const connectionJSON = await connectionRes.json(); const connectionJSON = await connectionRes.json();
@ -838,7 +838,7 @@ class Localuser {
async () => { async () => {
if (appName.trim().length == 0) if (appName.trim().length == 0)
return alert("Please enter a name for the application."); return alert("Please enter a name for the application.");
const res = await fetch(this.info.api.toString() + "/v9/applications", { const res = await fetch(this.info.api + "/v9/applications", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -856,7 +856,7 @@ class Localuser {
] ]
], () => { }, async () => { ], () => { }, async () => {
appListContainer.innerHTML = ""; appListContainer.innerHTML = "";
const res = await fetch(this.info.api.toString() + "/v9/applications", { const res = await fetch(this.info.api + "/v9/applications", {
headers: this.headers headers: this.headers
}); });
const json = await res.json(); const json = await res.json();
@ -865,7 +865,7 @@ class Localuser {
if (application.cover_image) { if (application.cover_image) {
const cover = document.createElement("img"); const cover = document.createElement("img");
cover.crossOrigin = "anonymous"; cover.crossOrigin = "anonymous";
cover.src = this.info.cdn.toString() + "/app-icons/" + application.id + "/" + application.cover_image + ".png?size=256"; cover.src = this.info.cdn + "/app-icons/" + application.id + "/" + application.cover_image + ".png?size=256";
cover.alt = ""; cover.alt = "";
cover.loading = "lazy"; cover.loading = "lazy";
container.appendChild(cover); container.appendChild(cover);
@ -882,7 +882,7 @@ class Localuser {
}); });
} }
async manageApplication(appId = "") { async manageApplication(appId = "") {
const res = await fetch(this.info.api.toString() + "/v9/applications/" + appId, { const res = await fetch(this.info.api + "/v9/applications/" + appId, {
headers: this.headers headers: this.headers
}); });
const json = await res.json(); const json = await res.json();
@ -899,7 +899,7 @@ class Localuser {
fields.description = event.target.value; fields.description = event.target.value;
}], }],
["vdiv", ["vdiv",
json.icon ? ["img", this.info.cdn.toString() + "/app-icons/" + appId + "/" + json.icon + ".png?size=128", [128, 128]] : ["text", "No icon"], json.icon ? ["img", this.info.cdn + "/app-icons/" + appId + "/" + json.icon + ".png?size=128", [128, 128]] : ["text", "No icon"],
["fileupload", "Application icon:", event => { ["fileupload", "Application icon:", event => {
const reader = new FileReader(); const reader = new FileReader();
reader.readAsDataURL(event.target.files[0]); reader.readAsDataURL(event.target.files[0]);
@ -930,7 +930,7 @@ class Localuser {
"", "",
"Save changes", "Save changes",
async () => { async () => {
const updateRes = await fetch(this.info.api.toString() + "/v9/applications/" + appId, { const updateRes = await fetch(this.info.api + "/v9/applications/" + appId, {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify(fields) body: JSON.stringify(fields)
@ -950,7 +950,7 @@ class Localuser {
if (!json.bot) { if (!json.bot) {
if (!confirm("Are you sure you want to add a bot to this application? There's no going back.")) if (!confirm("Are you sure you want to add a bot to this application? There's no going back."))
return; return;
const updateRes = await fetch(this.info.api.toString() + "/v9/applications/" + appId + "/bot", { const updateRes = await fetch(this.info.api + "/v9/applications/" + appId + "/bot", {
method: "POST", method: "POST",
headers: this.headers headers: this.headers
}); });
@ -966,7 +966,7 @@ class Localuser {
appDialog.show(); appDialog.show();
} }
async manageBot(appId = "") { async manageBot(appId = "") {
const res = await fetch(this.info.api.toString() + "/v9/applications/" + appId, { const res = await fetch(this.info.api + "/v9/applications/" + appId, {
headers: this.headers headers: this.headers
}); });
const json = await res.json(); const json = await res.json();
@ -974,7 +974,7 @@ class Localuser {
return alert("For some reason, this application doesn't have a bot (yet)."); return alert("For some reason, this application doesn't have a bot (yet).");
const fields = { const fields = {
username: json.bot.username, username: json.bot.username,
avatar: json.bot.avatar ? (this.info.cdn.toString() + "/app-icons/" + appId + "/" + json.bot.avatar + ".png?size=256") : "" avatar: json.bot.avatar ? (this.info.cdn + "/app-icons/" + appId + "/" + json.bot.avatar + ".png?size=256") : ""
}; };
const botDialog = new Fullscreen(["vdiv", const botDialog = new Fullscreen(["vdiv",
["title", ["title",
@ -1000,7 +1000,7 @@ class Localuser {
"", "",
"Save changes", "Save changes",
async () => { async () => {
const updateRes = await fetch(this.info.api.toString() + "/v9/applications/" + appId + "/bot", { const updateRes = await fetch(this.info.api + "/v9/applications/" + appId + "/bot", {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify(fields) body: JSON.stringify(fields)
@ -1019,7 +1019,7 @@ class Localuser {
async () => { async () => {
if (!confirm("Are you sure you want to reset the bot token? Your bot will stop working until you update it.")) if (!confirm("Are you sure you want to reset the bot token? Your bot will stop working until you update it."))
return; return;
const updateRes = await fetch(this.info.api.toString() + "/v9/applications/" + appId + "/bot/reset", { const updateRes = await fetch(this.info.api + "/v9/applications/" + appId + "/bot/reset", {
method: "POST", method: "POST",
headers: this.headers headers: this.headers
}); });

View file

@ -65,10 +65,16 @@ class Specialuser {
console.error("specialuser can't construct from another specialuser"); console.error("specialuser can't construct from another specialuser");
} }
this.serverurls = json.serverurls; this.serverurls = json.serverurls;
this.serverurls.api = new URL(this.serverurls.api); let apistring = new URL(json.serverurls.api).toString();
this.serverurls.cdn = new URL(this.serverurls.cdn); apistring = apistring.replace(/\/(v\d+\/?)?$/, "") + "/v9";
this.serverurls.gateway = new URL(this.serverurls.gateway); this.serverurls.api = apistring;
this.serverurls.wellknown = new URL(this.serverurls.wellknown); this.serverurls.cdn = new URL(json.serverurls.cdn).toString().replace(/\/$/, "");
this.serverurls.gateway = new URL(json.serverurls.gateway).toString().replace(/\/$/, "");
;
this.serverurls.wellknown = new URL(json.serverurls.wellknown).toString().replace(/\/$/, "");
;
this.serverurls.login = new URL(json.serverurls.login).toString().replace(/\/$/, "");
;
this.email = json.email; this.email = json.email;
this.token = json.token; this.token = json.token;
this.loggedin = json.loggedin; this.loggedin = json.loggedin;

View file

@ -455,7 +455,7 @@ class MarkDown {
emojiElem.classList.add("md-emoji"); emojiElem.classList.add("md-emoji");
emojiElem.classList.add(isEmojiOnly ? "bigemoji" : "smallemoji"); emojiElem.classList.add(isEmojiOnly ? "bigemoji" : "smallemoji");
emojiElem.crossOrigin = "anonymous"; emojiElem.crossOrigin = "anonymous";
emojiElem.src = this.info.cdn.toString() + "emojis/" + parts[2] + "." + (parts[1] ? "gif" : "png") + "?size=32"; emojiElem.src = this.info.cdn + "emojis/" + parts[2] + "." + (parts[1] ? "gif" : "png") + "?size=32";
emojiElem.alt = buildjoin; emojiElem.alt = buildjoin;
emojiElem.loading = "lazy"; emojiElem.loading = "lazy";
span.appendChild(emojiElem); span.appendChild(emojiElem);

View file

@ -16,7 +16,7 @@ class Member {
navigator.clipboard.writeText(this.id); navigator.clipboard.writeText(this.id);
}); });
this.contextmenu.addbutton("Message user", function () { this.contextmenu.addbutton("Message user", function () {
fetch(this.info.api.toString() + "/v9/users/@me/channels", { method: "POST", fetch(this.info.api + "/v9/users/@me/channels", { method: "POST",
body: JSON.stringify({ "recipients": [this.id] }), body: JSON.stringify({ "recipients": [this.id] }),
headers: this.headers headers: this.headers
}); });

View file

@ -79,7 +79,7 @@ class Message {
break; break;
} }
} }
fetch(this.info.api.toString() + "/channels/" + this.channel.id + "/messages/" + this.id + "/reactions/" + encodeURIComponent(emoji) + "/@me", { fetch(this.info.api + "/channels/" + this.channel.id + "/messages/" + this.id + "/reactions/" + encodeURIComponent(emoji) + "/@me", {
method: remove ? "DELETE" : "PUT", method: remove ? "DELETE" : "PUT",
headers: this.headers, headers: this.headers,
}); });
@ -184,14 +184,14 @@ class Message {
return build; return build;
} }
async edit(content) { async edit(content) {
return await fetch(this.info.api.toString() + "/channels/" + this.channel.snowflake + "/messages/" + this.id, { return await fetch(this.info.api + "/channels/" + this.channel.snowflake + "/messages/" + this.id, {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ content: content }) body: JSON.stringify({ content: content })
}); });
} }
delete() { delete() {
fetch(`${this.info.api.toString()}/channels/${this.channel.snowflake}/messages/${this.id}`, { fetch(`${this.info.api}/channels/${this.channel.snowflake}/messages/${this.id}`, {
headers: this.headers, headers: this.headers,
method: "DELETE", method: "DELETE",
}); });

View file

@ -48,7 +48,7 @@ class User {
navigator.clipboard.writeText(this.id.id); navigator.clipboard.writeText(this.id.id);
}); });
this.contextmenu.addbutton("Message user", function () { this.contextmenu.addbutton("Message user", function () {
fetch(this.info.api.toString() + "/v9/users/@me/channels", { method: "POST", fetch(this.info.api + "/v9/users/@me/channels", { method: "POST",
body: JSON.stringify({ "recipients": [this.id.id] }), body: JSON.stringify({ "recipients": [this.id.id] }),
headers: this.localuser.headers headers: this.localuser.headers
}); });
@ -141,10 +141,10 @@ class User {
return this.avatar; return this.avatar;
} }
if (this.avatar != null) { if (this.avatar != null) {
return this.info.cdn.toString() + "/avatars/" + this.id + "/" + this.avatar + ".png"; return this.info.cdn + "/avatars/" + this.id + "/" + this.avatar + ".png";
} }
else { else {
return this.info.cdn.toString() + "/embed/avatars/3.png"; return this.info.cdn + "/embed/avatars/3.png";
} }
} }
createjankpromises() { createjankpromises() {

View file

@ -369,7 +369,7 @@ class Channel{
if(!this.hasunreads){ if(!this.hasunreads){
return; return;
} }
fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages/"+this.lastmessageid+"/ack",{ fetch(this.info.api+"/channels/"+this.snowflake+"/messages/"+this.lastmessageid+"/ack",{
method:"POST", method:"POST",
headers:this.headers, headers:this.headers,
body:JSON.stringify({}) body:JSON.stringify({})
@ -437,7 +437,7 @@ class Channel{
return div; return div;
} }
createChannel(name:string,type:number){ createChannel(name:string,type:number){
fetch(this.info.api.toString()+"/guilds/"+this.guild.id+"/channels",{ fetch(this.info.api+"/guilds/"+this.guild.id+"/channels",{
method:"POST", method:"POST",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({
@ -461,7 +461,7 @@ class Channel{
["mdbox","Channel topic:",this.topic,function(){topic=this.value}], ["mdbox","Channel topic:",this.topic,function(){topic=this.value}],
["checkbox","NSFW Channel",this.nsfw,function(){nsfw=this.checked}], ["checkbox","NSFW Channel",this.nsfw,function(){nsfw=this.checked}],
["button","","submit",()=>{ ["button","","submit",()=>{
fetch(this.info.api.toString()+"/channels/"+thisid,{ fetch(this.info.api+"/channels/"+thisid,{
method:"PATCH", method:"PATCH",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({
@ -485,7 +485,7 @@ class Channel{
console.log(full) console.log(full)
} }
deleteChannel(){ deleteChannel(){
fetch(this.info.api.toString()+"/channels/"+this.snowflake,{ fetch(this.info.api+"/channels/"+this.snowflake,{
method:"DELETE", method:"DELETE",
headers:this.headers headers:this.headers
}) })
@ -527,7 +527,7 @@ class Channel{
if(snowflake.getObject()){ if(snowflake.getObject()){
return snowflake.getObject(); return snowflake.getObject();
}else{ }else{
const gety=await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages?limit=1&around="+id,{headers:this.headers}) const gety=await fetch(this.info.api+"/channels/"+this.snowflake+"/messages?limit=1&around="+id,{headers:this.headers})
const json=await gety.json(); const json=await gety.json();
return new Message(json[0],this); return new Message(json[0],this);
} }
@ -560,7 +560,7 @@ class Channel{
lastmessage:Message; lastmessage:Message;
async putmessages(){ async putmessages(){
if(this.allthewayup){return}; if(this.allthewayup){return};
const j=await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages?limit=100",{ const j=await fetch(this.info.api+"/channels/"+this.snowflake+"/messages?limit=100",{
headers: this.headers, headers: this.headers,
}); });
@ -597,7 +597,7 @@ class Channel{
if(id===this.lastmessage.id){ if(id===this.lastmessage.id){
return; return;
} }
await fetch(this.info.api.toString()+"/channels/"+this.id+"/messages?limit=100&after="+id,{ await fetch(this.info.api+"/channels/"+this.id+"/messages?limit=100&after="+id,{
headers:this.headers headers:this.headers
}).then((j)=>{return j.json()}).then(response=>{ }).then((j)=>{return j.json()}).then(response=>{
let previd:SnowFlake<Message>=SnowFlake.getSnowFlakeFromID(id,Message); let previd:SnowFlake<Message>=SnowFlake.getSnowFlakeFromID(id,Message);
@ -628,7 +628,7 @@ class Channel{
return; return;
} }
await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages?before="+id+"&limit=100",{ await fetch(this.info.api+"/channels/"+this.snowflake+"/messages?before="+id+"&limit=100",{
headers:this.headers headers:this.headers
}).then((j)=>{return j.json()}).then((response:messagejson[])=>{ }).then((j)=>{return j.json()}).then((response:messagejson[])=>{
if(response.length<100){ if(response.length<100){
@ -727,7 +727,7 @@ class Channel{
return; return;
} }
this.typing=new Date().getTime()+6000; this.typing=new Date().getTime()+6000;
fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/typing",{ fetch(this.info.api+"/channels/"+this.snowflake+"/typing",{
method:"POST", method:"POST",
headers:this.headers headers:this.headers
}) })
@ -767,7 +767,7 @@ class Channel{
body.message_reference=replyjson; body.message_reference=replyjson;
} }
console.log(body) console.log(body)
return await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages",{ return await fetch(this.info.api+"/channels/"+this.snowflake+"/messages",{
method:"POST", method:"POST",
headers:this.headers, headers:this.headers,
body:JSON.stringify(body) body:JSON.stringify(body)
@ -787,7 +787,7 @@ class Channel{
console.log(attachments[i]) console.log(attachments[i])
formData.append("files["+i+"]",attachments[i]); formData.append("files["+i+"]",attachments[i]);
} }
return await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages", { return await fetch(this.info.api+"/channels/"+this.snowflake+"/messages", {
method: 'POST', method: 'POST',
body: formData, body: formData,
headers:{"Authorization":this.headers.Authorization} headers:{"Authorization":this.headers.Authorization}
@ -868,7 +868,7 @@ class Channel{
} }
} }
async addRoleToPerms(role:Role){ async addRoleToPerms(role:Role){
await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/permissions/"+role.snowflake,{ await fetch(this.info.api+"/channels/"+this.snowflake+"/permissions/"+role.snowflake,{
method:"PUT", method:"PUT",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({
@ -886,7 +886,7 @@ class Channel{
const permission=this.permission_overwrites.get(id); const permission=this.permission_overwrites.get(id);
permission.allow=perms.allow; permission.allow=perms.allow;
permission.deny=perms.deny; permission.deny=perms.deny;
await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/permissions/"+id,{ await fetch(this.info.api+"/channels/"+this.snowflake+"/permissions/"+id,{
method:"PUT", method:"PUT",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({

View file

@ -128,7 +128,7 @@ class Guild{
noti noti
], ],
["button","","submit",_=>{ ["button","","submit",_=>{
fetch(this.info.api.toString()+"/v9/users/@me/guilds/settings",{ fetch(this.info.api+"/v9/users/@me/guilds/settings",{
method:"PATCH", method:"PATCH",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({
@ -173,7 +173,7 @@ class Guild{
full.show(); full.show();
} }
async leave(){ async leave(){
return fetch(this.info.api.toString()+"/users/@me/guilds/"+this.snowflake,{ return fetch(this.info.api+"/users/@me/guilds/"+this.snowflake,{
method:"DELETE", method:"DELETE",
headers:this.headers headers:this.headers
}) })
@ -221,14 +221,14 @@ class Guild{
if(serverbug){ if(serverbug){
for(const thing of build){ for(const thing of build){
console.log(build,thing) console.log(build,thing)
fetch(this.info.api.toString()+"/v9/guilds/"+this.snowflake+"/channels",{ fetch(this.info.api+"/v9/guilds/"+this.snowflake+"/channels",{
method:"PATCH", method:"PATCH",
headers:this.headers, headers:this.headers,
body:JSON.stringify([thing]) body:JSON.stringify([thing])
}); });
} }
}else{ }else{
fetch(this.info.api.toString()+"/v9/guilds/"+this.snowflake+"/channels",{ fetch(this.info.api+"/v9/guilds/"+this.snowflake+"/channels",{
method:"PATCH", method:"PATCH",
headers:this.headers, headers:this.headers,
body:JSON.stringify(build) body:JSON.stringify(build)
@ -256,7 +256,7 @@ class Guild{
if(this.properties.icon!=null){ if(this.properties.icon!=null){
const img=document.createElement("img"); const img=document.createElement("img");
img.classList.add("pfp","servericon"); img.classList.add("pfp","servericon");
img.src=this.info.cdn.toString()+"/icons/"+this.properties.id+"/"+this.properties.icon+".png"; img.src=this.info.cdn+"/icons/"+this.properties.id+"/"+this.properties.icon+".png";
divy.appendChild(img) divy.appendChild(img)
img.onclick=()=>{ img.onclick=()=>{
console.log(this.loadGuild) console.log(this.loadGuild)
@ -323,7 +323,7 @@ class Guild{
full.show(); full.show();
} }
async delete(){ async delete(){
return fetch(this.info.api.toString()+"/guilds/"+this.snowflake+"/delete",{ return fetch(this.info.api+"/guilds/"+this.snowflake+"/delete",{
method:"POST", method:"POST",
headers:this.headers, headers:this.headers,
}) })
@ -372,7 +372,7 @@ class Guild{
} }
} }
this.unreads(); this.unreads();
fetch(this.info.api.toString()+"/v9/read-states/ack-bulk",{ fetch(this.info.api+"/v9/read-states/ack-bulk",{
method:"POST", method:"POST",
headers:this.headers, headers:this.headers,
body:JSON.stringify(build) body:JSON.stringify(build)
@ -499,14 +499,14 @@ class Guild{
this.printServers(); this.printServers();
} }
createChannel(name:string,type:number){ createChannel(name:string,type:number){
fetch(this.info.api.toString()+"/guilds/"+this.snowflake+"/channels",{ fetch(this.info.api+"/guilds/"+this.snowflake+"/channels",{
method:"POST", method:"POST",
headers:this.headers, headers:this.headers,
body:JSON.stringify({name: name, type: type}) body:JSON.stringify({name: name, type: type})
}) })
} }
async createRole(name:string){ async createRole(name:string){
const fetched=await fetch(this.info.api.toString()+"/guilds/"+this.snowflake+"roles",{ const fetched=await fetch(this.info.api+"/guilds/"+this.snowflake+"roles",{
method:"POST", method:"POST",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({
@ -526,7 +526,7 @@ class Guild{
role.permissions.allow=perms.allow; role.permissions.allow=perms.allow;
role.permissions.deny=perms.deny; role.permissions.deny=perms.deny;
await fetch(this.info.api.toString()+"/guilds/"+this.snowflake+"/roles/"+this.snowflake,{ await fetch(this.info.api+"/guilds/"+this.snowflake+"/roles/"+this.snowflake,{
method:"PATCH", method:"PATCH",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({

View file

@ -31,40 +31,30 @@ thisuser.initwebsocket().then(_=>{
const userinfo=document.getElementById("userinfo"); const userinfo=document.getElementById("userinfo");
const userdock=document.getElementById("userdock"); const userdock=document.getElementById("userdock");
userinfo.addEventListener("click",function(event){ userinfo.addEventListener("click",function(event){
const table=document.createElement("table"); const table=document.createElement("div");
for(const thing of Object.values(users.users)){ for(const thing of Object.values(users.users)){
const specialuser=thing as Specialuser; const specialuser=thing as Specialuser;
console.log(specialuser.pfpsrc) console.log(specialuser.pfpsrc)
const tr=document.createElement("tr");
const td=document.createElement("td");
const userinfo=document.createElement("table"); const userinfo=document.createElement("div");
userinfo.classList.add("switchtable"); userinfo.classList.add("flexltr","switchtable");
const row=document.createElement("tr");
userinfo.append(row)
const pfpcell=document.createElement("td");
row.append(pfpcell);
const pfp=document.createElement("img"); const pfp=document.createElement("img");
pfpcell.append(pfp); userinfo.append(pfp);
const usertd=document.createElement("td")
row.append(usertd);
const user=document.createElement("div"); const user=document.createElement("div");
usertd.append(user); userinfo.append(user);
user.append(specialuser.username); user.append(specialuser.username);
user.append(document.createElement("br")); user.append(document.createElement("br"));
const span=document.createElement("span"); const span=document.createElement("span");
span.textContent=specialuser.serverurls.wellknown.hostname; span.textContent=specialuser.serverurls.wellknown.replace("https://","").replace("http://","");
user.append(span); user.append(span);
user.classList.add("userinfo")
span.classList.add("serverURL") span.classList.add("serverURL")
pfp.src=specialuser.pfpsrc; pfp.src=specialuser.pfpsrc;
pfp.classList.add("pfp"); pfp.classList.add("pfp");
td.append(userinfo) table.append(userinfo);
userinfo.addEventListener("click",_=>{
tr.append(td);
table.append(tr);
tr.addEventListener("click",_=>{
thisuser.unload(); thisuser.unload();
document.getElementById("loading").classList.remove("doneloading"); document.getElementById("loading").classList.remove("doneloading");
document.getElementById("loading").classList.add("loading"); document.getElementById("loading").classList.add("loading");
@ -82,14 +72,13 @@ thisuser.initwebsocket().then(_=>{
}) })
} }
{ {
const tr=document.createElement("tr"); const td=document.createElement("div");
const td=document.createElement("td"); td.classList.add("switchtable")
tr.append(td);
td.append("Switch accounts ⇌"); td.append("Switch accounts ⇌");
td.addEventListener("click",_=>{ td.addEventListener("click",_=>{
window.location.href="/login.html"; window.location.href="/login.html";
}) })
table.append(tr); table.append(td);
} }
table.classList.add("accountSwitcher"); table.classList.add("accountSwitcher");
if(Contextmenu.currentmenu!=""){ if(Contextmenu.currentmenu!=""){
@ -97,7 +86,7 @@ thisuser.initwebsocket().then(_=>{
} }
Contextmenu.currentmenu=table; Contextmenu.currentmenu=table;
console.log(table); console.log(table);
userdock.before(table); document.body.append(table);
event.stopImmediatePropagation(); event.stopImmediatePropagation();
}) })
} }

View file

@ -18,9 +18,9 @@ class Localuser{
lastSequence:number|null=null; lastSequence:number|null=null;
token:string; token:string;
userinfo:Specialuser; userinfo:Specialuser;
serverurls; serverurls:Specialuser["serverurls"];
initialized:boolean; initialized:boolean;
info; info:Specialuser["serverurls"];
headers:{"Content-type":string,Authorization:string}; headers:{"Content-type":string,Authorization:string};
usersettings:Settings; usersettings:Settings;
userConnections:Fullscreen; userConnections:Fullscreen;
@ -487,7 +487,7 @@ class Localuser{
}else{ }else{
parsed=inviteurl; parsed=inviteurl;
} }
fetch(this.info.api.toString()+"/v9/invites/"+parsed,{ fetch(this.info.api+"/v9/invites/"+parsed,{
method:"POST", method:"POST",
headers:this.headers, headers:this.headers,
}).then(r=>r.json()).then(_=>{ }).then(r=>r.json()).then(_=>{
@ -512,7 +512,7 @@ class Localuser{
const full=new Fullscreen(["html", content]); const full=new Fullscreen(["html", content]);
full.show(); full.show();
const res=await fetch(this.info.api.toString()+"/v9/discoverable-guilds?limit=50", { const res=await fetch(this.info.api+"/v9/discoverable-guilds?limit=50", {
headers: this.headers headers: this.headers
}); });
const json=await res.json(); const json=await res.json();
@ -533,7 +533,7 @@ class Localuser{
const banner=document.createElement("img"); const banner=document.createElement("img");
banner.classList.add("banner"); banner.classList.add("banner");
banner.crossOrigin="anonymous"; banner.crossOrigin="anonymous";
banner.src=this.info.cdn.toString()+"icons/"+guild.id+"/"+guild.banner+".png?size=256"; banner.src=this.info.cdn+"icons/"+guild.id+"/"+guild.banner+".png?size=256";
banner.alt=""; banner.alt="";
content.appendChild(banner); content.appendChild(banner);
} }
@ -543,7 +543,7 @@ class Localuser{
const img=document.createElement("img"); const img=document.createElement("img");
img.classList.add("icon"); img.classList.add("icon");
img.crossOrigin="anonymous"; img.crossOrigin="anonymous";
img.src=this.info.cdn.toString()+(guild.icon ? ("/icons/"+guild.id+"/"+guild.icon+".png?size=48") : "/embed/avatars/3.png"); img.src=this.info.cdn+(guild.icon ? ("/icons/"+guild.id+"/"+guild.icon+".png?size=48") : "/embed/avatars/3.png");
img.alt=""; img.alt="";
nameContainer.appendChild(img); nameContainer.appendChild(img);
@ -556,7 +556,7 @@ class Localuser{
content.appendChild(desc); content.appendChild(desc);
content.addEventListener("click", async ()=>{ content.addEventListener("click", async ()=>{
const joinRes=await fetch(this.info.api.toString()+"/v9/guilds/"+guild.id+"/members/@me", { const joinRes=await fetch(this.info.api+"/v9/guilds/"+guild.id+"/members/@me", {
method: "PUT", method: "PUT",
headers: this.headers headers: this.headers
}); });
@ -611,7 +611,7 @@ class Localuser{
var reader = new FileReader(); var reader = new FileReader();
reader.readAsDataURL(file); reader.readAsDataURL(file);
reader.onload = ()=>{ reader.onload = ()=>{
fetch(this.info.api.toString()+"/users/@me",{ fetch(this.info.api+"/users/@me",{
method:"PATCH", method:"PATCH",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({
@ -622,7 +622,7 @@ class Localuser{
} }
updatepronouns(pronouns:string):void{ updatepronouns(pronouns:string):void{
fetch(this.info.api.toString()+"/users/@me/profile",{ fetch(this.info.api+"/users/@me/profile",{
method:"PATCH", method:"PATCH",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({
@ -631,7 +631,7 @@ class Localuser{
}); });
} }
updatebio(bio:string):void{ updatebio(bio:string):void{
fetch(this.info.api.toString()+"/v9/users/@me/profile",{ fetch(this.info.api+"/v9/users/@me/profile",{
method:"PATCH", method:"PATCH",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({
@ -755,7 +755,7 @@ class Localuser{
const security=settings.addButton("Account Security"); const security=settings.addButton("Account Security");
if(this.mfa_enabled){ if(this.mfa_enabled){
security.addTextInput("Disable 2FA, totp code:",_=>{ security.addTextInput("Disable 2FA, totp code:",_=>{
fetch(this.info.api.toString()+"/users/@me/mfa/totp/disable",{ fetch(this.info.api+"/users/@me/mfa/totp/disable",{
method:"POST", method:"POST",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({
@ -786,7 +786,7 @@ class Localuser{
["textbox","Account password:","",function(){password=this.value}], ["textbox","Account password:","",function(){password=this.value}],
["textbox","Code:","",function(){code=this.value}], ["textbox","Code:","",function(){code=this.value}],
["button","","Submit",()=>{ ["button","","Submit",()=>{
fetch(this.info.api.toString()+"/users/@me/mfa/totp/enable/",{ fetch(this.info.api+"/users/@me/mfa/totp/enable/",{
method:"POST", method:"POST",
headers:this.headers, headers:this.headers,
body:JSON.stringify({ body:JSON.stringify({
@ -826,7 +826,7 @@ class Localuser{
], () => {}, async () => { ], () => {}, async () => {
connectionContainer.innerHTML=""; connectionContainer.innerHTML="";
const res=await fetch(this.info.api.toString()+"/v9/connections", { const res=await fetch(this.info.api+"/v9/connections", {
headers: this.headers headers: this.headers
}); });
const json=await res.json(); const json=await res.json();
@ -839,7 +839,7 @@ class Localuser{
if (connection.enabled) { if (connection.enabled) {
container.addEventListener("click", async () => { container.addEventListener("click", async () => {
const connectionRes=await fetch(this.info.api.toString()+"/v9/connections/" + key + "/authorize", { const connectionRes=await fetch(this.info.api+"/v9/connections/" + key + "/authorize", {
headers: this.headers headers: this.headers
}); });
const connectionJSON=await connectionRes.json(); const connectionJSON=await connectionRes.json();
@ -870,7 +870,7 @@ class Localuser{
async () => { async () => {
if (appName.trim().length == 0) return alert("Please enter a name for the application."); if (appName.trim().length == 0) return alert("Please enter a name for the application.");
const res=await fetch(this.info.api.toString()+"/v9/applications", { const res=await fetch(this.info.api+"/v9/applications", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify({ body: JSON.stringify({
@ -889,7 +889,7 @@ class Localuser{
], () => {}, async () => { ], () => {}, async () => {
appListContainer.innerHTML=""; appListContainer.innerHTML="";
const res=await fetch(this.info.api.toString()+"/v9/applications", { const res=await fetch(this.info.api+"/v9/applications", {
headers: this.headers headers: this.headers
}); });
const json=await res.json(); const json=await res.json();
@ -900,7 +900,7 @@ class Localuser{
if (application.cover_image) { if (application.cover_image) {
const cover=document.createElement("img"); const cover=document.createElement("img");
cover.crossOrigin="anonymous"; cover.crossOrigin="anonymous";
cover.src=this.info.cdn.toString()+"/app-icons/" + application.id + "/" + application.cover_image + ".png?size=256"; cover.src=this.info.cdn+"/app-icons/" + application.id + "/" + application.cover_image + ".png?size=256";
cover.alt=""; cover.alt="";
cover.loading="lazy"; cover.loading="lazy";
container.appendChild(cover); container.appendChild(cover);
@ -920,7 +920,7 @@ class Localuser{
) )
} }
async manageApplication(appId="") { async manageApplication(appId="") {
const res=await fetch(this.info.api.toString()+"/v9/applications/" + appId, { const res=await fetch(this.info.api+"/v9/applications/" + appId, {
headers: this.headers headers: this.headers
}); });
const json=await res.json(); const json=await res.json();
@ -939,7 +939,7 @@ class Localuser{
fields.description=event.target.value; fields.description=event.target.value;
}], }],
["vdiv", ["vdiv",
json.icon ? ["img", this.info.cdn.toString()+"/app-icons/" + appId + "/" + json.icon + ".png?size=128", [128, 128]] : ["text", "No icon"], json.icon ? ["img", this.info.cdn+"/app-icons/" + appId + "/" + json.icon + ".png?size=128", [128, 128]] : ["text", "No icon"],
["fileupload", "Application icon:", event => { ["fileupload", "Application icon:", event => {
const reader=new FileReader(); const reader=new FileReader();
reader.readAsDataURL(event.target.files[0]); reader.readAsDataURL(event.target.files[0]);
@ -970,7 +970,7 @@ class Localuser{
"", "",
"Save changes", "Save changes",
async () => { async () => {
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId, { const updateRes=await fetch(this.info.api+"/v9/applications/" + appId, {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify(fields) body: JSON.stringify(fields)
@ -989,7 +989,7 @@ class Localuser{
if (!json.bot) { if (!json.bot) {
if (!confirm("Are you sure you want to add a bot to this application? There's no going back.")) return; if (!confirm("Are you sure you want to add a bot to this application? There's no going back.")) return;
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId + "/bot", { const updateRes=await fetch(this.info.api+"/v9/applications/" + appId + "/bot", {
method: "POST", method: "POST",
headers: this.headers headers: this.headers
}); });
@ -1007,7 +1007,7 @@ class Localuser{
appDialog.show(); appDialog.show();
} }
async manageBot(appId="") { async manageBot(appId="") {
const res=await fetch(this.info.api.toString()+"/v9/applications/" + appId, { const res=await fetch(this.info.api+"/v9/applications/" + appId, {
headers: this.headers headers: this.headers
}); });
const json=await res.json(); const json=await res.json();
@ -1015,7 +1015,7 @@ class Localuser{
const fields: any={ const fields: any={
username: json.bot.username, username: json.bot.username,
avatar: json.bot.avatar ? (this.info.cdn.toString()+"/app-icons/" + appId + "/" + json.bot.avatar + ".png?size=256") : "" avatar: json.bot.avatar ? (this.info.cdn+"/app-icons/" + appId + "/" + json.bot.avatar + ".png?size=256") : ""
}; };
const botDialog=new Fullscreen( const botDialog=new Fullscreen(
["vdiv", ["vdiv",
@ -1042,7 +1042,7 @@ class Localuser{
"", "",
"Save changes", "Save changes",
async () => { async () => {
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId + "/bot", { const updateRes=await fetch(this.info.api+"/v9/applications/" + appId + "/bot", {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify(fields) body: JSON.stringify(fields)
@ -1060,7 +1060,7 @@ class Localuser{
async () => { async () => {
if (!confirm("Are you sure you want to reset the bot token? Your bot will stop working until you update it.")) return; if (!confirm("Are you sure you want to reset the bot token? Your bot will stop working until you update it.")) return;
const updateRes=await fetch(this.info.api.toString()+"/v9/applications/" + appId + "/bot/reset", { const updateRes=await fetch(this.info.api+"/v9/applications/" + appId + "/bot/reset", {
method: "POST", method: "POST",
headers: this.headers headers: this.headers
}); });

View file

@ -57,7 +57,7 @@ function setDefaults(){
} }
setDefaults(); setDefaults();
class Specialuser{ class Specialuser{
serverurls; serverurls:{api:string,cdn:string,gateway:string,wellknown:string,login:string};
email:string; email:string;
token:string; token:string;
loggedin; loggedin;
@ -67,10 +67,13 @@ class Specialuser{
console.error("specialuser can't construct from another specialuser"); console.error("specialuser can't construct from another specialuser");
} }
this.serverurls=json.serverurls; this.serverurls=json.serverurls;
this.serverurls.api=new URL(this.serverurls.api); let apistring=new URL(json.serverurls.api).toString();
this.serverurls.cdn=new URL(this.serverurls.cdn); apistring=apistring.replace(/\/(v\d+\/?)?$/, "")+"/v9";
this.serverurls.gateway=new URL(this.serverurls.gateway); this.serverurls.api=apistring;
this.serverurls.wellknown=new URL(this.serverurls.wellknown); this.serverurls.cdn=new URL(json.serverurls.cdn).toString().replace(/\/$/,"");
this.serverurls.gateway=new URL(json.serverurls.gateway).toString().replace(/\/$/,"");;
this.serverurls.wellknown=new URL(json.serverurls.wellknown).toString().replace(/\/$/,"");;
this.serverurls.login=new URL(json.serverurls.login).toString().replace(/\/$/,"");;
this.email=json.email; this.email=json.email;
this.token=json.token; this.token=json.token;
this.loggedin=json.loggedin; this.loggedin=json.loggedin;

View file

@ -421,7 +421,7 @@ class MarkDown{
emojiElem.classList.add("md-emoji"); emojiElem.classList.add("md-emoji");
emojiElem.classList.add(isEmojiOnly ? "bigemoji" : "smallemoji"); emojiElem.classList.add(isEmojiOnly ? "bigemoji" : "smallemoji");
emojiElem.crossOrigin="anonymous"; emojiElem.crossOrigin="anonymous";
emojiElem.src=this.info.cdn.toString() + "emojis/" + parts[2] + "." + (parts[1] ? "gif" : "png") + "?size=32"; emojiElem.src=this.info.cdn + "emojis/" + parts[2] + "." + (parts[1] ? "gif" : "png") + "?size=32";
emojiElem.alt=buildjoin; emojiElem.alt=buildjoin;
emojiElem.loading="lazy"; emojiElem.loading="lazy";

View file

@ -18,7 +18,7 @@ class Member{
navigator.clipboard.writeText(this.id); navigator.clipboard.writeText(this.id);
}); });
this.contextmenu.addbutton("Message user",function(){ this.contextmenu.addbutton("Message user",function(){
fetch(this.info.api.toString()+"/v9/users/@me/channels", fetch(this.info.api+"/v9/users/@me/channels",
{method:"POST", {method:"POST",
body:JSON.stringify({"recipients":[this.id]}), body:JSON.stringify({"recipients":[this.id]}),
headers: this.headers headers: this.headers

View file

@ -86,7 +86,7 @@ class Message{
break; break;
} }
} }
fetch(this.info.api.toString()+ "/channels/"+this.channel.id+"/messages/"+this.id+"/reactions/"+encodeURIComponent(emoji)+"/@me",{ fetch(this.info.api+ "/channels/"+this.channel.id+"/messages/"+this.id+"/reactions/"+encodeURIComponent(emoji)+"/@me",{
method:remove?"DELETE":"PUT", method:remove?"DELETE":"PUT",
headers:this.headers, headers:this.headers,
}) })
@ -186,14 +186,14 @@ class Message{
return build; return build;
} }
async edit(content){ async edit(content){
return await fetch(this.info.api.toString()+"/channels/"+this.channel.snowflake+"/messages/"+this.id,{ return await fetch(this.info.api+"/channels/"+this.channel.snowflake+"/messages/"+this.id,{
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body:JSON.stringify({content:content}) body:JSON.stringify({content:content})
}); });
} }
delete(){ delete(){
fetch(`${this.info.api.toString()}/channels/${this.channel.snowflake}/messages/${this.id}`,{ fetch(`${this.info.api}/channels/${this.channel.snowflake}/messages/${this.id}`,{
headers:this.headers, headers:this.headers,
method:"DELETE", method:"DELETE",
}) })

View file

@ -1044,20 +1044,28 @@ span {
.accountSwitcher{ .accountSwitcher{
background:var(--profile-bg); background:var(--profile-bg);
cursor:pointer; cursor:pointer;
box-shadow: .00in -.5in 1in color-mix(in srgb, var(--shadow) 42%, transparent); box-shadow: .00in -.5in 2in color-mix(in srgb, var(--shadow) 42%, transparent);
border-radius: .05in .05in .0in.0in; border-radius: .1in;
flex-grow: 0;
align-self: center;
flex-shrink: 1;
min-width: 0px; min-width: 0px;
display: inline-block; width: 80vw;
width: 100%; display: flex;
padding-left:.025in; flex-direction: column;
padding: .1in;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-height: 80vh;
overflow: auto;
border:solid var(--black) .035in;
} }
.accountSwitcher tr{ .switchtable{
transition: background .3s; transition: background .3s;
background:var(--profile-bg); background:var(--profile-bg);
} }
.switchtable:hover{
background:var(--profile-info-bg);
}
.accountSwitcher tr:hover{ .accountSwitcher tr:hover{
background:var(--profile-info-bg); background:var(--profile-info-bg);
} }
@ -1636,3 +1644,18 @@ form div{
.dontshrink{ .dontshrink{
flex-shrink:0; flex-shrink:0;
} }
.switchtable{
flex-grow:1;
flex-shrink: 0;
padding: .05in;
border-radius: .1in;
margin-bottom: .05in;
background: var(--message-bg-hover);
border: solid var(--black) .03in;
box-shadow: .01in .01in .05in var(--black);
align-items: center;
}
.userinfo{
margin-left:.1in;
height:fit-content;
}

View file

@ -52,7 +52,7 @@ class User{
navigator.clipboard.writeText(this.id.id); navigator.clipboard.writeText(this.id.id);
}); });
this.contextmenu.addbutton("Message user",function(){ this.contextmenu.addbutton("Message user",function(){
fetch(this.info.api.toString()+"/v9/users/@me/channels", fetch(this.info.api+"/v9/users/@me/channels",
{method:"POST", {method:"POST",
body:JSON.stringify({"recipients":[this.id.id]}), body:JSON.stringify({"recipients":[this.id.id]}),
headers: this.localuser.headers headers: this.localuser.headers
@ -144,9 +144,9 @@ class User{
return this.avatar; return this.avatar;
} }
if(this.avatar!=null){ if(this.avatar!=null){
return this.info.cdn.toString()+"/avatars/"+this.id+"/"+this.avatar+".png"; return this.info.cdn+"/avatars/"+this.id+"/"+this.avatar+".png";
}else{ }else{
return this.info.cdn.toString()+"/embed/avatars/3.png"; return this.info.cdn+"/embed/avatars/3.png";
} }
} }
createjankpromises(){ createjankpromises(){