From 274c165357f5712dabae55d49954ce2835eb99c2 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Wed, 21 Aug 2024 14:51:34 -0500 Subject: [PATCH] Updates to fix errors for CC --- .dist/dialog.js | 2 +- .dist/fullscreen.js | 247 --------------------- .dist/index.js | 388 ++++++++++++++++---------------- .dist/infiniteScroller.js | 4 +- .dist/invite.js | 222 ++++++++++--------- .dist/login.js | 2 +- .dist/markdown.js | 2 +- .dist/permissions.js | 2 +- .dist/role.js | 2 +- .gitignore | 1 + index.js | 6 - package-lock.json | 101 ++++++--- package.json | 3 +- webpage/dialog.ts | 3 +- webpage/index.ts | 429 ++++++++++++++++++------------------ webpage/infiniteScroller.ts | 5 +- webpage/invite.ts | 226 +++++++++---------- webpage/login.ts | 3 +- webpage/markdown.ts | 3 +- webpage/permissions.ts | 2 +- webpage/role.ts | 3 +- webpage/style.css | 1 + 22 files changed, 731 insertions(+), 926 deletions(-) delete mode 100644 .dist/fullscreen.js diff --git a/.dist/dialog.js b/.dist/dialog.js index 11ee249..120e90c 100644 --- a/.dist/dialog.js +++ b/.dist/dialog.js @@ -1,4 +1,3 @@ -export { Dialog }; class Dialog { layout; onclose; @@ -245,3 +244,4 @@ class Dialog { document.body.removeChild(this.html); } } +export { Dialog }; diff --git a/.dist/fullscreen.js b/.dist/fullscreen.js deleted file mode 100644 index fc2f3ab..0000000 --- a/.dist/fullscreen.js +++ /dev/null @@ -1,247 +0,0 @@ -export { Dialog }; -class Dialog { - layout; - onclose; - onopen; - html; - background; - constructor(layout, onclose = _ => { }, onopen = _ => { }) { - this.layout = layout; - this.onclose = onclose; - this.onopen = onopen; - const div = document.createElement("div"); - div.appendChild(this.tohtml(layout)); - this.html = div; - this.html.classList.add("centeritem"); - if (!(layout[0] === "img")) { - this.html.classList.add("nonimagecenter"); - } - } - tohtml(array) { - switch (array[0]) { - case "img": - const img = document.createElement("img"); - img.src = array[1]; - if (array[2] != undefined) { - if (array[2].length == 2) { - img.width = array[2][0]; - img.height = array[2][1]; - } - else if (array[2][0] == "fit") { - img.classList.add("imgfit"); - } - } - return img; - case "hdiv": - const hdiv = document.createElement("table"); - const tr = document.createElement("tr"); - hdiv.appendChild(tr); - for (const thing of array) { - if (thing === "hdiv") { - continue; - } - const td = document.createElement("td"); - td.appendChild(this.tohtml(thing)); - tr.appendChild(td); - } - return hdiv; - case "vdiv": - const vdiv = document.createElement("table"); - for (const thing of array) { - if (thing === "vdiv") { - continue; - } - const tr = document.createElement("tr"); - tr.appendChild(this.tohtml(thing)); - vdiv.appendChild(tr); - } - return vdiv; - case "checkbox": - { - const div = document.createElement("div"); - const checkbox = document.createElement('input'); - div.appendChild(checkbox); - const label = document.createElement("span"); - checkbox.checked = array[2]; - label.textContent = array[1]; - div.appendChild(label); - checkbox.addEventListener("change", array[3]); - checkbox.type = "checkbox"; - return div; - } - case "button": - { - const div = document.createElement("div"); - const input = document.createElement('button'); - const label = document.createElement("span"); - input.textContent = array[2]; - label.textContent = array[1]; - div.appendChild(label); - div.appendChild(input); - input.addEventListener("click", array[3]); - return div; - } - case "mdbox": - { - const div = document.createElement("div"); - const input = document.createElement("textarea"); - input.value = array[2]; - const label = document.createElement("span"); - label.textContent = array[1]; - input.addEventListener("input", array[3]); - div.appendChild(label); - div.appendChild(document.createElement("br")); - div.appendChild(input); - return div; - } - case "textbox": - { - const div = document.createElement("div"); - const input = document.createElement("input"); - input.value = array[2]; - input.type = "text"; - const label = document.createElement("span"); - label.textContent = array[1]; - console.log(array[3]); - input.addEventListener("input", array[3]); - div.appendChild(label); - div.appendChild(input); - return div; - } - case "fileupload": - { - const div = document.createElement("div"); - const input = document.createElement("input"); - input.type = "file"; - const label = document.createElement("span"); - label.textContent = array[1]; - div.appendChild(label); - div.appendChild(input); - input.addEventListener("change", array[2]); - console.log(array); - return div; - } - case "text": { - const span = document.createElement("span"); - span.textContent = array[1]; - return span; - } - case "title": { - const span = document.createElement("span"); - span.classList.add("title"); - span.textContent = array[1]; - return span; - } - case "radio": { - const div = document.createElement("div"); - const fieldset = document.createElement("fieldset"); - fieldset.addEventListener("change", function () { - let i = -1; - for (const thing of fieldset.children) { - i++; - if (i === 0) { - continue; - } - const checkbox = thing.children[0].children[0]; - if (checkbox.checked) { - array[3](checkbox.value); - } - } - }); - const legend = document.createElement("legend"); - legend.textContent = array[1]; - fieldset.appendChild(legend); - let i = 0; - for (const thing of array[2]) { - const div = document.createElement("div"); - const input = document.createElement("input"); - input.classList.add("radio"); - input.type = "radio"; - input.name = array[1]; - input.value = thing; - if (i === array[4]) { - input.checked = true; - } - const label = document.createElement("label"); - label.appendChild(input); - const span = document.createElement("span"); - span.textContent = thing; - label.appendChild(span); - div.appendChild(label); - fieldset.appendChild(div); - i++; - } - div.appendChild(fieldset); - return div; - } - case "html": { - return array[1]; - } - case "select": { - const div = document.createElement("div"); - const label = document.createElement("label"); - const select = document.createElement("select"); - label.textContent = array[1]; - div.append(label); - div.appendChild(select); - for (const thing of array[2]) { - const option = document.createElement("option"); - option.textContent = thing; - select.appendChild(option); - } - select.selectedIndex = array[4]; - select.addEventListener("change", array[3]); - return div; - } - case "tabs": { - const table = document.createElement("table"); - const tabs = document.createElement("tr"); - tabs.classList.add("tabbed-head"); - table.appendChild(tabs); - const td = document.createElement("td"); - tabs.appendChild(td); - const content = document.createElement("tr"); - content.classList.add("tabbed-content"); - table.appendChild(content); - let shown; - for (const thing of array[1]) { - const button = document.createElement("button"); - button.textContent = thing[0]; - td.appendChild(button); - const tdcontent = document.createElement("td"); - tdcontent.colSpan = array[1].length; - tdcontent.appendChild(this.tohtml(thing[1])); - content.appendChild(tdcontent); - if (!shown) { - shown = tdcontent; - } - else { - tdcontent.hidden = true; - } - button.addEventListener("click", _ => { - shown.hidden = true; - tdcontent.hidden = false; - shown = tdcontent; - }); - } - return table; - } - default: - console.error("can't find element:" + array[0], " full element:" + array); - return; - } - } - show() { - this.onopen(); - console.log("fullscreen"); - this.background = document.createElement("div"); - this.background.classList.add("background"); - document.body.appendChild(this.background); - document.body.appendChild(this.html); - this.background.onclick = function () { this.hide(); }.bind(this); - } - hide() { - document.body.removeChild(this.background); - document.body.removeChild(this.html); - } -} diff --git a/.dist/index.js b/.dist/index.js index e40eb59..dd8f41a 100644 --- a/.dist/index.js +++ b/.dist/index.js @@ -1,205 +1,207 @@ import { Localuser } from "./localuser.js"; import { Contextmenu } from "./contextmenu.js"; import { mobile, getBulkUsers, setTheme } from "./login.js"; -async function waitforload() { - let res; - new Promise(r => { res = r; }); - document.addEventListener("DOMContentLoaded", function () { - res(); - }); - await res; -} -await waitforload(); -const users = getBulkUsers(); -if (!users.currentuser) { - window.location.href = '/login.html'; -} -function showAccountSwitcher() { - const table = document.createElement("div"); - for (const thing of Object.values(users.users)) { - const specialuser = thing; - console.log(specialuser.pfpsrc); - const userinfo = document.createElement("div"); - userinfo.classList.add("flexltr", "switchtable"); - const pfp = document.createElement("img"); - userinfo.append(pfp); - const user = document.createElement("div"); - userinfo.append(user); - user.append(specialuser.username); - user.append(document.createElement("br")); - const span = document.createElement("span"); - span.textContent = specialuser.serverurls.wellknown.replace("https://", "").replace("http://", ""); - user.append(span); - user.classList.add("userinfo"); - span.classList.add("serverURL"); - pfp.src = specialuser.pfpsrc; - pfp.classList.add("pfp"); - table.append(userinfo); - userinfo.addEventListener("click", _ => { - thisuser.unload(); - thisuser.swapped = true; - const loading = document.getElementById("loading"); - loading.classList.remove("doneloading"); - loading.classList.add("loading"); - thisuser = new Localuser(specialuser); - users["currentuser"] = specialuser.uid; - localStorage.setItem("userinfos", JSON.stringify(users)); - thisuser.initwebsocket().then(_ => { - thisuser.loaduser(); - thisuser.init(); - loading.classList.add("doneloading"); - loading.classList.remove("loading"); - console.log("done loading"); - }); - userinfo.remove(); +import { MarkDown } from "./markdown.js"; +import { File } from "./file.js"; +(async () => { + async function waitforload() { + let res; + new Promise(r => { res = r; }); + document.addEventListener("DOMContentLoaded", function () { + res(); }); + await res; + } + await waitforload(); + const users = getBulkUsers(); + if (!users.currentuser) { + window.location.href = '/login.html'; + } + function showAccountSwitcher() { + const table = document.createElement("div"); + for (const thing of Object.values(users.users)) { + const specialuser = thing; + console.log(specialuser.pfpsrc); + const userinfo = document.createElement("div"); + userinfo.classList.add("flexltr", "switchtable"); + const pfp = document.createElement("img"); + userinfo.append(pfp); + const user = document.createElement("div"); + userinfo.append(user); + user.append(specialuser.username); + user.append(document.createElement("br")); + const span = document.createElement("span"); + span.textContent = specialuser.serverurls.wellknown.replace("https://", "").replace("http://", ""); + user.append(span); + user.classList.add("userinfo"); + span.classList.add("serverURL"); + pfp.src = specialuser.pfpsrc; + pfp.classList.add("pfp"); + table.append(userinfo); + userinfo.addEventListener("click", _ => { + thisuser.unload(); + thisuser.swapped = true; + const loading = document.getElementById("loading"); + loading.classList.remove("doneloading"); + loading.classList.add("loading"); + thisuser = new Localuser(specialuser); + users["currentuser"] = specialuser.uid; + localStorage.setItem("userinfos", JSON.stringify(users)); + thisuser.initwebsocket().then(_ => { + thisuser.loaduser(); + thisuser.init(); + loading.classList.add("doneloading"); + loading.classList.remove("loading"); + console.log("done loading"); + }); + userinfo.remove(); + }); + } + { + const td = document.createElement("div"); + td.classList.add("switchtable"); + td.append("Switch accounts ⇌"); + td.addEventListener("click", _ => { + window.location.href = "/login.html"; + }); + table.append(td); + } + table.classList.add("accountSwitcher"); + if (Contextmenu.currentmenu != "") { + Contextmenu.currentmenu.remove(); + } + Contextmenu.currentmenu = table; + console.log(table); + document.body.append(table); } { - const td = document.createElement("div"); - td.classList.add("switchtable"); - td.append("Switch accounts ⇌"); - td.addEventListener("click", _ => { - window.location.href = "/login.html"; + const userinfo = document.getElementById("userinfo"); + userinfo.addEventListener("click", _ => { + _.stopImmediatePropagation(); + showAccountSwitcher(); }); - table.append(td); + const switchaccounts = document.getElementById("switchaccounts"); + switchaccounts.addEventListener("click", _ => { + _.stopImmediatePropagation(); + showAccountSwitcher(); + }); + console.log("this ran"); } - table.classList.add("accountSwitcher"); - if (Contextmenu.currentmenu != "") { - Contextmenu.currentmenu.remove(); + let thisuser; + try { + console.log(users.users, users.currentuser); + thisuser = new Localuser(users.users[users.currentuser]); + thisuser.initwebsocket().then(_ => { + thisuser.loaduser(); + thisuser.init(); + const loading = document.getElementById("loading"); + loading.classList.add("doneloading"); + loading.classList.remove("loading"); + console.log("done loading"); + }); } - Contextmenu.currentmenu = table; - console.log(table); - document.body.append(table); -} -{ - const userinfo = document.getElementById("userinfo"); - userinfo.addEventListener("click", _ => { - _.stopImmediatePropagation(); - showAccountSwitcher(); - }); - const switchaccounts = document.getElementById("switchaccounts"); - switchaccounts.addEventListener("click", _ => { - _.stopImmediatePropagation(); - showAccountSwitcher(); - }); - console.log("this ran"); -} -let thisuser; -try { - console.log(users.users, users.currentuser); - thisuser = new Localuser(users.users[users.currentuser]); - thisuser.initwebsocket().then(_ => { - thisuser.loaduser(); - thisuser.init(); - const loading = document.getElementById("loading"); - loading.classList.add("doneloading"); - loading.classList.remove("loading"); - console.log("done loading"); - }); -} -catch (e) { - console.error(e); - document.getElementById("load-desc").textContent = "Account unable to start"; - thisuser = new Localuser(-1); -} -{ - const menu = new Contextmenu("create rightclick"); //Really should go into the localuser class, but that's a later thing - menu.addbutton("Create channel", function () { - if (thisuser.lookingguild) { - thisuser.lookingguild.createchannels(); - } - }, null, _ => { return thisuser.isAdmin(); }); - menu.addbutton("Create category", function () { - if (thisuser.lookingguild) { - thisuser.lookingguild.createcategory(); - } - }, null, _ => { return thisuser.isAdmin(); }); - menu.bindContextmenu(document.getElementById("channels"), 0, 0); -} -const pasteimage = document.getElementById("pasteimage"); -let replyingto = null; -async function enter(event) { - const channel = thisuser.channelfocus; - if (!channel || !thisuser.channelfocus) - return; - channel.typingstart(); - if (event.key === "Enter" && !event.shiftKey) { - event.preventDefault(); - if (channel.editing) { - channel.editing.edit(markdown.rawString); - channel.editing = null; - } - else { - replyingto = thisuser.channelfocus.replyingto; - let replying = replyingto; - if (replyingto?.div) { - replyingto.div.classList.remove("replying"); + catch (e) { + console.error(e); + document.getElementById("load-desc").textContent = "Account unable to start"; + thisuser = new Localuser(-1); + } + { + const menu = new Contextmenu("create rightclick"); //Really should go into the localuser class, but that's a later thing + menu.addbutton("Create channel", function () { + if (thisuser.lookingguild) { + thisuser.lookingguild.createchannels(); } - thisuser.channelfocus.replyingto = null; - channel.sendMessage(markdown.rawString, { - attachments: images, - embeds: [], - replyingto: replying - }); - thisuser.channelfocus.makereplybox(); - } - while (images.length != 0) { - images.pop(); - pasteimage.removeChild(imageshtml.pop()); - } - typebox.innerHTML = ""; - return; + }, null, _ => { return thisuser.isAdmin(); }); + menu.addbutton("Create category", function () { + if (thisuser.lookingguild) { + thisuser.lookingguild.createcategory(); + } + }, null, _ => { return thisuser.isAdmin(); }); + menu.bindContextmenu(document.getElementById("channels"), 0, 0); } -} -const typebox = document.getElementById("typebox"); -const markdown = new MarkDown("", thisuser); -markdown.giveBox(typebox); -typebox["markdown"] = markdown; -typebox.addEventListener("keyup", enter); -typebox.addEventListener("keydown", event => { - if (event.key === "Enter" && !event.shiftKey) - event.preventDefault(); -}); -console.log(typebox); -typebox.onclick = console.log; -/* -function getguildinfo(){ - const path=window.location.pathname.split("/"); - const channel=path[3]; - this.ws.send(JSON.stringify({op: 14, d: {guild_id: path[2], channels: {[channel]: [[0, 99]]}}})); -} -*/ -const images = []; -const imageshtml = []; -import { File } from "./file.js"; -import { MarkDown } from "./markdown.js"; -document.addEventListener('paste', async (e) => { - if (!e.clipboardData) - return; - Array.from(e.clipboardData.files).forEach(async (f) => { - const file = File.initFromBlob(f); - e.preventDefault(); - const html = file.upHTML(images, f); - pasteimage.appendChild(html); - images.push(f); - imageshtml.push(html); + const pasteimage = document.getElementById("pasteimage"); + let replyingto = null; + async function enter(event) { + const channel = thisuser.channelfocus; + if (!channel || !thisuser.channelfocus) + return; + channel.typingstart(); + if (event.key === "Enter" && !event.shiftKey) { + event.preventDefault(); + if (channel.editing) { + channel.editing.edit(markdown.rawString); + channel.editing = null; + } + else { + replyingto = thisuser.channelfocus.replyingto; + let replying = replyingto; + if (replyingto?.div) { + replyingto.div.classList.remove("replying"); + } + thisuser.channelfocus.replyingto = null; + channel.sendMessage(markdown.rawString, { + attachments: images, + embeds: [], + replyingto: replying + }); + thisuser.channelfocus.makereplybox(); + } + while (images.length != 0) { + images.pop(); + pasteimage.removeChild(imageshtml.pop()); + } + typebox.innerHTML = ""; + return; + } + } + const typebox = document.getElementById("typebox"); + const markdown = new MarkDown("", thisuser); + markdown.giveBox(typebox); + typebox["markdown"] = markdown; + typebox.addEventListener("keyup", enter); + typebox.addEventListener("keydown", event => { + if (event.key === "Enter" && !event.shiftKey) + event.preventDefault(); }); -}); -setTheme(); -function userSettings() { - thisuser.showusersettings(); -} -document.getElementById("settings").onclick = userSettings; -if (mobile) { - document.getElementById("channelw").onclick = () => { - document.getElementById("channels").parentNode.classList.add("collapse"); - document.getElementById("servertd").classList.add("collapse"); - document.getElementById("servers").classList.add("collapse"); - }; - document.getElementById("mobileback").textContent = "#"; - document.getElementById("mobileback").onclick = () => { - document.getElementById("channels").parentNode.classList.remove("collapse"); - document.getElementById("servertd").classList.remove("collapse"); - document.getElementById("servers").classList.remove("collapse"); - }; -} + console.log(typebox); + typebox.onclick = console.log; + /* + function getguildinfo(){ + const path=window.location.pathname.split("/"); + const channel=path[3]; + this.ws.send(JSON.stringify({op: 14, d: {guild_id: path[2], channels: {[channel]: [[0, 99]]}}})); + } + */ + const images = []; + const imageshtml = []; + document.addEventListener('paste', async (e) => { + if (!e.clipboardData) + return; + Array.from(e.clipboardData.files).forEach(async (f) => { + const file = File.initFromBlob(f); + e.preventDefault(); + const html = file.upHTML(images, f); + pasteimage.appendChild(html); + images.push(f); + imageshtml.push(html); + }); + }); + setTheme(); + function userSettings() { + thisuser.showusersettings(); + } + document.getElementById("settings").onclick = userSettings; + if (mobile) { + document.getElementById("channelw").onclick = () => { + document.getElementById("channels").parentNode.classList.add("collapse"); + document.getElementById("servertd").classList.add("collapse"); + document.getElementById("servers").classList.add("collapse"); + }; + document.getElementById("mobileback").textContent = "#"; + document.getElementById("mobileback").onclick = () => { + document.getElementById("channels").parentNode.classList.remove("collapse"); + document.getElementById("servertd").classList.remove("collapse"); + document.getElementById("servers").classList.remove("collapse"); + }; + } +})(); diff --git a/.dist/infiniteScroller.js b/.dist/infiniteScroller.js index a2e04ca..5526f3c 100644 --- a/.dist/infiniteScroller.js +++ b/.dist/infiniteScroller.js @@ -209,7 +209,7 @@ class InfiniteScroller { return await this.changePromise; } else { - return true; + return false; } } else { @@ -244,8 +244,8 @@ class InfiniteScroller { throw e; } finally { - this.changePromise = undefined; setTimeout(_ => { + this.changePromise = undefined; this.currrunning = false; if (this.watchtime) { this.watchForChange(); diff --git a/.dist/invite.js b/.dist/invite.js index 837fcd8..4e83e70 100644 --- a/.dist/invite.js +++ b/.dist/invite.js @@ -1,116 +1,118 @@ import { getBulkUsers, getapiurls } from "./login.js"; -const users = getBulkUsers(); -const well = new URLSearchParams(window.location.search).get("instance"); -const joinable = []; -for (const thing in users.users) { - const user = users.users[thing]; - if (user.serverurls.wellknown.includes(well)) { - joinable.push(user); - } - console.log(users.users[thing]); -} -let urls; -if (!joinable.length) { - const out = await getapiurls(well); - if (out) { - urls = out; - for (const thing in users.users) { - const user = users.users[thing]; - if (user.serverurls.api.includes(out.api)) { - joinable.push(user); - } - console.log(users.users[thing]); +(async () => { + const users = getBulkUsers(); + const well = new URLSearchParams(window.location.search).get("instance"); + const joinable = []; + for (const thing in users.users) { + const user = users.users[thing]; + if (user.serverurls.wellknown.includes(well)) { + joinable.push(user); } + console.log(users.users[thing]); } - else { - throw Error("someone needs to handle the case where the servers don't exist"); - } -} -else { - urls = joinable[0].serverurls; -} -if (!joinable.length) { - document.getElementById("AcceptInvite").textContent = "Create an account to accept the invite"; -} -const code = window.location.pathname.split("/")[2]; -let guildinfo; -fetch(`${urls.api}/invites/${code}`, { - method: "GET" -}).then(_ => _.json()).then(json => { - const guildjson = json.guild; - guildinfo = guildjson; - document.getElementById("invitename").textContent = guildjson.name; - document.getElementById("invitedescription").textContent = - `${json.inviter.username} invited you to join ${guildjson.name}`; - if (guildjson.icon) { - const img = document.createElement("img"); - img.src = `${urls.cdn}/icons/${guildjson.id}/${guildjson.icon}.png`; - img.classList.add("inviteGuild"); - document.getElementById("inviteimg").append(img); - } - else { - const txt = guildjson.name.replace(/'s /g, " ").replace(/\w+/g, word => word[0]).replace(/\s/g, ""); - const div = document.createElement("div"); - div.textContent = txt; - div.classList.add("inviteGuild"); - document.getElementById("inviteimg").append(div); - } -}); -function showAccounts() { - const table = document.createElement("dialog"); - for (const thing of Object.values(joinable)) { - const specialuser = thing; - console.log(specialuser.pfpsrc); - const userinfo = document.createElement("div"); - userinfo.classList.add("flexltr", "switchtable"); - const pfp = document.createElement("img"); - userinfo.append(pfp); - const user = document.createElement("div"); - userinfo.append(user); - user.append(specialuser.username); - user.append(document.createElement("br")); - const span = document.createElement("span"); - span.textContent = specialuser.serverurls.wellknown.replace("https://", "").replace("http://", ""); - user.append(span); - user.classList.add("userinfo"); - span.classList.add("serverURL"); - pfp.src = specialuser.pfpsrc; - pfp.classList.add("pfp"); - table.append(userinfo); - userinfo.addEventListener("click", _ => { - console.log(thing); - fetch(`${urls.api}/invites/${code}`, { - method: "POST", - headers: { - Authorization: thing.token + let urls; + if (!joinable.length) { + const out = await getapiurls(well); + if (out) { + urls = out; + for (const thing in users.users) { + const user = users.users[thing]; + if (user.serverurls.api.includes(out.api)) { + joinable.push(user); } - }).then(_ => { - users["currentuser"] = specialuser.uid; - localStorage.setItem("userinfos", JSON.stringify(users)); - window.location.href = "/channels/" + guildinfo.id; - }); - }); - } - { - const td = document.createElement("div"); - td.classList.add("switchtable"); - td.append("Login or create an account ⇌"); - td.addEventListener("click", _ => { - const l = new URLSearchParams("?"); - l.set("goback", window.location.href); - l.set("instance", well); - window.location.href = "/login?" + l.toString(); - }); - if (!joinable.length) { - const l = new URLSearchParams("?"); - l.set("goback", window.location.href); - l.set("instance", well); - window.location.href = "/login?" + l.toString(); + console.log(users.users[thing]); + } + } + else { + throw Error("someone needs to handle the case where the servers don't exist"); } - table.append(td); } - table.classList.add("accountSwitcher"); - console.log(table); - document.body.append(table); -} -document.getElementById("AcceptInvite").addEventListener("click", showAccounts); + else { + urls = joinable[0].serverurls; + } + if (!joinable.length) { + document.getElementById("AcceptInvite").textContent = "Create an account to accept the invite"; + } + const code = window.location.pathname.split("/")[2]; + let guildinfo; + fetch(`${urls.api}/invites/${code}`, { + method: "GET" + }).then(_ => _.json()).then(json => { + const guildjson = json.guild; + guildinfo = guildjson; + document.getElementById("invitename").textContent = guildjson.name; + document.getElementById("invitedescription").textContent = + `${json.inviter.username} invited you to join ${guildjson.name}`; + if (guildjson.icon) { + const img = document.createElement("img"); + img.src = `${urls.cdn}/icons/${guildjson.id}/${guildjson.icon}.png`; + img.classList.add("inviteGuild"); + document.getElementById("inviteimg").append(img); + } + else { + const txt = guildjson.name.replace(/'s /g, " ").replace(/\w+/g, word => word[0]).replace(/\s/g, ""); + const div = document.createElement("div"); + div.textContent = txt; + div.classList.add("inviteGuild"); + document.getElementById("inviteimg").append(div); + } + }); + function showAccounts() { + const table = document.createElement("dialog"); + for (const thing of Object.values(joinable)) { + const specialuser = thing; + console.log(specialuser.pfpsrc); + const userinfo = document.createElement("div"); + userinfo.classList.add("flexltr", "switchtable"); + const pfp = document.createElement("img"); + userinfo.append(pfp); + const user = document.createElement("div"); + userinfo.append(user); + user.append(specialuser.username); + user.append(document.createElement("br")); + const span = document.createElement("span"); + span.textContent = specialuser.serverurls.wellknown.replace("https://", "").replace("http://", ""); + user.append(span); + user.classList.add("userinfo"); + span.classList.add("serverURL"); + pfp.src = specialuser.pfpsrc; + pfp.classList.add("pfp"); + table.append(userinfo); + userinfo.addEventListener("click", _ => { + console.log(thing); + fetch(`${urls.api}/invites/${code}`, { + method: "POST", + headers: { + Authorization: thing.token + } + }).then(_ => { + users["currentuser"] = specialuser.uid; + localStorage.setItem("userinfos", JSON.stringify(users)); + window.location.href = "/channels/" + guildinfo.id; + }); + }); + } + { + const td = document.createElement("div"); + td.classList.add("switchtable"); + td.append("Login or create an account ⇌"); + td.addEventListener("click", _ => { + const l = new URLSearchParams("?"); + l.set("goback", window.location.href); + l.set("instance", well); + window.location.href = "/login?" + l.toString(); + }); + if (!joinable.length) { + const l = new URLSearchParams("?"); + l.set("goback", window.location.href); + l.set("instance", well); + window.location.href = "/login?" + l.toString(); + } + table.append(td); + } + table.classList.add("accountSwitcher"); + console.log(table); + document.body.append(table); + } + document.getElementById("AcceptInvite").addEventListener("click", showAccounts); +}); diff --git a/.dist/login.js b/.dist/login.js index 4b06633..f287be6 100644 --- a/.dist/login.js +++ b/.dist/login.js @@ -1,6 +1,5 @@ import { Dialog } from "./dialog.js"; const mobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); -export { mobile, getBulkUsers, getBulkInfo, setTheme, Specialuser, getapiurls, adduser }; function setTheme() { let name = localStorage.getItem("theme"); if (!name) { @@ -387,3 +386,4 @@ if (switchurl) { } export { checkInstance }; trimswitcher(); +export { mobile, getBulkUsers, getBulkInfo, setTheme, Specialuser, getapiurls, adduser }; diff --git a/.dist/markdown.js b/.dist/markdown.js index 0abea4d..52a65e2 100644 --- a/.dist/markdown.js +++ b/.dist/markdown.js @@ -1,6 +1,5 @@ import { Channel } from "./channel.js"; import { Emoji } from "./emoji.js"; -export { MarkDown }; class MarkDown { txt; keep; @@ -565,3 +564,4 @@ function getTextNodeAtPosition(root, index) { position: index }; } +export { MarkDown }; diff --git a/.dist/permissions.js b/.dist/permissions.js index 8bc32c2..0b166aa 100644 --- a/.dist/permissions.js +++ b/.dist/permissions.js @@ -1,4 +1,3 @@ -export { Permissions }; class Permissions { allow; deny; @@ -326,3 +325,4 @@ class Permissions { } } Permissions.makeMap(); +export { Permissions }; diff --git a/.dist/role.js b/.dist/role.js index 26047de..b1f34b6 100644 --- a/.dist/role.js +++ b/.dist/role.js @@ -1,4 +1,3 @@ -export { Role }; import { Permissions } from "./permissions.js"; import { SnowFlake } from "./snowflake.js"; class Role { @@ -43,3 +42,4 @@ class Role { return `#${this.color.toString(16)}`; } } +export { Role }; diff --git a/.gitignore b/.gitignore index 2db5e63..11de622 100644 --- a/.gitignore +++ b/.gitignore @@ -131,3 +131,4 @@ dist #Data file for tomoato testAccount.json +CC diff --git a/index.js b/index.js index 0bb9cfa..e199bf6 100755 --- a/index.js +++ b/index.js @@ -6,12 +6,6 @@ const fs = require('fs'); const app = express(); app.use(compression()) -const tsNode = require('ts-node'); - -tsNode.register({ - transpileOnly: true, - files: true -}); app.use("/getupdates",(req, res) => { const out=fs.statSync(`${__dirname}/webpage`); diff --git a/package-lock.json b/package-lock.json index 3f8b682..82ad6e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,9 @@ "version": "0.1.0", "license": "GPL-3.0", "dependencies": { - "express": "^4.19.2" + "compression": "^1.7.4", + "express": "^4.19.2", + "ts-to-jsdoc": "^2.2.0" }, "devDependencies": { "@eslint/js": "^9.7.0", @@ -17,7 +19,6 @@ "@html-eslint/parser": "^0.25.0", "@stylistic/eslint-plugin": "^2.3.0", "@types/eslint__js": "^8.42.3", - "compression": "^1.7.4", "eslint": "^8.57.0", "eslint-plugin-html": "^8.1.1", "eslint-plugin-sonarjs": "^1.0.4", @@ -423,7 +424,6 @@ "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", - "dev": true, "dependencies": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" @@ -436,7 +436,6 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", - "dev": true, "engines": { "node": ">= 8" } @@ -445,7 +444,6 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", - "dev": true, "dependencies": { "@nodelib/fs.scandir": "2.1.5", "fastq": "^1.6.0" @@ -539,6 +537,18 @@ "eslint": ">=8.40.0" } }, + "node_modules/@ts-morph/common": { + "version": "0.22.0", + "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.22.0.tgz", + "integrity": "sha512-HqNBuV/oIlMKdkLshXd1zKBqNQCsuPEsgQOkfFQ/eUKjRlwndXW1AjN9LVkBEIukm00gGXSRmfkl0Wv5VXLnlw==", + "license": "MIT", + "dependencies": { + "fast-glob": "^3.3.2", + "minimatch": "^9.0.3", + "mkdirp": "^3.0.1", + "path-browserify": "^1.0.1" + } + }, "node_modules/@tsconfig/node10": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", @@ -1006,8 +1016,7 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "node_modules/body-parser": { "version": "1.20.2", @@ -1037,7 +1046,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, "dependencies": { "balanced-match": "^1.0.0" } @@ -1046,7 +1054,6 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", - "dev": true, "dependencies": { "fill-range": "^7.1.1" }, @@ -1207,6 +1214,12 @@ "node": ">=0.8.0" } }, + "node_modules/code-block-writer": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-12.0.0.tgz", + "integrity": "sha512-q4dMFMlXtKR3XNBHyMHt/3pwYNA69EDk00lloMOaaUMKPUXBw6lpXtbu3MMVG6/uOihGnRDOlkyqsONEUj60+w==", + "license": "MIT" + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -1229,7 +1242,6 @@ "version": "2.0.18", "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz", "integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==", - "dev": true, "license": "MIT", "dependencies": { "mime-db": ">= 1.43.0 < 2" @@ -1242,7 +1254,6 @@ "version": "1.7.4", "resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz", "integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==", - "dev": true, "license": "MIT", "dependencies": { "accepts": "~1.3.5", @@ -1261,7 +1272,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", "integrity": "sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.8" @@ -1271,7 +1281,6 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true, "license": "MIT" }, "node_modules/concat-map": { @@ -1941,7 +1950,6 @@ "version": "3.3.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", - "dev": true, "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -1957,7 +1965,6 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, "dependencies": { "is-glob": "^4.0.1" }, @@ -1981,7 +1988,6 @@ "version": "1.17.1", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", - "dev": true, "dependencies": { "reusify": "^1.0.4" } @@ -2002,7 +2008,6 @@ "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", - "dev": true, "dependencies": { "to-regex-range": "^5.0.1" }, @@ -2443,7 +2448,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -2452,7 +2456,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "dev": true, "dependencies": { "is-extglob": "^2.1.1" }, @@ -2464,7 +2467,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true, "engines": { "node": ">=0.12.0" } @@ -2613,7 +2615,6 @@ "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", - "dev": true, "engines": { "node": ">= 8" } @@ -2631,7 +2632,6 @@ "version": "4.0.7", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", - "dev": true, "dependencies": { "braces": "^3.0.3", "picomatch": "^2.3.1" @@ -2644,7 +2644,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, "engines": { "node": ">=8.6" }, @@ -2698,7 +2697,6 @@ "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", - "dev": true, "dependencies": { "brace-expansion": "^2.0.1" }, @@ -2709,6 +2707,21 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/mkdirp": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz", + "integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==", + "license": "MIT", + "bin": { + "mkdirp": "dist/cjs/src/bin.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -2785,7 +2798,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.8" @@ -2895,6 +2907,12 @@ "node": ">= 0.8" } }, + "node_modules/path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "license": "MIT" + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -3020,7 +3038,6 @@ "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", - "dev": true, "funding": [ { "type": "github", @@ -3222,7 +3239,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", - "dev": true, "engines": { "iojs": ">=1.0.0", "node": ">=0.10.0" @@ -3248,7 +3264,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", - "dev": true, "funding": [ { "type": "github", @@ -3532,7 +3547,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, "dependencies": { "is-number": "^7.0.0" }, @@ -3561,6 +3575,16 @@ "typescript": ">=4.2.0" } }, + "node_modules/ts-morph": { + "version": "21.0.1", + "resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-21.0.1.tgz", + "integrity": "sha512-dbDtVdEAncKctzrVZ+Nr7kHpHkv+0JDJb2MjjpBaj8bFeCkePU9rHfMklmhuLFnpeq/EJZk2IhStY6NzqgjOkg==", + "license": "MIT", + "dependencies": { + "@ts-morph/common": "~0.22.0", + "code-block-writer": "^12.0.0" + } + }, "node_modules/ts-node": { "version": "10.9.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", @@ -3605,6 +3629,25 @@ } } }, + "node_modules/ts-to-jsdoc": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/ts-to-jsdoc/-/ts-to-jsdoc-2.2.0.tgz", + "integrity": "sha512-5miE85Iy8Hwo3KU4QpoXxSYbTyA7cUitgUAMZF6cQgvOzRmonNFWbxiYE5JcREqV5uvb0DGT/2BTwemlgyV3UQ==", + "license": "MIT", + "dependencies": { + "arg": "^5.0.1", + "ts-morph": "^21.0.1" + }, + "bin": { + "ts-to-jsdoc": "bin/ts-to-jsdoc" + } + }, + "node_modules/ts-to-jsdoc/node_modules/arg": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz", + "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==", + "license": "MIT" + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/package.json b/package.json index 3e629a9..04e6780 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,9 @@ "author": "MathMan05", "license": "GPL-3.0", "dependencies": { + "compression": "^1.7.4", "express": "^4.19.2", - "compression":"^1.7.4" + "ts-to-jsdoc": "^2.2.0" }, "devDependencies": { "@eslint/js": "^9.7.0", diff --git a/webpage/dialog.ts b/webpage/dialog.ts index def7c25..cbb8ee1 100644 --- a/webpage/dialog.ts +++ b/webpage/dialog.ts @@ -1,4 +1,4 @@ -export {Dialog}; + class Dialog{ layout; onclose: Function; @@ -248,3 +248,4 @@ class Dialog{ document.body.removeChild(this.html); } } +export {Dialog}; diff --git a/webpage/index.ts b/webpage/index.ts index 9427d79..87ea021 100644 --- a/webpage/index.ts +++ b/webpage/index.ts @@ -1,224 +1,225 @@ import { Localuser } from "./localuser.js"; import {Contextmenu} from "./contextmenu.js"; import {mobile, getBulkUsers,setTheme, Specialuser} from "./login.js"; - -async function waitforload(){ - let res; - new Promise(r=>{res=r}); - document.addEventListener("DOMContentLoaded", function(){ - res(); - }); - await res; -} -await waitforload(); - - - -const users=getBulkUsers(); -if(!users.currentuser){ - window.location.href = '/login.html'; -} - - -function showAccountSwitcher(){ - const table=document.createElement("div"); - for(const thing of Object.values(users.users)){ - const specialuser=thing as Specialuser; - console.log(specialuser.pfpsrc) - - const userinfo=document.createElement("div"); - userinfo.classList.add("flexltr","switchtable"); - const pfp=document.createElement("img"); - userinfo.append(pfp); - - const user=document.createElement("div"); - userinfo.append(user); - user.append(specialuser.username); - user.append(document.createElement("br")); - const span=document.createElement("span"); - span.textContent=specialuser.serverurls.wellknown.replace("https://","").replace("http://",""); - user.append(span); - user.classList.add("userinfo") - span.classList.add("serverURL") - - pfp.src=specialuser.pfpsrc; - pfp.classList.add("pfp"); - table.append(userinfo); - userinfo.addEventListener("click",_=>{ - thisuser.unload(); - thisuser.swapped=true; - const loading=document.getElementById("loading") as HTMLDivElement; - loading.classList.remove("doneloading"); - loading.classList.add("loading"); - thisuser=new Localuser(specialuser); - users["currentuser"]=specialuser.uid; - localStorage.setItem("userinfos",JSON.stringify(users)); - thisuser.initwebsocket().then(_=>{ - thisuser.loaduser(); - thisuser.init(); - loading.classList.add("doneloading"); - loading.classList.remove("loading"); - console.log("done loading") - - }); - userinfo.remove(); - }) - } - { - const td=document.createElement("div"); - td.classList.add("switchtable") - td.append("Switch accounts ⇌"); - td.addEventListener("click",_=>{ - window.location.href="/login.html"; - }) - table.append(td); - } - table.classList.add("accountSwitcher"); - if(Contextmenu.currentmenu!=""){ - Contextmenu.currentmenu.remove(); - } - Contextmenu.currentmenu=table; - console.log(table); - document.body.append(table); -} -{ - const userinfo=document.getElementById("userinfo") as HTMLDivElement; - userinfo.addEventListener("click",_=>{ - _.stopImmediatePropagation(); - showAccountSwitcher(); - }) - const switchaccounts=document.getElementById("switchaccounts") as HTMLDivElement; - switchaccounts.addEventListener("click",_=>{ - _.stopImmediatePropagation(); - showAccountSwitcher(); - }) - console.log("this ran") -} -let thisuser:Localuser; -try{ - console.log(users.users,users.currentuser) - thisuser=new Localuser(users.users[users.currentuser]); - thisuser.initwebsocket().then(_=>{ - thisuser.loaduser(); - thisuser.init(); - const loading=document.getElementById("loading") as HTMLDivElement; - loading.classList.add("doneloading"); - loading.classList.remove("loading"); - console.log("done loading") - }); -}catch(e){ - console.error(e); - (document.getElementById("load-desc") as HTMLSpanElement).textContent="Account unable to start"; - thisuser=new Localuser(-1); -} - - -{ - const menu=new Contextmenu("create rightclick");//Really should go into the localuser class, but that's a later thing - menu.addbutton("Create channel",function(){ - if(thisuser.lookingguild){ - thisuser.lookingguild.createchannels(); - } - },null,_=>{return thisuser.isAdmin()}) - - menu.addbutton("Create category",function(){ - if(thisuser.lookingguild){ - thisuser.lookingguild.createcategory(); - } - },null,_=>{return thisuser.isAdmin()}) - menu.bindContextmenu(document.getElementById("channels") as HTMLDivElement,0,0) -} - -const pasteimage=document.getElementById("pasteimage") as HTMLDivElement; -let replyingto:Message|null=null; -async function enter(event){ - const channel=thisuser.channelfocus - if(!channel||!thisuser.channelfocus) return; - channel.typingstart(); - if(event.key === "Enter"&&!event.shiftKey){ - event.preventDefault(); - if(channel.editing){ - channel.editing.edit(markdown.rawString); - channel.editing=null; - }else{ - replyingto= thisuser.channelfocus.replyingto; - let replying=replyingto; - if(replyingto?.div){ - replyingto.div.classList.remove("replying"); - } - thisuser.channelfocus.replyingto=null; - channel.sendMessage(markdown.rawString,{ - attachments:images, - embeds:[], - replyingto:replying - }) - thisuser.channelfocus.makereplybox(); - } - while(images.length!=0){ - images.pop(); - pasteimage.removeChild(imageshtml.pop() as HTMLElement); - } - typebox.innerHTML=""; - return; - } -} - -const typebox=document.getElementById("typebox") as HTMLDivElement; -const markdown=new MarkDown("",thisuser); -markdown.giveBox(typebox); -typebox["markdown"]=markdown; -typebox.addEventListener("keyup",enter); -typebox.addEventListener("keydown",event=>{ - if(event.key === "Enter"&&!event.shiftKey) event.preventDefault(); -}); -console.log(typebox) -typebox.onclick=console.log; - -/* -function getguildinfo(){ - const path=window.location.pathname.split("/"); - const channel=path[3]; - this.ws.send(JSON.stringify({op: 14, d: {guild_id: path[2], channels: {[channel]: [[0, 99]]}}})); -} -*/ - -const images:Blob[]=[]; -const imageshtml:HTMLElement[]=[]; - -import { File } from "./file.js"; import { MarkDown } from "./markdown.js"; import { Message } from "./message.js"; -document.addEventListener('paste', async (e) => { - if(!e.clipboardData) return; - Array.from(e.clipboardData.files).forEach(async (f) => { - const file=File.initFromBlob(f); - e.preventDefault(); - const html=file.upHTML(images,f); - pasteimage.appendChild(html); - images.push(f) - imageshtml.push(html); +import { File } from "./file.js"; +(async()=>{ + async function waitforload(){ + let res; + new Promise(r=>{res=r}); + document.addEventListener("DOMContentLoaded", function(){ + res(); + }); + await res; + } + await waitforload(); + + + + const users=getBulkUsers(); + if(!users.currentuser){ + window.location.href = '/login.html'; + } + + + function showAccountSwitcher(){ + const table=document.createElement("div"); + for(const thing of Object.values(users.users)){ + const specialuser=thing as Specialuser; + console.log(specialuser.pfpsrc) + + const userinfo=document.createElement("div"); + userinfo.classList.add("flexltr","switchtable"); + const pfp=document.createElement("img"); + userinfo.append(pfp); + + const user=document.createElement("div"); + userinfo.append(user); + user.append(specialuser.username); + user.append(document.createElement("br")); + const span=document.createElement("span"); + span.textContent=specialuser.serverurls.wellknown.replace("https://","").replace("http://",""); + user.append(span); + user.classList.add("userinfo") + span.classList.add("serverURL") + + pfp.src=specialuser.pfpsrc; + pfp.classList.add("pfp"); + table.append(userinfo); + userinfo.addEventListener("click",_=>{ + thisuser.unload(); + thisuser.swapped=true; + const loading=document.getElementById("loading") as HTMLDivElement; + loading.classList.remove("doneloading"); + loading.classList.add("loading"); + thisuser=new Localuser(specialuser); + users["currentuser"]=specialuser.uid; + localStorage.setItem("userinfos",JSON.stringify(users)); + thisuser.initwebsocket().then(_=>{ + thisuser.loaduser(); + thisuser.init(); + loading.classList.add("doneloading"); + loading.classList.remove("loading"); + console.log("done loading") + + }); + userinfo.remove(); + }) + } + { + const td=document.createElement("div"); + td.classList.add("switchtable") + td.append("Switch accounts ⇌"); + td.addEventListener("click",_=>{ + window.location.href="/login.html"; + }) + table.append(td); + } + table.classList.add("accountSwitcher"); + if(Contextmenu.currentmenu!=""){ + Contextmenu.currentmenu.remove(); + } + Contextmenu.currentmenu=table; + console.log(table); + document.body.append(table); + } + { + const userinfo=document.getElementById("userinfo") as HTMLDivElement; + userinfo.addEventListener("click",_=>{ + _.stopImmediatePropagation(); + showAccountSwitcher(); + }) + const switchaccounts=document.getElementById("switchaccounts") as HTMLDivElement; + switchaccounts.addEventListener("click",_=>{ + _.stopImmediatePropagation(); + showAccountSwitcher(); + }) + console.log("this ran") + } + let thisuser:Localuser; + try{ + console.log(users.users,users.currentuser) + thisuser=new Localuser(users.users[users.currentuser]); + thisuser.initwebsocket().then(_=>{ + thisuser.loaduser(); + thisuser.init(); + const loading=document.getElementById("loading") as HTMLDivElement; + loading.classList.add("doneloading"); + loading.classList.remove("loading"); + console.log("done loading") + }); + }catch(e){ + console.error(e); + (document.getElementById("load-desc") as HTMLSpanElement).textContent="Account unable to start"; + thisuser=new Localuser(-1); + } + + + { + const menu=new Contextmenu("create rightclick");//Really should go into the localuser class, but that's a later thing + menu.addbutton("Create channel",function(){ + if(thisuser.lookingguild){ + thisuser.lookingguild.createchannels(); + } + },null,_=>{return thisuser.isAdmin()}) + + menu.addbutton("Create category",function(){ + if(thisuser.lookingguild){ + thisuser.lookingguild.createcategory(); + } + },null,_=>{return thisuser.isAdmin()}) + menu.bindContextmenu(document.getElementById("channels") as HTMLDivElement,0,0) + } + + const pasteimage=document.getElementById("pasteimage") as HTMLDivElement; + let replyingto:Message|null=null; + async function enter(event){ + const channel=thisuser.channelfocus + if(!channel||!thisuser.channelfocus) return; + channel.typingstart(); + if(event.key === "Enter"&&!event.shiftKey){ + event.preventDefault(); + if(channel.editing){ + channel.editing.edit(markdown.rawString); + channel.editing=null; + }else{ + replyingto= thisuser.channelfocus.replyingto; + let replying=replyingto; + if(replyingto?.div){ + replyingto.div.classList.remove("replying"); + } + thisuser.channelfocus.replyingto=null; + channel.sendMessage(markdown.rawString,{ + attachments:images, + embeds:[], + replyingto:replying + }) + thisuser.channelfocus.makereplybox(); + } + while(images.length!=0){ + images.pop(); + pasteimage.removeChild(imageshtml.pop() as HTMLElement); + } + typebox.innerHTML=""; + return; + } + } + + const typebox=document.getElementById("typebox") as HTMLDivElement; + const markdown=new MarkDown("",thisuser); + markdown.giveBox(typebox); + typebox["markdown"]=markdown; + typebox.addEventListener("keyup",enter); + typebox.addEventListener("keydown",event=>{ + if(event.key === "Enter"&&!event.shiftKey) event.preventDefault(); }); -}); + console.log(typebox) + typebox.onclick=console.log; -setTheme(); - -function userSettings(){ - thisuser.showusersettings(); -} -(document.getElementById("settings") as HTMLImageElement).onclick=userSettings; - -if(mobile){ - (document.getElementById("channelw") as HTMLDivElement).onclick=()=>{ - ((document.getElementById("channels") as HTMLDivElement).parentNode as HTMLElement).classList.add("collapse"); - (document.getElementById("servertd") as HTMLDivElement).classList.add("collapse"); - (document.getElementById("servers") as HTMLDivElement).classList.add("collapse"); + /* + function getguildinfo(){ + const path=window.location.pathname.split("/"); + const channel=path[3]; + this.ws.send(JSON.stringify({op: 14, d: {guild_id: path[2], channels: {[channel]: [[0, 99]]}}})); } - (document.getElementById("mobileback") as HTMLDivElement).textContent="#"; - (document.getElementById("mobileback") as HTMLDivElement).onclick=()=>{ - ((document.getElementById("channels") as HTMLDivElement).parentNode as HTMLElement).classList.remove("collapse"); - (document.getElementById("servertd") as HTMLDivElement).classList.remove("collapse"); - (document.getElementById("servers") as HTMLDivElement).classList.remove("collapse"); + */ + + const images:Blob[]=[]; + const imageshtml:HTMLElement[]=[]; + + + + document.addEventListener('paste', async (e) => { + if(!e.clipboardData) return; + Array.from(e.clipboardData.files).forEach(async (f) => { + const file=File.initFromBlob(f); + e.preventDefault(); + const html=file.upHTML(images,f); + pasteimage.appendChild(html); + images.push(f) + imageshtml.push(html); + }); + }); + + setTheme(); + + function userSettings(){ + thisuser.showusersettings(); } -} - + (document.getElementById("settings") as HTMLImageElement).onclick=userSettings; + if(mobile){ + (document.getElementById("channelw") as HTMLDivElement).onclick=()=>{ + ((document.getElementById("channels") as HTMLDivElement).parentNode as HTMLElement).classList.add("collapse"); + (document.getElementById("servertd") as HTMLDivElement).classList.add("collapse"); + (document.getElementById("servers") as HTMLDivElement).classList.add("collapse"); + } + (document.getElementById("mobileback") as HTMLDivElement).textContent="#"; + (document.getElementById("mobileback") as HTMLDivElement).onclick=()=>{ + ((document.getElementById("channels") as HTMLDivElement).parentNode as HTMLElement).classList.remove("collapse"); + (document.getElementById("servertd") as HTMLDivElement).classList.remove("collapse"); + (document.getElementById("servers") as HTMLDivElement).classList.remove("collapse"); + } + } +})() diff --git a/webpage/infiniteScroller.ts b/webpage/infiniteScroller.ts index e52358f..6d7e4d4 100644 --- a/webpage/infiniteScroller.ts +++ b/webpage/infiniteScroller.ts @@ -208,7 +208,7 @@ class InfiniteScroller{ if(this.changePromise){ return await this.changePromise; }else{ - return true; + return false; } }else{ this.watchtime=false; @@ -239,8 +239,9 @@ class InfiniteScroller{ throw e; }finally{ - this.changePromise=undefined; + setTimeout(_=>{ + this.changePromise=undefined; this.currrunning=false; if(this.watchtime){ this.watchForChange(); diff --git a/webpage/invite.ts b/webpage/invite.ts index 2caed95..f57db51 100644 --- a/webpage/invite.ts +++ b/webpage/invite.ts @@ -1,118 +1,120 @@ import {getBulkUsers, Specialuser, getapiurls} from "./login.js"; -const users=getBulkUsers(); -const well=new URLSearchParams(window.location.search).get("instance"); -const joinable:Specialuser[]=[]; -for(const thing in users.users){ - const user:Specialuser = users.users[thing] - if(user.serverurls.wellknown.includes(well)){ - joinable.push(user); - } - console.log(users.users[thing]); -} -let urls:{api:string,cdn:string}; -if(!joinable.length){ - const out=await getapiurls(well); - if(out){ - urls=out; - for(const thing in users.users){ - const user:Specialuser = users.users[thing] - if(user.serverurls.api.includes(out.api)){ - joinable.push(user); - } - console.log(users.users[thing]); +(async()=>{ + const users=getBulkUsers(); + const well=new URLSearchParams(window.location.search).get("instance"); + const joinable:Specialuser[]=[]; + for(const thing in users.users){ + const user:Specialuser = users.users[thing] + if(user.serverurls.wellknown.includes(well)){ + joinable.push(user); } - }else{ - throw Error("someone needs to handle the case where the servers don't exist") + console.log(users.users[thing]); } - -}else{ - urls=joinable[0].serverurls; -} -if(!joinable.length){ - document.getElementById("AcceptInvite").textContent="Create an account to accept the invite" -} -const code=window.location.pathname.split("/")[2]; -let guildinfo; -fetch(`${urls.api}/invites/${code}`,{ - method:"GET" -}).then(_=>_.json()).then(json=>{ - const guildjson=json.guild; - guildinfo=guildjson; - document.getElementById("invitename").textContent=guildjson.name; - document.getElementById("invitedescription").textContent= - `${json.inviter.username} invited you to join ${guildjson.name}`; - if(guildjson.icon){ - const img=document.createElement("img"); - img.src=`${urls.cdn}/icons/${guildjson.id}/${guildjson.icon}.png`; - img.classList.add("inviteGuild"); - document.getElementById("inviteimg").append(img); - }else{ - const txt=guildjson.name.replace(/'s /g, " ").replace(/\w+/g, word => word[0]).replace(/\s/g, ""); - const div=document.createElement("div"); - div.textContent=txt; - div.classList.add("inviteGuild"); - document.getElementById("inviteimg").append(div); - } - -}) -function showAccounts(){ - const table=document.createElement("dialog"); - for(const thing of Object.values(joinable)){ - const specialuser=thing as Specialuser; - console.log(specialuser.pfpsrc) - - const userinfo=document.createElement("div"); - userinfo.classList.add("flexltr","switchtable"); - const pfp=document.createElement("img"); - userinfo.append(pfp); - - const user=document.createElement("div"); - userinfo.append(user); - user.append(specialuser.username); - user.append(document.createElement("br")); - const span=document.createElement("span"); - span.textContent=specialuser.serverurls.wellknown.replace("https://","").replace("http://",""); - user.append(span); - user.classList.add("userinfo") - span.classList.add("serverURL") - - pfp.src=specialuser.pfpsrc; - pfp.classList.add("pfp"); - table.append(userinfo); - userinfo.addEventListener("click",_=>{ - console.log(thing); - fetch(`${urls.api}/invites/${code}`,{ - method:"POST", - headers:{ - Authorization:thing.token + let urls:{api:string,cdn:string}; + if(!joinable.length){ + const out=await getapiurls(well); + if(out){ + urls=out; + for(const thing in users.users){ + const user:Specialuser = users.users[thing] + if(user.serverurls.api.includes(out.api)){ + joinable.push(user); } - }).then(_=>{ - users["currentuser"]=specialuser.uid; - localStorage.setItem("userinfos",JSON.stringify(users)); - window.location.href="/channels/"+guildinfo.id; - }) - }) - } - { - const td=document.createElement("div"); - td.classList.add("switchtable") - td.append("Login or create an account ⇌"); - td.addEventListener("click",_=>{ - const l=new URLSearchParams("?") - l.set("goback",window.location.href); - l.set("instance",well); - window.location.href="/login?"+l.toString(); - }) - if(!joinable.length){ - const l=new URLSearchParams("?") - l.set("goback",window.location.href); - l.set("instance",well); - window.location.href="/login?"+l.toString(); + console.log(users.users[thing]); + } + }else{ + throw Error("someone needs to handle the case where the servers don't exist") } - table.append(td); + + }else{ + urls=joinable[0].serverurls; } - table.classList.add("accountSwitcher"); - console.log(table); - document.body.append(table); -} -document.getElementById("AcceptInvite").addEventListener("click",showAccounts); + if(!joinable.length){ + document.getElementById("AcceptInvite").textContent="Create an account to accept the invite" + } + const code=window.location.pathname.split("/")[2]; + let guildinfo; + fetch(`${urls.api}/invites/${code}`,{ + method:"GET" + }).then(_=>_.json()).then(json=>{ + const guildjson=json.guild; + guildinfo=guildjson; + document.getElementById("invitename").textContent=guildjson.name; + document.getElementById("invitedescription").textContent= + `${json.inviter.username} invited you to join ${guildjson.name}`; + if(guildjson.icon){ + const img=document.createElement("img"); + img.src=`${urls.cdn}/icons/${guildjson.id}/${guildjson.icon}.png`; + img.classList.add("inviteGuild"); + document.getElementById("inviteimg").append(img); + }else{ + const txt=guildjson.name.replace(/'s /g, " ").replace(/\w+/g, word => word[0]).replace(/\s/g, ""); + const div=document.createElement("div"); + div.textContent=txt; + div.classList.add("inviteGuild"); + document.getElementById("inviteimg").append(div); + } + + }) + function showAccounts(){ + const table=document.createElement("dialog"); + for(const thing of Object.values(joinable)){ + const specialuser=thing as Specialuser; + console.log(specialuser.pfpsrc) + + const userinfo=document.createElement("div"); + userinfo.classList.add("flexltr","switchtable"); + const pfp=document.createElement("img"); + userinfo.append(pfp); + + const user=document.createElement("div"); + userinfo.append(user); + user.append(specialuser.username); + user.append(document.createElement("br")); + const span=document.createElement("span"); + span.textContent=specialuser.serverurls.wellknown.replace("https://","").replace("http://",""); + user.append(span); + user.classList.add("userinfo") + span.classList.add("serverURL") + + pfp.src=specialuser.pfpsrc; + pfp.classList.add("pfp"); + table.append(userinfo); + userinfo.addEventListener("click",_=>{ + console.log(thing); + fetch(`${urls.api}/invites/${code}`,{ + method:"POST", + headers:{ + Authorization:thing.token + } + }).then(_=>{ + users["currentuser"]=specialuser.uid; + localStorage.setItem("userinfos",JSON.stringify(users)); + window.location.href="/channels/"+guildinfo.id; + }) + }) + } + { + const td=document.createElement("div"); + td.classList.add("switchtable") + td.append("Login or create an account ⇌"); + td.addEventListener("click",_=>{ + const l=new URLSearchParams("?") + l.set("goback",window.location.href); + l.set("instance",well); + window.location.href="/login?"+l.toString(); + }) + if(!joinable.length){ + const l=new URLSearchParams("?") + l.set("goback",window.location.href); + l.set("instance",well); + window.location.href="/login?"+l.toString(); + } + table.append(td); + } + table.classList.add("accountSwitcher"); + console.log(table); + document.body.append(table); + } + document.getElementById("AcceptInvite").addEventListener("click",showAccounts); +}) diff --git a/webpage/login.ts b/webpage/login.ts index e5b960a..807cbab 100644 --- a/webpage/login.ts +++ b/webpage/login.ts @@ -1,7 +1,7 @@ import { Dialog } from "./dialog.js"; const mobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); -export {mobile, getBulkUsers,getBulkInfo,setTheme,Specialuser,getapiurls,adduser} + function setTheme(){ let name=localStorage.getItem("theme"); if(!name){ @@ -379,3 +379,4 @@ if(switchurl){ } export {checkInstance}; trimswitcher(); +export {mobile, getBulkUsers,getBulkInfo,setTheme,Specialuser,getapiurls,adduser} diff --git a/webpage/markdown.ts b/webpage/markdown.ts index 1ce84be..004fb04 100644 --- a/webpage/markdown.ts +++ b/webpage/markdown.ts @@ -2,7 +2,7 @@ import { Channel } from "./channel.js"; import { Emoji } from "./emoji.js"; import { Localuser } from "./localuser.js"; -export {MarkDown}; + class MarkDown{ txt : string[]; keep:boolean; @@ -530,3 +530,4 @@ function getTextNodeAtPosition(root, index){ position: index }; } +export {MarkDown}; diff --git a/webpage/permissions.ts b/webpage/permissions.ts index 34f1c94..8ce18e9 100644 --- a/webpage/permissions.ts +++ b/webpage/permissions.ts @@ -1,4 +1,3 @@ -export {Permissions}; class Permissions{ allow:bigint; deny:bigint; @@ -321,3 +320,4 @@ class Permissions{ } } Permissions.makeMap(); +export {Permissions}; diff --git a/webpage/role.ts b/webpage/role.ts index 4a58382..2a60083 100644 --- a/webpage/role.ts +++ b/webpage/role.ts @@ -1,4 +1,4 @@ -export {Role}; + import {Permissions} from "./permissions.js"; import {Localuser} from "./localuser.js"; import {Guild} from "./guild.js"; @@ -43,3 +43,4 @@ class Role{ return `#${this.color.toString(16)}`; } } +export {Role}; diff --git a/webpage/style.css b/webpage/style.css index fcce055..c178ce8 100644 --- a/webpage/style.css +++ b/webpage/style.css @@ -1920,6 +1920,7 @@ form div{ padding-left: .45in; cursor: pointer; font-weight: bold; + font-style: italic; } .zeroheight{ height: 0px;