Updates to fix errors for CC
This commit is contained in:
parent
3ccb7e63e1
commit
274c165357
22 changed files with 731 additions and 926 deletions
|
@ -1,4 +1,3 @@
|
|||
export { Dialog };
|
||||
class Dialog {
|
||||
layout;
|
||||
onclose;
|
||||
|
@ -245,3 +244,4 @@ class Dialog {
|
|||
document.body.removeChild(this.html);
|
||||
}
|
||||
}
|
||||
export { Dialog };
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
388
.dist/index.js
388
.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");
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -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();
|
||||
|
|
222
.dist/invite.js
222
.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);
|
||||
});
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
export { Permissions };
|
||||
class Permissions {
|
||||
allow;
|
||||
deny;
|
||||
|
@ -326,3 +325,4 @@ class Permissions {
|
|||
}
|
||||
}
|
||||
Permissions.makeMap();
|
||||
export { Permissions };
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue