Merge branch 'main' into svg-masks
This commit is contained in:
commit
ebf4c5aa6e
60 changed files with 9653 additions and 9426 deletions
|
@ -9,7 +9,7 @@ class Voice {
|
||||||
source;
|
source;
|
||||||
constructor(wave, freq, volume = 1) {
|
constructor(wave, freq, volume = 1) {
|
||||||
this.audioCtx = new (window.AudioContext)();
|
this.audioCtx = new (window.AudioContext)();
|
||||||
this.info = { wave: wave, freq: freq };
|
this.info = { wave, freq };
|
||||||
this.playing = false;
|
this.playing = false;
|
||||||
this.myArrayBuffer = this.audioCtx.createBuffer(1, this.audioCtx.sampleRate, this.audioCtx.sampleRate);
|
this.myArrayBuffer = this.audioCtx.createBuffer(1, this.audioCtx.sampleRate, this.audioCtx.sampleRate);
|
||||||
this.gainNode = this.audioCtx.createGain();
|
this.gainNode = this.audioCtx.createGain();
|
||||||
|
@ -43,7 +43,7 @@ class Voice {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
waveFunction() {
|
waveFunction() {
|
||||||
if (typeof this.wave === 'function') {
|
if (typeof this.wave === "function") {
|
||||||
return this.wave;
|
return this.wave;
|
||||||
}
|
}
|
||||||
switch (this.wave) {
|
switch (this.wave) {
|
||||||
|
@ -92,9 +92,15 @@ class Voice {
|
||||||
case "three": {
|
case "three": {
|
||||||
const voicy = new Voice("sin", 800);
|
const voicy = new Voice("sin", 800);
|
||||||
voicy.play();
|
voicy.play();
|
||||||
setTimeout(_ => { voicy.freq = 1000; }, 50);
|
setTimeout(_ => {
|
||||||
setTimeout(_ => { voicy.freq = 1300; }, 100);
|
voicy.freq = 1000;
|
||||||
setTimeout(_ => { voicy.stop(); }, 150);
|
}, 50);
|
||||||
|
setTimeout(_ => {
|
||||||
|
voicy.freq = 1300;
|
||||||
|
}, 100);
|
||||||
|
setTimeout(_ => {
|
||||||
|
voicy.stop();
|
||||||
|
}, 150);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "zip": {
|
case "zip": {
|
||||||
|
@ -102,23 +108,37 @@ class Voice {
|
||||||
return Math.sin(((t + 2) ** (Math.cos(t * 4))) * Math.PI * 2 * freq);
|
return Math.sin(((t + 2) ** (Math.cos(t * 4))) * Math.PI * 2 * freq);
|
||||||
}, 700);
|
}, 700);
|
||||||
voicy.play();
|
voicy.play();
|
||||||
setTimeout(_ => { voicy.stop(); }, 150);
|
setTimeout(_ => {
|
||||||
|
voicy.stop();
|
||||||
|
}, 150);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "square": {
|
case "square": {
|
||||||
const voicy = new Voice("square", 600, .4);
|
const voicy = new Voice("square", 600, 0.4);
|
||||||
voicy.play();
|
voicy.play();
|
||||||
setTimeout(_ => { voicy.freq = 800; }, 50);
|
setTimeout(_ => {
|
||||||
setTimeout(_ => { voicy.freq = 1000; }, 100);
|
voicy.freq = 800;
|
||||||
setTimeout(_ => { voicy.stop(); }, 150);
|
}, 50);
|
||||||
|
setTimeout(_ => {
|
||||||
|
voicy.freq = 1000;
|
||||||
|
}, 100);
|
||||||
|
setTimeout(_ => {
|
||||||
|
voicy.stop();
|
||||||
|
}, 150);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "beep": {
|
case "beep": {
|
||||||
const voicy = new Voice("sin", 800);
|
const voicy = new Voice("sin", 800);
|
||||||
voicy.play();
|
voicy.play();
|
||||||
setTimeout(_ => { voicy.stop(); }, 50);
|
setTimeout(_ => {
|
||||||
setTimeout(_ => { voicy.play(); }, 100);
|
voicy.stop();
|
||||||
setTimeout(_ => { voicy.stop(); }, 150);
|
}, 50);
|
||||||
|
setTimeout(_ => {
|
||||||
|
voicy.play();
|
||||||
|
}, 100);
|
||||||
|
setTimeout(_ => {
|
||||||
|
voicy.stop();
|
||||||
|
}, 150);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,13 +147,13 @@ class Voice {
|
||||||
return ["three", "zip", "square", "beep"];
|
return ["three", "zip", "square", "beep"];
|
||||||
}
|
}
|
||||||
static setNotificationSound(sound) {
|
static setNotificationSound(sound) {
|
||||||
let userinfos = getBulkInfo();
|
const userinfos = getBulkInfo();
|
||||||
userinfos.preferences.notisound = sound;
|
userinfos.preferences.notisound = sound;
|
||||||
localStorage.setItem("userinfos", JSON.stringify(userinfos));
|
localStorage.setItem("userinfos", JSON.stringify(userinfos));
|
||||||
}
|
}
|
||||||
static getNotificationSound() {
|
static getNotificationSound() {
|
||||||
let userinfos = getBulkInfo();
|
const userinfos = getBulkInfo();
|
||||||
return userinfos.preferences.notisound;
|
return userinfos.preferences.notisound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export { Voice as Voice };
|
export { Voice };
|
||||||
|
|
143
.dist/channel.js
143
.dist/channel.js
|
@ -58,10 +58,14 @@ class Channel {
|
||||||
this.contextmenu.addbutton("Delete channel", function () {
|
this.contextmenu.addbutton("Delete channel", function () {
|
||||||
console.log(this);
|
console.log(this);
|
||||||
this.deleteChannel();
|
this.deleteChannel();
|
||||||
}, null, function () { return this.isAdmin(); });
|
}, null, function () {
|
||||||
|
return this.isAdmin();
|
||||||
|
});
|
||||||
this.contextmenu.addbutton("Edit channel", function () {
|
this.contextmenu.addbutton("Edit channel", function () {
|
||||||
this.editChannel();
|
this.editChannel();
|
||||||
}, null, function () { return this.isAdmin(); });
|
}, null, function () {
|
||||||
|
return this.isAdmin();
|
||||||
|
});
|
||||||
this.contextmenu.addbutton("Make invite", function () {
|
this.contextmenu.addbutton("Make invite", function () {
|
||||||
this.createInvite();
|
this.createInvite();
|
||||||
}, null, function () {
|
}, null, function () {
|
||||||
|
@ -147,12 +151,11 @@ class Channel {
|
||||||
}
|
}
|
||||||
sortPerms() {
|
sortPerms() {
|
||||||
this.permission_overwritesar.sort((a, b) => {
|
this.permission_overwritesar.sort((a, b) => {
|
||||||
const order = this.guild.roles.findIndex(_ => _.snowflake === a[0]) - this.guild.roles.findIndex(_ => _.snowflake === b[0]);
|
return this.guild.roles.findIndex(_ => _.snowflake === a[0]) - this.guild.roles.findIndex(_ => _.snowflake === b[0]);
|
||||||
return order;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setUpInfiniteScroller() {
|
setUpInfiniteScroller() {
|
||||||
this.infinite = new InfiniteScroller(async function (id, offset) {
|
this.infinite = new InfiniteScroller((async (id, offset) => {
|
||||||
const snowflake = id;
|
const snowflake = id;
|
||||||
if (offset === 1) {
|
if (offset === 1) {
|
||||||
if (this.idToPrev.has(snowflake)) {
|
if (this.idToPrev.has(snowflake)) {
|
||||||
|
@ -175,13 +178,12 @@ class Channel {
|
||||||
console.log("at bottom");
|
console.log("at bottom");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.bind(this), async function (id) {
|
}), (async (id) => {
|
||||||
//await new Promise(_=>{setTimeout(_,Math.random()*10)})
|
//await new Promise(_=>{setTimeout(_,Math.random()*10)})
|
||||||
const messgage = this.messages.get(id);
|
const messgage = this.messages.get(id);
|
||||||
try {
|
try {
|
||||||
if (messgage) {
|
if (messgage) {
|
||||||
const html = messgage.buildhtml();
|
return messgage.buildhtml();
|
||||||
return html;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error(id + " not found");
|
console.error(id + " not found");
|
||||||
|
@ -190,18 +192,21 @@ class Channel {
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}.bind(this), async function (id) {
|
return document.createElement("div");
|
||||||
|
}), (async (id) => {
|
||||||
const message = this.messages.get(id);
|
const message = this.messages.get(id);
|
||||||
try {
|
try {
|
||||||
if (message) {
|
if (message) {
|
||||||
message.deleteDiv();
|
message.deleteDiv();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
finally { }
|
finally { }
|
||||||
}.bind(this), this.readbottom.bind(this));
|
return false;
|
||||||
|
}), this.readbottom.bind(this));
|
||||||
}
|
}
|
||||||
constructor(json, owner) {
|
constructor(json, owner) {
|
||||||
if (json === -1) {
|
if (json === -1) {
|
||||||
|
@ -226,7 +231,6 @@ class Channel {
|
||||||
if (thing.id === "1182819038095799904" || thing.id === "1182820803700625444") {
|
if (thing.id === "1182819038095799904" || thing.id === "1182820803700625444") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
|
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
|
||||||
const permission = this.permission_overwrites.get(thing.id);
|
const permission = this.permission_overwrites.get(thing.id);
|
||||||
if (permission) {
|
if (permission) {
|
||||||
|
@ -267,7 +271,7 @@ class Channel {
|
||||||
if (!this.hasPermission("VIEW_CHANNEL")) {
|
if (!this.hasPermission("VIEW_CHANNEL")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.lastmessageid !== this.lastreadmessageid && this.type !== 4 && !!this.lastmessageid;
|
return this.lastmessageid !== this.lastreadmessageid && this.type !== 4 && Boolean(this.lastmessageid);
|
||||||
}
|
}
|
||||||
hasPermission(name, member = this.guild.member) {
|
hasPermission(name, member = this.guild.member) {
|
||||||
if (member.isAdmin()) {
|
if (member.isAdmin()) {
|
||||||
|
@ -276,7 +280,7 @@ class Channel {
|
||||||
for (const thing of member.roles) {
|
for (const thing of member.roles) {
|
||||||
const premission = this.permission_overwrites.get(thing.id);
|
const premission = this.permission_overwrites.get(thing.id);
|
||||||
if (premission) {
|
if (premission) {
|
||||||
let perm = premission.getPermission(name);
|
const perm = premission.getPermission(name);
|
||||||
if (perm) {
|
if (perm) {
|
||||||
return perm === 1;
|
return perm === 1;
|
||||||
}
|
}
|
||||||
|
@ -288,7 +292,7 @@ class Channel {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
get canMessage() {
|
get canMessage() {
|
||||||
if ((0 === this.permission_overwritesar.length) && this.hasPermission("MANAGE_CHANNELS")) {
|
if ((this.permission_overwritesar.length === 0) && this.hasPermission("MANAGE_CHANNELS")) {
|
||||||
const role = this.guild.roles.find(_ => _.name === "@everyone");
|
const role = this.guild.roles.find(_ => _.name === "@everyone");
|
||||||
if (role) {
|
if (role) {
|
||||||
this.addRoleToPerms(role);
|
this.addRoleToPerms(role);
|
||||||
|
@ -297,7 +301,9 @@ class Channel {
|
||||||
return this.hasPermission("SEND_MESSAGES");
|
return this.hasPermission("SEND_MESSAGES");
|
||||||
}
|
}
|
||||||
sortchildren() {
|
sortchildren() {
|
||||||
this.children.sort((a, b) => { return a.position - b.position; });
|
this.children.sort((a, b) => {
|
||||||
|
return a.position - b.position;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
resolveparent(guild) {
|
resolveparent(guild) {
|
||||||
const parentid = this.parent_id?.id;
|
const parentid = this.parent_id?.id;
|
||||||
|
@ -312,7 +318,7 @@ class Channel {
|
||||||
}
|
}
|
||||||
calculateReorder() {
|
calculateReorder() {
|
||||||
let position = -1;
|
let position = -1;
|
||||||
let build = [];
|
const build = [];
|
||||||
for (const thing of this.children) {
|
for (const thing of this.children) {
|
||||||
const thisthing = { id: thing.snowflake, position: undefined, parent_id: undefined };
|
const thisthing = { id: thing.snowflake, position: undefined, parent_id: undefined };
|
||||||
if (thing.position < position) {
|
if (thing.position < position) {
|
||||||
|
@ -347,8 +353,13 @@ class Channel {
|
||||||
}
|
}
|
||||||
div["all"] = this;
|
div["all"] = this;
|
||||||
div.draggable = admin;
|
div.draggable = admin;
|
||||||
div.addEventListener("dragstart", (e) => { Channel.dragged = [this, div]; e.stopImmediatePropagation(); });
|
div.addEventListener("dragstart", e => {
|
||||||
div.addEventListener("dragend", () => { Channel.dragged = []; });
|
Channel.dragged = [this, div];
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
});
|
||||||
|
div.addEventListener("dragend", () => {
|
||||||
|
Channel.dragged = [];
|
||||||
|
});
|
||||||
if (this.type === 4) {
|
if (this.type === 4) {
|
||||||
this.sortchildren();
|
this.sortchildren();
|
||||||
const caps = document.createElement("div");
|
const caps = document.createElement("div");
|
||||||
|
@ -381,17 +392,19 @@ class Channel {
|
||||||
childrendiv.appendChild(channel.createguildHTML(admin));
|
childrendiv.appendChild(channel.createguildHTML(admin));
|
||||||
}
|
}
|
||||||
childrendiv.classList.add("channels");
|
childrendiv.classList.add("channels");
|
||||||
setTimeout(_ => { childrendiv.style.height = childrendiv.scrollHeight + 'px'; }, 100);
|
setTimeout(_ => {
|
||||||
|
childrendiv.style.height = childrendiv.scrollHeight + "px";
|
||||||
|
}, 100);
|
||||||
decdiv.onclick = function () {
|
decdiv.onclick = function () {
|
||||||
if (childrendiv.style.height !== '0px') {
|
if (childrendiv.style.height !== "0px") {
|
||||||
decoration.classList.add("hiddencat");
|
decoration.classList.add("hiddencat");
|
||||||
//childrendiv.classList.add("colapsediv");
|
//childrendiv.classList.add("colapsediv");
|
||||||
childrendiv.style.height = '0px';
|
childrendiv.style.height = "0px";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
decoration.classList.remove("hiddencat");
|
decoration.classList.remove("hiddencat");
|
||||||
//childrendiv.classList.remove("colapsediv")
|
//childrendiv.classList.remove("colapsediv")
|
||||||
childrendiv.style.height = childrendiv.scrollHeight + 'px';
|
childrendiv.style.height = childrendiv.scrollHeight + "px";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
div.appendChild(childrendiv);
|
div.appendChild(childrendiv);
|
||||||
|
@ -474,14 +487,14 @@ class Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
coatDropDiv(div, container = false) {
|
coatDropDiv(div, container = false) {
|
||||||
div.addEventListener("dragenter", (event) => {
|
div.addEventListener("dragenter", event => {
|
||||||
console.log("enter");
|
console.log("enter");
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
div.addEventListener("dragover", (event) => {
|
div.addEventListener("dragover", event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
div.addEventListener("drop", (event) => {
|
div.addEventListener("drop", event => {
|
||||||
const that = Channel.dragged[0];
|
const that = Channel.dragged[0];
|
||||||
if (!that)
|
if (!that)
|
||||||
return;
|
return;
|
||||||
|
@ -538,8 +551,8 @@ class Channel {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: name,
|
name,
|
||||||
type: type,
|
type,
|
||||||
parent_id: this.snowflake,
|
parent_id: this.snowflake,
|
||||||
permission_overwrites: [],
|
permission_overwrites: [],
|
||||||
})
|
})
|
||||||
|
@ -553,22 +566,28 @@ class Channel {
|
||||||
const thistype = this.type;
|
const thistype = this.type;
|
||||||
const full = new Dialog(["hdiv",
|
const full = new Dialog(["hdiv",
|
||||||
["vdiv",
|
["vdiv",
|
||||||
["textbox", "Channel name:", this.name, function () { name = this.value; }],
|
["textbox", "Channel name:", this.name, function () {
|
||||||
["mdbox", "Channel topic:", this.topic, function () { topic = this.value; }],
|
name = this.value;
|
||||||
["checkbox", "NSFW Channel", this.nsfw, function () { nsfw = this.checked; }],
|
}],
|
||||||
|
["mdbox", "Channel topic:", this.topic, function () {
|
||||||
|
topic = this.value;
|
||||||
|
}],
|
||||||
|
["checkbox", "NSFW Channel", this.nsfw, function () {
|
||||||
|
nsfw = this.checked;
|
||||||
|
}],
|
||||||
["button", "", "submit", () => {
|
["button", "", "submit", () => {
|
||||||
fetch(this.info.api + "/channels/" + thisid, {
|
fetch(this.info.api + "/channels/" + thisid, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
"name": name,
|
name,
|
||||||
"type": thistype,
|
type: thistype,
|
||||||
"topic": topic,
|
topic,
|
||||||
"bitrate": 64000,
|
bitrate: 64000,
|
||||||
"user_limit": 0,
|
user_limit: 0,
|
||||||
"nsfw": nsfw,
|
nsfw,
|
||||||
"flags": 0,
|
flags: 0,
|
||||||
"rate_limit_per_user": 0
|
rate_limit_per_user: 0
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
console.log(full);
|
console.log(full);
|
||||||
|
@ -678,7 +697,7 @@ class Channel {
|
||||||
for (let i = 0; i < 15; i++) {
|
for (let i = 0; i < 15; i++) {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
div.classList.add("loadingmessage");
|
div.classList.add("loadingmessage");
|
||||||
if (Math.random() < .5) {
|
if (Math.random() < 0.5) {
|
||||||
const pfp = document.createElement("div");
|
const pfp = document.createElement("div");
|
||||||
pfp.classList.add("loadingpfp");
|
pfp.classList.add("loadingpfp");
|
||||||
const username = document.createElement("div");
|
const username = document.createElement("div");
|
||||||
|
@ -699,7 +718,6 @@ class Channel {
|
||||||
if (this.allthewayup) {
|
if (this.allthewayup) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
if (this.lastreadmessageid && this.messages.has(this.lastreadmessageid)) {
|
if (this.lastreadmessageid && this.messages.has(this.lastreadmessageid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -710,7 +728,7 @@ class Channel {
|
||||||
if (response.length !== 100) {
|
if (response.length !== 100) {
|
||||||
this.allthewayup = true;
|
this.allthewayup = true;
|
||||||
}
|
}
|
||||||
let prev = undefined;
|
let prev;
|
||||||
for (const thing of response) {
|
for (const thing of response) {
|
||||||
const message = new Message(thing, this);
|
const message = new Message(thing, this);
|
||||||
if (prev) {
|
if (prev) {
|
||||||
|
@ -742,7 +760,9 @@ class Channel {
|
||||||
}
|
}
|
||||||
await fetch(this.info.api + "/channels/" + this.id + "/messages?limit=100&after=" + id, {
|
await fetch(this.info.api + "/channels/" + this.id + "/messages?limit=100&after=" + id, {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
}).then((j) => { return j.json(); }).then(response => {
|
}).then(j => {
|
||||||
|
return j.json();
|
||||||
|
}).then(response => {
|
||||||
let previd = id;
|
let previd = id;
|
||||||
for (const i in response) {
|
for (const i in response) {
|
||||||
let messager;
|
let messager;
|
||||||
|
@ -764,7 +784,6 @@ class Channel {
|
||||||
}
|
}
|
||||||
//out.buildmessages();
|
//out.buildmessages();
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
topid;
|
topid;
|
||||||
async grabBefore(id) {
|
async grabBefore(id) {
|
||||||
|
@ -773,7 +792,9 @@ class Channel {
|
||||||
}
|
}
|
||||||
await fetch(this.info.api + "/channels/" + this.id + "/messages?before=" + id + "&limit=100", {
|
await fetch(this.info.api + "/channels/" + this.id + "/messages?before=" + id + "&limit=100", {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
}).then((j) => { return j.json(); }).then((response) => {
|
}).then(j => {
|
||||||
|
return j.json();
|
||||||
|
}).then((response) => {
|
||||||
if (response.length < 100) {
|
if (response.length < 100) {
|
||||||
this.allthewayup = true;
|
this.allthewayup = true;
|
||||||
if (response.length === 0) {
|
if (response.length === 0) {
|
||||||
|
@ -796,7 +817,7 @@ class Channel {
|
||||||
this.idToPrev.set(previd, messager.id);
|
this.idToPrev.set(previd, messager.id);
|
||||||
previd = messager.id;
|
previd = messager.id;
|
||||||
this.messageids.set(messager.snowflake, messager);
|
this.messageids.set(messager.snowflake, messager);
|
||||||
if (+i === response.length - 1 && response.length < 100) {
|
if (Number(i) === response.length - 1 && response.length < 100) {
|
||||||
this.topid = previd;
|
this.topid = previd;
|
||||||
}
|
}
|
||||||
if (willbreak) {
|
if (willbreak) {
|
||||||
|
@ -804,7 +825,6 @@ class Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Please dont use this, its not implemented.
|
* Please dont use this, its not implemented.
|
||||||
|
@ -895,7 +915,7 @@ class Channel {
|
||||||
while (flake && time < flaketime) {
|
while (flake && time < flaketime) {
|
||||||
flake = this.idToPrev.get(flake);
|
flake = this.idToPrev.get(flake);
|
||||||
if (!flake) {
|
if (!flake) {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
flaketime = Number((BigInt(flake) >> 22n) + 1420070400000n);
|
flaketime = Number((BigInt(flake) >> 22n) + 1420070400000n);
|
||||||
}
|
}
|
||||||
|
@ -914,7 +934,6 @@ class Channel {
|
||||||
if (thing.id === "1182819038095799904" || thing.id === "1182820803700625444") {
|
if (thing.id === "1182819038095799904" || thing.id === "1182820803700625444") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
|
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
|
||||||
const permisions = this.permission_overwrites.get(thing.id);
|
const permisions = this.permission_overwrites.get(thing.id);
|
||||||
if (permisions) {
|
if (permisions) {
|
||||||
|
@ -925,10 +944,10 @@ class Channel {
|
||||||
this.nsfw = json.nsfw;
|
this.nsfw = json.nsfw;
|
||||||
}
|
}
|
||||||
typingstart() {
|
typingstart() {
|
||||||
if (this.typing > new Date().getTime()) {
|
if (this.typing > Date.now()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.typing = new Date().getTime() + 6000;
|
this.typing = Date.now() + 6000;
|
||||||
fetch(this.info.api + "/channels/" + this.snowflake + "/typing", {
|
fetch(this.info.api + "/channels/" + this.snowflake + "/typing", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
|
@ -936,11 +955,11 @@ class Channel {
|
||||||
}
|
}
|
||||||
get notification() {
|
get notification() {
|
||||||
let notinumber = this.message_notifications;
|
let notinumber = this.message_notifications;
|
||||||
if (+notinumber === 3) {
|
if (Number(notinumber) === 3) {
|
||||||
notinumber = null;
|
notinumber = null;
|
||||||
}
|
}
|
||||||
notinumber ??= this.guild.message_notifications;
|
notinumber ??= this.guild.message_notifications;
|
||||||
switch (+notinumber) {
|
switch (Number(notinumber)) {
|
||||||
case 0:
|
case 0:
|
||||||
return "all";
|
return "all";
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -956,15 +975,14 @@ class Channel {
|
||||||
if (replyingto) {
|
if (replyingto) {
|
||||||
replyjson =
|
replyjson =
|
||||||
{
|
{
|
||||||
"guild_id": replyingto.guild.id,
|
guild_id: replyingto.guild.id,
|
||||||
"channel_id": replyingto.channel.id,
|
channel_id: replyingto.channel.id,
|
||||||
"message_id": replyingto.id,
|
message_id: replyingto.id,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
;
|
|
||||||
if (attachments.length === 0) {
|
if (attachments.length === 0) {
|
||||||
const body = {
|
const body = {
|
||||||
content: content,
|
content,
|
||||||
nonce: Math.floor(Math.random() * 1000000000),
|
nonce: Math.floor(Math.random() * 1000000000),
|
||||||
message_reference: undefined
|
message_reference: undefined
|
||||||
};
|
};
|
||||||
|
@ -980,21 +998,21 @@ class Channel {
|
||||||
else {
|
else {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
const body = {
|
const body = {
|
||||||
content: content,
|
content,
|
||||||
nonce: Math.floor(Math.random() * 1000000000),
|
nonce: Math.floor(Math.random() * 1000000000),
|
||||||
message_reference: undefined
|
message_reference: undefined
|
||||||
};
|
};
|
||||||
if (replyjson) {
|
if (replyjson) {
|
||||||
body.message_reference = replyjson;
|
body.message_reference = replyjson;
|
||||||
}
|
}
|
||||||
formData.append('payload_json', JSON.stringify(body));
|
formData.append("payload_json", JSON.stringify(body));
|
||||||
for (const i in attachments) {
|
for (const i in attachments) {
|
||||||
formData.append("files[" + i + "]", attachments[i]);
|
formData.append("files[" + i + "]", attachments[i]);
|
||||||
}
|
}
|
||||||
return await fetch(this.info.api + "/channels/" + this.snowflake + "/messages", {
|
return await fetch(this.info.api + "/channels/" + this.snowflake + "/messages", {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
headers: { "Authorization": this.headers.Authorization }
|
headers: { Authorization: this.headers.Authorization }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1079,7 +1097,6 @@ class Channel {
|
||||||
if (deep === 3) {
|
if (deep === 3) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
this.notify(message, deep + 1);
|
this.notify(message, deep + 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1110,7 +1127,7 @@ class Channel {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
allow: permission.allow.toString(),
|
allow: permission.allow.toString(),
|
||||||
deny: permission.deny.toString(),
|
deny: permission.deny.toString(),
|
||||||
id: id,
|
id,
|
||||||
type: 0
|
type: 0
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,7 @@ class Contextmenu {
|
||||||
div;
|
div;
|
||||||
static setup() {
|
static setup() {
|
||||||
Contextmenu.currentmenu = "";
|
Contextmenu.currentmenu = "";
|
||||||
document.addEventListener('click', function (event) {
|
document.addEventListener("click", event => {
|
||||||
if (Contextmenu.currentmenu == "") {
|
if (Contextmenu.currentmenu == "") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,11 @@ class Contextmenu {
|
||||||
makemenu(x, y, addinfo, other) {
|
makemenu(x, y, addinfo, other) {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
div.classList.add("contextmenu", "flexttb");
|
div.classList.add("contextmenu", "flexttb");
|
||||||
|
let visibleButtons = 0;
|
||||||
for (const thing of this.buttons) {
|
for (const thing of this.buttons) {
|
||||||
if (!thing[3].bind(addinfo)(other)) {
|
if (!thing[3].bind(addinfo)(other))
|
||||||
continue;
|
continue;
|
||||||
}
|
visibleButtons++;
|
||||||
const intext = document.createElement("button");
|
const intext = document.createElement("button");
|
||||||
intext.disabled = !thing[4].bind(addinfo)(other);
|
intext.disabled = !thing[4].bind(addinfo)(other);
|
||||||
intext.classList.add("contextbutton");
|
intext.classList.add("contextbutton");
|
||||||
|
@ -44,11 +45,13 @@ class Contextmenu {
|
||||||
}
|
}
|
||||||
div.appendChild(intext);
|
div.appendChild(intext);
|
||||||
}
|
}
|
||||||
|
if (visibleButtons == 0)
|
||||||
|
return;
|
||||||
if (Contextmenu.currentmenu != "") {
|
if (Contextmenu.currentmenu != "") {
|
||||||
Contextmenu.currentmenu.remove();
|
Contextmenu.currentmenu.remove();
|
||||||
}
|
}
|
||||||
div.style.top = y + 'px';
|
div.style.top = y + "px";
|
||||||
div.style.left = x + 'px';
|
div.style.left = x + "px";
|
||||||
document.body.appendChild(div);
|
document.body.appendChild(div);
|
||||||
Contextmenu.keepOnScreen(div);
|
Contextmenu.keepOnScreen(div);
|
||||||
console.log(div);
|
console.log(div);
|
||||||
|
@ -56,7 +59,7 @@ class Contextmenu {
|
||||||
return this.div;
|
return this.div;
|
||||||
}
|
}
|
||||||
bindContextmenu(obj, addinfo, other) {
|
bindContextmenu(obj, addinfo, other) {
|
||||||
const func = (event) => {
|
const func = event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
this.makemenu(event.clientX, event.clientY, addinfo, other);
|
this.makemenu(event.clientX, event.clientY, addinfo, other);
|
||||||
|
@ -72,12 +75,12 @@ class Contextmenu {
|
||||||
console.log(box, docheight, docwidth);
|
console.log(box, docheight, docwidth);
|
||||||
if (box.right > docwidth) {
|
if (box.right > docwidth) {
|
||||||
console.log("test");
|
console.log("test");
|
||||||
obj.style.left = docwidth - box.width + 'px';
|
obj.style.left = docwidth - box.width + "px";
|
||||||
}
|
}
|
||||||
if (box.bottom > docheight) {
|
if (box.bottom > docheight) {
|
||||||
obj.style.top = docheight - box.height + 'px';
|
obj.style.top = docheight - box.height + "px";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Contextmenu.setup();
|
Contextmenu.setup();
|
||||||
export { Contextmenu as Contextmenu };
|
export { Contextmenu };
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Dialog {
|
||||||
case "checkbox":
|
case "checkbox":
|
||||||
{
|
{
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
const checkbox = document.createElement('input');
|
const checkbox = document.createElement("input");
|
||||||
div.appendChild(checkbox);
|
div.appendChild(checkbox);
|
||||||
const label = document.createElement("span");
|
const label = document.createElement("span");
|
||||||
checkbox.checked = array[2];
|
checkbox.checked = array[2];
|
||||||
|
@ -71,7 +71,7 @@ class Dialog {
|
||||||
case "button":
|
case "button":
|
||||||
{
|
{
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
const input = document.createElement('button');
|
const input = document.createElement("button");
|
||||||
const label = document.createElement("span");
|
const label = document.createElement("span");
|
||||||
input.textContent = array[2];
|
input.textContent = array[2];
|
||||||
label.textContent = array[1];
|
label.textContent = array[1];
|
||||||
|
@ -134,7 +134,7 @@ class Dialog {
|
||||||
case "radio": {
|
case "radio": {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
const fieldset = document.createElement("fieldset");
|
const fieldset = document.createElement("fieldset");
|
||||||
fieldset.addEventListener("change", function () {
|
fieldset.addEventListener("change", () => {
|
||||||
let i = -1;
|
let i = -1;
|
||||||
for (const thing of fieldset.children) {
|
for (const thing of fieldset.children) {
|
||||||
i++;
|
i++;
|
||||||
|
@ -173,9 +173,8 @@ class Dialog {
|
||||||
div.appendChild(fieldset);
|
div.appendChild(fieldset);
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
case "html": {
|
case "html":
|
||||||
return array[1];
|
return array[1];
|
||||||
}
|
|
||||||
case "select": {
|
case "select": {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
const label = document.createElement("label");
|
const label = document.createElement("label");
|
||||||
|
@ -227,7 +226,6 @@ class Dialog {
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
console.error("can't find element:" + array[0], " full element:" + array);
|
console.error("can't find element:" + array[0], " full element:" + array);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
show() {
|
show() {
|
||||||
|
@ -237,7 +235,9 @@ class Dialog {
|
||||||
this.background.classList.add("background");
|
this.background.classList.add("background");
|
||||||
document.body.appendChild(this.background);
|
document.body.appendChild(this.background);
|
||||||
document.body.appendChild(this.html);
|
document.body.appendChild(this.html);
|
||||||
this.background.onclick = _ => { this.hide(); };
|
this.background.onclick = _ => {
|
||||||
|
this.hide();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
hide() {
|
hide() {
|
||||||
document.body.removeChild(this.background);
|
document.body.removeChild(this.background);
|
||||||
|
|
|
@ -96,7 +96,6 @@ class Group extends Channel {
|
||||||
this.messageids = new Map();
|
this.messageids = new Map();
|
||||||
this.permission_overwrites = new Map();
|
this.permission_overwrites = new Map();
|
||||||
this.lastmessageid = json.last_message_id;
|
this.lastmessageid = json.last_message_id;
|
||||||
this.lastmessageid ??= null;
|
|
||||||
this.mentions = 0;
|
this.mentions = 0;
|
||||||
this.setUpInfiniteScroller();
|
this.setUpInfiniteScroller();
|
||||||
if (this.lastmessageid) {
|
if (this.lastmessageid) {
|
||||||
|
@ -140,8 +139,8 @@ class Group extends Channel {
|
||||||
const messagez = new Message(messagep.d, this);
|
const messagez = new Message(messagep.d, this);
|
||||||
if (this.lastmessageid) {
|
if (this.lastmessageid) {
|
||||||
this.idToNext.set(this.lastmessageid, messagez.id);
|
this.idToNext.set(this.lastmessageid, messagez.id);
|
||||||
|
this.idToPrev.set(messagez.id, this.lastmessageid);
|
||||||
}
|
}
|
||||||
this.idToPrev.set(messagez.id, this.lastmessageid);
|
|
||||||
this.lastmessageid = messagez.id;
|
this.lastmessageid = messagez.id;
|
||||||
this.messageids.set(messagez.snowflake, messagez);
|
this.messageids.set(messagez.snowflake, messagez);
|
||||||
if (messagez.author === this.localuser.user) {
|
if (messagez.author === this.localuser.user) {
|
||||||
|
|
|
@ -119,7 +119,6 @@ class Embed {
|
||||||
if (this.json?.timestamp) {
|
if (this.json?.timestamp) {
|
||||||
const span = document.createElement("span");
|
const span = document.createElement("span");
|
||||||
span.textContent = new Date(this.json.timestamp).toLocaleString();
|
span.textContent = new Date(this.json.timestamp).toLocaleString();
|
||||||
;
|
|
||||||
footer.append(span);
|
footer.append(span);
|
||||||
}
|
}
|
||||||
embed.append(footer);
|
embed.append(footer);
|
||||||
|
|
|
@ -62,10 +62,8 @@ class Emoji {
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
array[i] = read8();
|
array[i] = read8();
|
||||||
}
|
}
|
||||||
const decoded = new TextDecoder("utf-8").decode(array.buffer);
|
|
||||||
;
|
|
||||||
//console.log(array);
|
//console.log(array);
|
||||||
return decoded;
|
return new TextDecoder("utf-8").decode(array.buffer);
|
||||||
}
|
}
|
||||||
const build = [];
|
const build = [];
|
||||||
let cats = read16();
|
let cats = read16();
|
||||||
|
@ -78,7 +76,7 @@ class Emoji {
|
||||||
const name = readString8();
|
const name = readString8();
|
||||||
const len = read8();
|
const len = read8();
|
||||||
const skin_tone_support = len > 127;
|
const skin_tone_support = len > 127;
|
||||||
const emoji = readStringNo(len - (+skin_tone_support * 128));
|
const emoji = readStringNo(len - (Number(skin_tone_support) * 128));
|
||||||
emojis.push({
|
emojis.push({
|
||||||
name,
|
name,
|
||||||
skin_tone_support,
|
skin_tone_support,
|
||||||
|
@ -102,7 +100,9 @@ class Emoji {
|
||||||
}
|
}
|
||||||
static async emojiPicker(x, y, localuser) {
|
static async emojiPicker(x, y, localuser) {
|
||||||
let res;
|
let res;
|
||||||
const promise = new Promise((r) => { res = r; });
|
const promise = new Promise(r => {
|
||||||
|
res = r;
|
||||||
|
});
|
||||||
const menu = document.createElement("div");
|
const menu = document.createElement("div");
|
||||||
menu.classList.add("flextttb", "emojiPicker");
|
menu.classList.add("flextttb", "emojiPicker");
|
||||||
menu.style.top = y + "px";
|
menu.style.top = y + "px";
|
||||||
|
|
|
@ -31,7 +31,7 @@ class File {
|
||||||
this.width /= scale;
|
this.width /= scale;
|
||||||
this.height /= scale;
|
this.height /= scale;
|
||||||
}
|
}
|
||||||
if (this.content_type.startsWith('image/')) {
|
if (this.content_type.startsWith("image/")) {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
const img = document.createElement("img");
|
const img = document.createElement("img");
|
||||||
img.classList.add("messageimg");
|
img.classList.add("messageimg");
|
||||||
|
@ -50,7 +50,7 @@ class File {
|
||||||
console.log(this.width, this.height);
|
console.log(this.width, this.height);
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
else if (this.content_type.startsWith('video/')) {
|
else if (this.content_type.startsWith("video/")) {
|
||||||
const video = document.createElement("video");
|
const video = document.createElement("video");
|
||||||
const source = document.createElement("source");
|
const source = document.createElement("source");
|
||||||
source.src = src;
|
source.src = src;
|
||||||
|
@ -63,7 +63,7 @@ class File {
|
||||||
}
|
}
|
||||||
return video;
|
return video;
|
||||||
}
|
}
|
||||||
else if (this.content_type.startsWith('audio/')) {
|
else if (this.content_type.startsWith("audio/")) {
|
||||||
const audio = document.createElement("audio");
|
const audio = document.createElement("audio");
|
||||||
const source = document.createElement("source");
|
const source = document.createElement("source");
|
||||||
source.src = src;
|
source.src = src;
|
||||||
|
@ -138,8 +138,8 @@ class File {
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
static filesizehuman(fsize) {
|
static filesizehuman(fsize) {
|
||||||
var i = fsize == 0 ? 0 : Math.floor(Math.log(fsize) / Math.log(1024));
|
const i = fsize == 0 ? 0 : Math.floor(Math.log(fsize) / Math.log(1024));
|
||||||
return +((fsize / Math.pow(1024, i)).toFixed(2)) * 1 + ' ' + ['Bytes', 'Kilobytes', 'Megabytes', 'Gigabytes', 'Terabytes'][i];
|
return Number((fsize / Math.pow(1024, i)).toFixed(2)) * 1 + " " + ["Bytes", "Kilobytes", "Megabytes", "Gigabytes", "Terabytes"][i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export { File };
|
export { File };
|
||||||
|
|
|
@ -149,7 +149,7 @@ class Guild {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
"message_notifications": noti
|
message_notifications: noti
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
this.message_notifications = noti;
|
this.message_notifications = noti;
|
||||||
|
@ -202,7 +202,7 @@ class Guild {
|
||||||
}
|
}
|
||||||
calculateReorder() {
|
calculateReorder() {
|
||||||
let position = -1;
|
let position = -1;
|
||||||
let build = [];
|
const build = [];
|
||||||
for (const thing of this.headchannels) {
|
for (const thing of this.headchannels) {
|
||||||
const thisthing = { id: thing.snowflake, position: undefined, parent_id: undefined };
|
const thisthing = { id: thing.snowflake, position: undefined, parent_id: undefined };
|
||||||
if (thing.position <= position) {
|
if (thing.position <= position) {
|
||||||
|
@ -256,7 +256,9 @@ class Guild {
|
||||||
return this.owner.info;
|
return this.owner.info;
|
||||||
}
|
}
|
||||||
sortchannels() {
|
sortchannels() {
|
||||||
this.headchannels.sort((a, b) => { return a.position - b.position; });
|
this.headchannels.sort((a, b) => {
|
||||||
|
return a.position - b.position;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
generateGuildIcon() {
|
generateGuildIcon() {
|
||||||
const divy = document.createElement("div");
|
const divy = document.createElement("div");
|
||||||
|
@ -279,7 +281,7 @@ class Guild {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
let build = this.properties.name.replace(/'s /g, " ").replace(/\w+/g, word => word[0]).replace(/\s/g, "");
|
const build = this.properties.name.replace(/'s /g, " ").replace(/\w+/g, word => word[0]).replace(/\s/g, "");
|
||||||
div.textContent = build;
|
div.textContent = build;
|
||||||
div.classList.add("blankserver", "servericon");
|
div.classList.add("blankserver", "servericon");
|
||||||
divy.appendChild(div);
|
divy.appendChild(div);
|
||||||
|
@ -336,7 +338,7 @@ class Guild {
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
unreads(html = undefined) {
|
unreads(html) {
|
||||||
if (html) {
|
if (html) {
|
||||||
this.html = html;
|
this.html = html;
|
||||||
}
|
}
|
||||||
|
@ -399,7 +401,7 @@ class Guild {
|
||||||
}
|
}
|
||||||
return this.member.hasRole(r);
|
return this.member.hasRole(r);
|
||||||
}
|
}
|
||||||
loadChannel(ID = undefined) {
|
loadChannel(ID) {
|
||||||
if (ID && this.channelids[ID]) {
|
if (ID && this.channelids[ID]) {
|
||||||
this.channelids[ID].getHTML();
|
this.channelids[ID].getHTML();
|
||||||
return;
|
return;
|
||||||
|
@ -451,7 +453,7 @@ class Guild {
|
||||||
["voice", "text", "announcement"],
|
["voice", "text", "announcement"],
|
||||||
function (e) {
|
function (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
category = { "text": 0, "voice": 2, "announcement": 5, "category": 4 }[e];
|
category = { text: 0, voice: 2, announcement: 5, category: 4 }[e];
|
||||||
},
|
},
|
||||||
1
|
1
|
||||||
],
|
],
|
||||||
|
@ -463,12 +465,12 @@ class Guild {
|
||||||
console.log(name, category);
|
console.log(name, category);
|
||||||
func(name, category);
|
func(name, category);
|
||||||
channelselect.hide();
|
channelselect.hide();
|
||||||
}.bind(this)]]);
|
}]]);
|
||||||
channelselect.show();
|
channelselect.show();
|
||||||
}
|
}
|
||||||
createcategory() {
|
createcategory() {
|
||||||
let name = "";
|
let name = "";
|
||||||
let category = 4;
|
const category = 4;
|
||||||
const channelselect = new Dialog(["vdiv",
|
const channelselect = new Dialog(["vdiv",
|
||||||
["textbox", "Name of category", "", function () {
|
["textbox", "Name of category", "", function () {
|
||||||
console.log(this);
|
console.log(this);
|
||||||
|
@ -510,7 +512,7 @@ class Guild {
|
||||||
fetch(this.info.api + "/guilds/" + this.snowflake + "/channels", {
|
fetch(this.info.api + "/guilds/" + this.snowflake + "/channels", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({ name: name, type: type })
|
body: JSON.stringify({ name, type })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async createRole(name) {
|
async createRole(name) {
|
||||||
|
@ -518,7 +520,7 @@ class Guild {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: name,
|
name,
|
||||||
color: 0,
|
color: 0,
|
||||||
permissions: "0"
|
permissions: "0"
|
||||||
})
|
})
|
||||||
|
|
|
@ -33,7 +33,7 @@ fetch("/instances.json").then(_ => _.json()).then((json) => {
|
||||||
if (instance.descriptionLong) {
|
if (instance.descriptionLong) {
|
||||||
p.innerText = instance.descriptionLong;
|
p.innerText = instance.descriptionLong;
|
||||||
}
|
}
|
||||||
else {
|
else if (instance.description) {
|
||||||
p.innerText = instance.description;
|
p.innerText = instance.description;
|
||||||
}
|
}
|
||||||
textbox.append(p);
|
textbox.append(p);
|
||||||
|
|
|
@ -6,8 +6,10 @@ import { File } from "./file.js";
|
||||||
(async () => {
|
(async () => {
|
||||||
async function waitforload() {
|
async function waitforload() {
|
||||||
let res;
|
let res;
|
||||||
new Promise(r => { res = r; });
|
new Promise(r => {
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
res = r;
|
||||||
|
});
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
res();
|
res();
|
||||||
});
|
});
|
||||||
await res;
|
await res;
|
||||||
|
@ -15,7 +17,7 @@ import { File } from "./file.js";
|
||||||
await waitforload();
|
await waitforload();
|
||||||
const users = getBulkUsers();
|
const users = getBulkUsers();
|
||||||
if (!users.currentuser) {
|
if (!users.currentuser) {
|
||||||
window.location.href = '/login.html';
|
window.location.href = "/login.html";
|
||||||
}
|
}
|
||||||
function showAccountSwitcher() {
|
function showAccountSwitcher() {
|
||||||
const table = document.createElement("div");
|
const table = document.createElement("div");
|
||||||
|
@ -45,7 +47,7 @@ import { File } from "./file.js";
|
||||||
loading.classList.remove("doneloading");
|
loading.classList.remove("doneloading");
|
||||||
loading.classList.add("loading");
|
loading.classList.add("loading");
|
||||||
thisuser = new Localuser(specialuser);
|
thisuser = new Localuser(specialuser);
|
||||||
users["currentuser"] = specialuser.uid;
|
users.currentuser = specialuser.uid;
|
||||||
localStorage.setItem("userinfos", JSON.stringify(users));
|
localStorage.setItem("userinfos", JSON.stringify(users));
|
||||||
thisuser.initwebsocket().then(_ => {
|
thisuser.initwebsocket().then(_ => {
|
||||||
thisuser.loaduser();
|
thisuser.loaduser();
|
||||||
|
@ -107,16 +109,20 @@ import { File } from "./file.js";
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const menu = new Contextmenu("create rightclick"); //Really should go into the localuser class, but that's a later thing
|
const menu = new Contextmenu("create rightclick"); //Really should go into the localuser class, but that's a later thing
|
||||||
menu.addbutton("Create channel", function () {
|
menu.addbutton("Create channel", () => {
|
||||||
if (thisuser.lookingguild) {
|
if (thisuser.lookingguild) {
|
||||||
thisuser.lookingguild.createchannels();
|
thisuser.lookingguild.createchannels();
|
||||||
}
|
}
|
||||||
}, null, _ => { return thisuser.isAdmin(); });
|
}, null, _ => {
|
||||||
menu.addbutton("Create category", function () {
|
return thisuser.isAdmin();
|
||||||
|
});
|
||||||
|
menu.addbutton("Create category", () => {
|
||||||
if (thisuser.lookingguild) {
|
if (thisuser.lookingguild) {
|
||||||
thisuser.lookingguild.createcategory();
|
thisuser.lookingguild.createcategory();
|
||||||
}
|
}
|
||||||
}, null, _ => { return thisuser.isAdmin(); });
|
}, null, _ => {
|
||||||
|
return thisuser.isAdmin();
|
||||||
|
});
|
||||||
menu.bindContextmenu(document.getElementById("channels"), 0, 0);
|
menu.bindContextmenu(document.getElementById("channels"), 0, 0);
|
||||||
}
|
}
|
||||||
const pasteimage = document.getElementById("pasteimage");
|
const pasteimage = document.getElementById("pasteimage");
|
||||||
|
@ -134,7 +140,7 @@ import { File } from "./file.js";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
replyingto = thisuser.channelfocus.replyingto;
|
replyingto = thisuser.channelfocus.replyingto;
|
||||||
let replying = replyingto;
|
const replying = replyingto;
|
||||||
if (replyingto?.div) {
|
if (replyingto?.div) {
|
||||||
replyingto.div.classList.remove("replying");
|
replyingto.div.classList.remove("replying");
|
||||||
}
|
}
|
||||||
|
@ -151,7 +157,6 @@ import { File } from "./file.js";
|
||||||
pasteimage.removeChild(imageshtml.pop());
|
pasteimage.removeChild(imageshtml.pop());
|
||||||
}
|
}
|
||||||
typebox.innerHTML = "";
|
typebox.innerHTML = "";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const typebox = document.getElementById("typebox");
|
const typebox = document.getElementById("typebox");
|
||||||
|
@ -174,7 +179,7 @@ import { File } from "./file.js";
|
||||||
*/
|
*/
|
||||||
const images = [];
|
const images = [];
|
||||||
const imageshtml = [];
|
const imageshtml = [];
|
||||||
document.addEventListener('paste', async (e) => {
|
document.addEventListener("paste", async (e) => {
|
||||||
if (!e.clipboardData)
|
if (!e.clipboardData)
|
||||||
return;
|
return;
|
||||||
Array.from(e.clipboardData.files).forEach(async (f) => {
|
Array.from(e.clipboardData.files).forEach(async (f) => {
|
||||||
|
|
|
@ -32,7 +32,7 @@ class InfiniteScroller {
|
||||||
this.watchForChange();
|
this.watchForChange();
|
||||||
});
|
});
|
||||||
this.scroll.addEventListener("scroll", _ => {
|
this.scroll.addEventListener("scroll", _ => {
|
||||||
if (null === this.timeout) {
|
if (this.timeout === null) {
|
||||||
this.timeout = setTimeout(this.updatestuff.bind(this), 300);
|
this.timeout = setTimeout(this.updatestuff.bind(this), 300);
|
||||||
}
|
}
|
||||||
this.watchForChange();
|
this.watchForChange();
|
||||||
|
@ -71,10 +71,8 @@ class InfiniteScroller {
|
||||||
this.averageheight = 60;
|
this.averageheight = 60;
|
||||||
}
|
}
|
||||||
this.scrollTop = this.scroll.scrollTop;
|
this.scrollTop = this.scroll.scrollTop;
|
||||||
if (!this.scrollBottom) {
|
if (!this.scrollBottom && !await this.watchForChange()) {
|
||||||
if (!await this.watchForChange()) {
|
this.reachesBottom();
|
||||||
this.reachesBottom();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!this.scrollTop) {
|
if (!this.scrollTop) {
|
||||||
await this.watchForChange();
|
await this.watchForChange();
|
||||||
|
@ -129,7 +127,6 @@ class InfiniteScroller {
|
||||||
this.HTMLElements.unshift([html, nextid]);
|
this.HTMLElements.unshift([html, nextid]);
|
||||||
this.scrollTop += this.averageheight;
|
this.scrollTop += this.averageheight;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
if (this.scrollTop > this.maxDist) {
|
if (this.scrollTop > this.maxDist) {
|
||||||
const html = this.HTMLElements.shift();
|
const html = this.HTMLElements.shift();
|
||||||
|
@ -176,7 +173,6 @@ class InfiniteScroller {
|
||||||
this.HTMLElements.push([html, nextid]);
|
this.HTMLElements.push([html, nextid]);
|
||||||
this.scrollBottom += this.averageheight;
|
this.scrollBottom += this.averageheight;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
if (scrollBottom > this.maxDist) {
|
if (scrollBottom > this.maxDist) {
|
||||||
const html = this.HTMLElements.pop();
|
const html = this.HTMLElements.pop();
|
||||||
|
@ -225,14 +221,14 @@ class InfiniteScroller {
|
||||||
}
|
}
|
||||||
const out = await Promise.allSettled([this.watchForTop(), this.watchForBottom()]);
|
const out = await Promise.allSettled([this.watchForTop(), this.watchForBottom()]);
|
||||||
const changed = (out[0].value || out[1].value);
|
const changed = (out[0].value || out[1].value);
|
||||||
if (null === this.timeout && changed) {
|
if (this.timeout === null && changed) {
|
||||||
this.timeout = setTimeout(this.updatestuff.bind(this), 300);
|
this.timeout = setTimeout(this.updatestuff.bind(this), 300);
|
||||||
}
|
}
|
||||||
if (!this.currrunning) {
|
if (!this.currrunning) {
|
||||||
console.error("something really bad happened");
|
console.error("something really bad happened");
|
||||||
}
|
}
|
||||||
res(!!changed);
|
res(Boolean(changed));
|
||||||
return !!changed;
|
return Boolean(changed);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { getBulkUsers, getapiurls } from "./login.js";
|
||||||
console.log(users.users[thing]);
|
console.log(users.users[thing]);
|
||||||
}
|
}
|
||||||
let urls;
|
let urls;
|
||||||
if (!joinable.length) {
|
if (!joinable.length && well) {
|
||||||
const out = await getapiurls(well);
|
const out = await getapiurls(well);
|
||||||
if (out) {
|
if (out) {
|
||||||
urls = out;
|
urls = out;
|
||||||
|
@ -24,7 +24,7 @@ import { getBulkUsers, getapiurls } from "./login.js";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw Error("someone needs to handle the case where the servers don't exist");
|
throw new Error("someone needs to handle the case where the servers don't exist");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -86,7 +86,7 @@ import { getBulkUsers, getapiurls } from "./login.js";
|
||||||
Authorization: thing.token
|
Authorization: thing.token
|
||||||
}
|
}
|
||||||
}).then(_ => {
|
}).then(_ => {
|
||||||
users["currentuser"] = specialuser.uid;
|
users.currentuser = specialuser.uid;
|
||||||
localStorage.setItem("userinfos", JSON.stringify(users));
|
localStorage.setItem("userinfos", JSON.stringify(users));
|
||||||
window.location.href = "/channels/" + guildinfo.id;
|
window.location.href = "/channels/" + guildinfo.id;
|
||||||
});
|
});
|
||||||
|
|
|
@ -125,7 +125,6 @@ class Localuser {
|
||||||
async initwebsocket() {
|
async initwebsocket() {
|
||||||
let returny;
|
let returny;
|
||||||
const ws = new WebSocket(this.serverurls.gateway.toString() + "?encoding=json&v=9" + (DecompressionStream ? "&compress=zlib-stream" : ""));
|
const ws = new WebSocket(this.serverurls.gateway.toString() + "?encoding=json&v=9" + (DecompressionStream ? "&compress=zlib-stream" : ""));
|
||||||
;
|
|
||||||
this.ws = ws;
|
this.ws = ws;
|
||||||
let ds;
|
let ds;
|
||||||
let w;
|
let w;
|
||||||
|
@ -138,27 +137,27 @@ class Localuser {
|
||||||
r = ds.readable.getReader();
|
r = ds.readable.getReader();
|
||||||
arr = new Uint8Array();
|
arr = new Uint8Array();
|
||||||
}
|
}
|
||||||
const promise = new Promise((res) => {
|
const promise = new Promise(res => {
|
||||||
returny = res;
|
returny = res;
|
||||||
ws.addEventListener('open', (_event) => {
|
ws.addEventListener("open", _event => {
|
||||||
console.log('WebSocket connected');
|
console.log("WebSocket connected");
|
||||||
ws.send(JSON.stringify({
|
ws.send(JSON.stringify({
|
||||||
"op": 2,
|
op: 2,
|
||||||
"d": {
|
d: {
|
||||||
"token": this.token,
|
token: this.token,
|
||||||
"capabilities": 16381,
|
capabilities: 16381,
|
||||||
"properties": {
|
properties: {
|
||||||
"browser": "Jank Client",
|
browser: "Jank Client",
|
||||||
"client_build_number": 0, //might update this eventually lol
|
client_build_number: 0, //might update this eventually lol
|
||||||
"release_channel": "Custom",
|
release_channel: "Custom",
|
||||||
"browser_user_agent": navigator.userAgent
|
browser_user_agent: navigator.userAgent
|
||||||
},
|
},
|
||||||
"compress": !!DecompressionStream,
|
compress: Boolean(DecompressionStream),
|
||||||
"presence": {
|
presence: {
|
||||||
"status": "online",
|
status: "online",
|
||||||
"since": null, //new Date().getTime()
|
since: null, //new Date().getTime()
|
||||||
"activities": [],
|
activities: [],
|
||||||
"afk": false
|
afk: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -183,8 +182,8 @@ class Localuser {
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let order = new Promise((res) => (res()));
|
let order = new Promise(res => (res()));
|
||||||
ws.addEventListener('message', async (event) => {
|
ws.addEventListener("message", async (event) => {
|
||||||
const temp2 = order;
|
const temp2 = order;
|
||||||
order = new Promise(async (res) => {
|
order = new Promise(async (res) => {
|
||||||
await temp2;
|
await temp2;
|
||||||
|
@ -261,7 +260,7 @@ class Localuser {
|
||||||
case 5:
|
case 5:
|
||||||
{
|
{
|
||||||
const breakappart = new URL(this.info.wellknown).origin.split(".");
|
const breakappart = new URL(this.info.wellknown).origin.split(".");
|
||||||
const url = "https://" + breakappart[breakappart.length - 2] + "." + breakappart[breakappart.length - 1];
|
const url = "https://" + breakappart.at(-2) + "." + breakappart.at(-1);
|
||||||
const newurls = await getapiurls(url);
|
const newurls = await getapiurls(url);
|
||||||
if (newurls) {
|
if (newurls) {
|
||||||
this.info = newurls;
|
this.info = newurls;
|
||||||
|
@ -290,7 +289,6 @@ class Localuser {
|
||||||
document.getElementById("load-desc").textContent = "Unable to connect to the Spacebar server. Please try logging out and back in.";
|
document.getElementById("load-desc").textContent = "Unable to connect to the Spacebar server. Please try logging out and back in.";
|
||||||
});
|
});
|
||||||
await promise;
|
await promise;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
async handleEvent(temp) {
|
async handleEvent(temp) {
|
||||||
console.debug(temp);
|
console.debug(temp);
|
||||||
|
@ -418,7 +416,7 @@ class Localuser {
|
||||||
}
|
}
|
||||||
heartbeat_interval;
|
heartbeat_interval;
|
||||||
resolveChannelFromID(ID) {
|
resolveChannelFromID(ID) {
|
||||||
let resolve = this.guilds.find(guild => guild.channelids[ID]);
|
const resolve = this.guilds.find(guild => guild.channelids[ID]);
|
||||||
if (resolve) {
|
if (resolve) {
|
||||||
return resolve.channelids[ID];
|
return resolve.channelids[ID];
|
||||||
}
|
}
|
||||||
|
@ -648,7 +646,7 @@ class Localuser {
|
||||||
content.appendChild(title);
|
content.appendChild(title);
|
||||||
const guilds = document.createElement("div");
|
const guilds = document.createElement("div");
|
||||||
guilds.id = "discovery-guild-content";
|
guilds.id = "discovery-guild-content";
|
||||||
json.guilds.forEach((guild) => {
|
json.guilds.forEach(guild => {
|
||||||
const content = document.createElement("div");
|
const content = document.createElement("div");
|
||||||
content.classList.add("discovery-guild");
|
content.classList.add("discovery-guild");
|
||||||
if (guild.banner) {
|
if (guild.banner) {
|
||||||
|
@ -716,13 +714,13 @@ class Localuser {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("user is typing and you should see it");
|
console.log("user is typing and you should see it");
|
||||||
this.typing.set(memb, new Date().getTime());
|
this.typing.set(memb, Date.now());
|
||||||
setTimeout(this.rendertyping.bind(this), 10000);
|
setTimeout(this.rendertyping.bind(this), 10000);
|
||||||
this.rendertyping();
|
this.rendertyping();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updatepfp(file) {
|
updatepfp(file) {
|
||||||
var reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
reader.onload = () => {
|
reader.onload = () => {
|
||||||
fetch(this.info.api + "/users/@me", {
|
fetch(this.info.api + "/users/@me", {
|
||||||
|
@ -736,7 +734,7 @@ class Localuser {
|
||||||
}
|
}
|
||||||
updatebanner(file) {
|
updatebanner(file) {
|
||||||
if (file) {
|
if (file) {
|
||||||
var reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
reader.onload = () => {
|
reader.onload = () => {
|
||||||
fetch(this.info.api + "/users/@me", {
|
fetch(this.info.api + "/users/@me", {
|
||||||
|
@ -770,7 +768,7 @@ class Localuser {
|
||||||
let build = "";
|
let build = "";
|
||||||
let showing = false;
|
let showing = false;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const curtime = new Date().getTime() - 5000;
|
const curtime = Date.now() - 5000;
|
||||||
for (const thing of this.typing.keys()) {
|
for (const thing of this.typing.keys()) {
|
||||||
if (this.typing.get(thing) > curtime) {
|
if (this.typing.get(thing) > curtime) {
|
||||||
if (i !== 0) {
|
if (i !== 0) {
|
||||||
|
@ -804,15 +802,15 @@ class Localuser {
|
||||||
typingtext.classList.add("hidden");
|
typingtext.classList.add("hidden");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
showusersettings() {
|
async showusersettings() {
|
||||||
const settings = new Settings("Settings");
|
const settings = new Settings("Settings");
|
||||||
{
|
{
|
||||||
const userOptions = settings.addButton("User Settings", { ltr: true });
|
const userOptions = settings.addButton("User Settings", { ltr: true });
|
||||||
const hypotheticalProfile = document.createElement("div");
|
const hypotheticalProfile = document.createElement("div");
|
||||||
let file = undefined;
|
let file;
|
||||||
let newpronouns = undefined;
|
let newpronouns;
|
||||||
let newbio = undefined;
|
let newbio;
|
||||||
let hypouser = this.user.clone();
|
const hypouser = this.user.clone();
|
||||||
let color;
|
let color;
|
||||||
async function regen() {
|
async function regen() {
|
||||||
hypotheticalProfile.textContent = "";
|
hypotheticalProfile.textContent = "";
|
||||||
|
@ -836,7 +834,6 @@ class Localuser {
|
||||||
regen();
|
regen();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
if (_.length) {
|
if (_.length) {
|
||||||
file = _[0];
|
file = _[0];
|
||||||
const blob = URL.createObjectURL(file);
|
const blob = URL.createObjectURL(file);
|
||||||
|
@ -845,7 +842,7 @@ class Localuser {
|
||||||
regen();
|
regen();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let bfile = undefined;
|
let bfile;
|
||||||
const binput = settingsLeft.addFileInput("Upload banner:", _ => {
|
const binput = settingsLeft.addFileInput("Upload banner:", _ => {
|
||||||
if (bfile !== undefined) {
|
if (bfile !== undefined) {
|
||||||
this.updatebanner(bfile);
|
this.updatebanner(bfile);
|
||||||
|
@ -870,7 +867,7 @@ class Localuser {
|
||||||
let changed = false;
|
let changed = false;
|
||||||
const pronounbox = settingsLeft.addTextInput("Pronouns", _ => {
|
const pronounbox = settingsLeft.addTextInput("Pronouns", _ => {
|
||||||
if (newpronouns || newbio || changed) {
|
if (newpronouns || newbio || changed) {
|
||||||
this.updateProfile({ pronouns: newpronouns, bio: newbio, accent_color: parseInt("0x" + color.substr(1), 16) });
|
this.updateProfile({ pronouns: newpronouns, bio: newbio, accent_color: Number.parseInt("0x" + color.substr(1), 16) });
|
||||||
}
|
}
|
||||||
}, { initText: this.user.pronouns });
|
}, { initText: this.user.pronouns });
|
||||||
pronounbox.watchForChange(_ => {
|
pronounbox.watchForChange(_ => {
|
||||||
|
@ -891,11 +888,11 @@ class Localuser {
|
||||||
else {
|
else {
|
||||||
color = "transparent";
|
color = "transparent";
|
||||||
}
|
}
|
||||||
const colorPicker = settingsLeft.addColorInput("Profile color", (_) => { }, { initColor: color });
|
const colorPicker = settingsLeft.addColorInput("Profile color", _ => { }, { initColor: color });
|
||||||
colorPicker.watchForChange(_ => {
|
colorPicker.watchForChange(_ => {
|
||||||
console.log();
|
console.log();
|
||||||
color = _;
|
color = _;
|
||||||
hypouser.accent_color = parseInt("0x" + _.substr(1), 16);
|
hypouser.accent_color = Number.parseInt("0x" + _.substr(1), 16);
|
||||||
changed = true;
|
changed = true;
|
||||||
regen();
|
regen();
|
||||||
});
|
});
|
||||||
|
@ -922,7 +919,7 @@ class Localuser {
|
||||||
tas.addColorInput("Accent color:", _ => {
|
tas.addColorInput("Accent color:", _ => {
|
||||||
userinfos.accent_color = _;
|
userinfos.accent_color = _;
|
||||||
localStorage.setItem("userinfos", JSON.stringify(userinfos));
|
localStorage.setItem("userinfos", JSON.stringify(userinfos));
|
||||||
document.documentElement.style.setProperty('--accent-color', userinfos.accent_color);
|
document.documentElement.style.setProperty("--accent-color", userinfos.accent_color);
|
||||||
}, { initColor: userinfos.accent_color });
|
}, { initColor: userinfos.accent_color });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -986,7 +983,9 @@ class Localuser {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
security.addButtonInput("", "Change discriminator", () => {
|
security.addButtonInput("", "Change discriminator", () => {
|
||||||
const form = security.addSubForm("Change Discriminator", (_) => { security.returnFromSub(); }, {
|
const form = security.addSubForm("Change Discriminator", _ => {
|
||||||
|
security.returnFromSub();
|
||||||
|
}, {
|
||||||
fetchURL: (this.info.api + "/users/@me/"),
|
fetchURL: (this.info.api + "/users/@me/"),
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
method: "PATCH"
|
method: "PATCH"
|
||||||
|
@ -994,7 +993,9 @@ class Localuser {
|
||||||
form.addTextInput("New discriminator:", "discriminator");
|
form.addTextInput("New discriminator:", "discriminator");
|
||||||
});
|
});
|
||||||
security.addButtonInput("", "Change email", () => {
|
security.addButtonInput("", "Change email", () => {
|
||||||
const form = security.addSubForm("Change Email", (_) => { security.returnFromSub(); }, {
|
const form = security.addSubForm("Change Email", _ => {
|
||||||
|
security.returnFromSub();
|
||||||
|
}, {
|
||||||
fetchURL: (this.info.api + "/users/@me/"),
|
fetchURL: (this.info.api + "/users/@me/"),
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
method: "PATCH"
|
method: "PATCH"
|
||||||
|
@ -1006,7 +1007,9 @@ class Localuser {
|
||||||
form.addTextInput("New email:", "email");
|
form.addTextInput("New email:", "email");
|
||||||
});
|
});
|
||||||
security.addButtonInput("", "Change username", () => {
|
security.addButtonInput("", "Change username", () => {
|
||||||
const form = security.addSubForm("Change Username", (_) => { security.returnFromSub(); }, {
|
const form = security.addSubForm("Change Username", _ => {
|
||||||
|
security.returnFromSub();
|
||||||
|
}, {
|
||||||
fetchURL: (this.info.api + "/users/@me/"),
|
fetchURL: (this.info.api + "/users/@me/"),
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
method: "PATCH"
|
method: "PATCH"
|
||||||
|
@ -1018,7 +1021,9 @@ class Localuser {
|
||||||
form.addTextInput("New username:", "username");
|
form.addTextInput("New username:", "username");
|
||||||
});
|
});
|
||||||
security.addButtonInput("", "Change password", () => {
|
security.addButtonInput("", "Change password", () => {
|
||||||
const form = security.addSubForm("Change Password", (_) => { security.returnFromSub(); }, {
|
const form = security.addSubForm("Change Password", _ => {
|
||||||
|
security.returnFromSub();
|
||||||
|
}, {
|
||||||
fetchURL: (this.info.api + "/users/@me/"),
|
fetchURL: (this.info.api + "/users/@me/"),
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
method: "PATCH"
|
method: "PATCH"
|
||||||
|
@ -1079,23 +1084,27 @@ class Localuser {
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const devPortal = settings.addButton("Developer Portal");
|
const devPortal = settings.addButton("Developer Portal");
|
||||||
let appName = "";
|
const teamsRes = await fetch(this.info.api + "/teams", {
|
||||||
devPortal.addTextInput("Name:", value => {
|
headers: this.headers
|
||||||
appName = value;
|
|
||||||
});
|
});
|
||||||
devPortal.addButtonInput("", "Create application", async () => {
|
const teams = await teamsRes.json();
|
||||||
if (appName.trim().length == 0) {
|
devPortal.addButtonInput("", "Create application", () => {
|
||||||
return alert("Please enter a name for the application.");
|
const form = devPortal.addSubForm("Create application", (json) => {
|
||||||
}
|
if (json.message)
|
||||||
const res = await fetch(this.info.api + "/applications", {
|
form.error("name", json.message);
|
||||||
method: "POST",
|
else {
|
||||||
|
devPortal.returnFromSub();
|
||||||
|
this.manageApplication(json.id);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
fetchURL: this.info.api + "/applications",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
method: "POST"
|
||||||
name: appName
|
});
|
||||||
})
|
form.addTextInput("Name", "name", { required: true });
|
||||||
|
form.addSelect("Team", "team_id", ["Personal", ...teams.map(team => team.name)], {
|
||||||
|
defaultIndex: 0
|
||||||
});
|
});
|
||||||
const json = await res.json();
|
|
||||||
this.manageApplication(json.id);
|
|
||||||
});
|
});
|
||||||
const appListContainer = document.createElement("div");
|
const appListContainer = document.createElement("div");
|
||||||
appListContainer.id = "app-list-container";
|
appListContainer.id = "app-list-container";
|
||||||
|
@ -1288,7 +1297,7 @@ class Localuser {
|
||||||
guildmap = new Map();
|
guildmap = new Map();
|
||||||
this.waitingmembers.set(guildid, guildmap);
|
this.waitingmembers.set(guildid, guildmap);
|
||||||
}
|
}
|
||||||
const promise = new Promise((res) => {
|
const promise = new Promise(res => {
|
||||||
guildmap.set(id, res);
|
guildmap.set(id, res);
|
||||||
this.getmembers();
|
this.getmembers();
|
||||||
});
|
});
|
||||||
|
@ -1324,7 +1333,9 @@ class Localuser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getmembers() {
|
async getmembers() {
|
||||||
const promise = new Promise(res => { setTimeout(res, 10); });
|
const promise = new Promise(res => {
|
||||||
|
setTimeout(res, 10);
|
||||||
|
});
|
||||||
await promise; //allow for more to be sent at once :P
|
await promise; //allow for more to be sent at once :P
|
||||||
if (this.ws) {
|
if (this.ws) {
|
||||||
this.waitingmembers.forEach(async (value, guildid) => {
|
this.waitingmembers.forEach(async (value, guildid) => {
|
||||||
|
@ -1339,13 +1350,11 @@ class Localuser {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
|
||||||
if (!build.length) {
|
if (!build.length) {
|
||||||
this.waitingmembers.delete(guildid);
|
this.waitingmembers.delete(guildid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
;
|
const promise = new Promise(res => {
|
||||||
const promise = new Promise((res) => {
|
|
||||||
const nonce = "" + Math.floor(Math.random() * 100000000000);
|
const nonce = "" + Math.floor(Math.random() * 100000000000);
|
||||||
this.noncemap.set(nonce, res);
|
this.noncemap.set(nonce, res);
|
||||||
this.noncebuild.set(nonce, [[], [], []]);
|
this.noncebuild.set(nonce, [[], [], []]);
|
||||||
|
@ -1364,7 +1373,6 @@ class Localuser {
|
||||||
this.fetchingmembers.set(guildid, true);
|
this.fetchingmembers.set(guildid, true);
|
||||||
});
|
});
|
||||||
const prom = await promise;
|
const prom = await promise;
|
||||||
;
|
|
||||||
const data = prom[0];
|
const data = prom[0];
|
||||||
for (const thing of data) {
|
for (const thing of data) {
|
||||||
if (value.has(thing.id)) {
|
if (value.has(thing.id)) {
|
||||||
|
|
|
@ -22,13 +22,13 @@ function trimswitcher() {
|
||||||
for (const thing in json.users) {
|
for (const thing in json.users) {
|
||||||
const user = json.users[thing];
|
const user = json.users[thing];
|
||||||
let wellknown = user.serverurls.wellknown;
|
let wellknown = user.serverurls.wellknown;
|
||||||
if (wellknown[wellknown.length - 1] !== "/") {
|
if (wellknown.at(-1) !== "/") {
|
||||||
wellknown += "/";
|
wellknown += "/";
|
||||||
}
|
}
|
||||||
wellknown += user.username;
|
wellknown += user.username;
|
||||||
if (map.has(wellknown)) {
|
if (map.has(wellknown)) {
|
||||||
const otheruser = map.get(wellknown);
|
const otheruser = map.get(wellknown);
|
||||||
if (otheruser[1].serverurls.wellknown[otheruser[1].serverurls.wellknown.length - 1] === "/") {
|
if (otheruser[1].serverurls.wellknown.at(-1) === "/") {
|
||||||
delete json.users[otheruser[0]];
|
delete json.users[otheruser[0]];
|
||||||
map.set(wellknown, [thing, user]);
|
map.set(wellknown, [thing, user]);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ function trimswitcher() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const thing in json.users) {
|
for (const thing in json.users) {
|
||||||
if (thing[thing.length - 1] === "/") {
|
if (thing.at(-1) === "/") {
|
||||||
const user = json.users[thing];
|
const user = json.users[thing];
|
||||||
delete json.users[thing];
|
delete json.users[thing];
|
||||||
json.users[thing.slice(0, -1)] = user;
|
json.users[thing.slice(0, -1)] = user;
|
||||||
|
@ -73,7 +73,7 @@ function setDefaults() {
|
||||||
if (userinfos.accent_color === undefined) {
|
if (userinfos.accent_color === undefined) {
|
||||||
userinfos.accent_color = "#242443";
|
userinfos.accent_color = "#242443";
|
||||||
}
|
}
|
||||||
document.documentElement.style.setProperty('--accent-color', userinfos.accent_color);
|
document.documentElement.style.setProperty("--accent-color", userinfos.accent_color);
|
||||||
if (userinfos.preferences === undefined) {
|
if (userinfos.preferences === undefined) {
|
||||||
userinfos.preferences = {
|
userinfos.preferences = {
|
||||||
theme: "Dark",
|
theme: "Dark",
|
||||||
|
@ -103,11 +103,8 @@ class Specialuser {
|
||||||
this.serverurls.api = apistring;
|
this.serverurls.api = apistring;
|
||||||
this.serverurls.cdn = new URL(json.serverurls.cdn).toString().replace(/\/$/, "");
|
this.serverurls.cdn = new URL(json.serverurls.cdn).toString().replace(/\/$/, "");
|
||||||
this.serverurls.gateway = new URL(json.serverurls.gateway).toString().replace(/\/$/, "");
|
this.serverurls.gateway = new URL(json.serverurls.gateway).toString().replace(/\/$/, "");
|
||||||
;
|
|
||||||
this.serverurls.wellknown = new URL(json.serverurls.wellknown).toString().replace(/\/$/, "");
|
this.serverurls.wellknown = new URL(json.serverurls.wellknown).toString().replace(/\/$/, "");
|
||||||
;
|
|
||||||
this.serverurls.login = new URL(json.serverurls.login).toString().replace(/\/$/, "");
|
this.serverurls.login = new URL(json.serverurls.login).toString().replace(/\/$/, "");
|
||||||
;
|
|
||||||
this.email = json.email;
|
this.email = json.email;
|
||||||
this.token = json.token;
|
this.token = json.token;
|
||||||
this.loggedin = json.loggedin;
|
this.loggedin = json.loggedin;
|
||||||
|
@ -178,12 +175,12 @@ async function getapiurls(str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (str[str.length - 1] !== "/") {
|
if (str.at(-1) !== "/") {
|
||||||
str += "/";
|
str += "/";
|
||||||
}
|
}
|
||||||
let api;
|
let api;
|
||||||
try {
|
try {
|
||||||
const info = await fetch(`${str}/.well-known/spacebar`).then((x) => x.json());
|
const info = await fetch(`${str}/.well-known/spacebar`).then(x => x.json());
|
||||||
api = info.api;
|
api = info.api;
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
@ -191,7 +188,7 @@ async function getapiurls(str) {
|
||||||
}
|
}
|
||||||
const url = new URL(api);
|
const url = new URL(api);
|
||||||
try {
|
try {
|
||||||
const info = await fetch(`${api}${url.pathname.includes("api") ? "" : "api"}/policies/instance/domains`).then((x) => x.json());
|
const info = await fetch(`${api}${url.pathname.includes("api") ? "" : "api"}/policies/instance/domains`).then(x => x.json());
|
||||||
return {
|
return {
|
||||||
api: info.apiEndpoint,
|
api: info.apiEndpoint,
|
||||||
gateway: info.gateway,
|
gateway: info.gateway,
|
||||||
|
@ -226,8 +223,8 @@ async function checkInstance(e) {
|
||||||
instanceinfo.value = instancein.value;
|
instanceinfo.value = instancein.value;
|
||||||
localStorage.setItem("instanceinfo", JSON.stringify(instanceinfo));
|
localStorage.setItem("instanceinfo", JSON.stringify(instanceinfo));
|
||||||
verify.textContent = "Instance is all good";
|
verify.textContent = "Instance is all good";
|
||||||
if (checkInstance["alt"]) {
|
if (checkInstance.alt) {
|
||||||
checkInstance["alt"]();
|
checkInstance.alt();
|
||||||
}
|
}
|
||||||
setTimeout(_ => {
|
setTimeout(_ => {
|
||||||
console.log(verify.textContent);
|
console.log(verify.textContent);
|
||||||
|
@ -238,7 +235,7 @@ async function checkInstance(e) {
|
||||||
verify.textContent = "Invalid Instance, try again";
|
verify.textContent = "Invalid Instance, try again";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch {
|
||||||
console.log("catch");
|
console.log("catch");
|
||||||
verify.textContent = "Invalid Instance, try again";
|
verify.textContent = "Invalid Instance, try again";
|
||||||
}
|
}
|
||||||
|
@ -271,10 +268,10 @@ async function login(username, password, captcha) {
|
||||||
const options = {
|
const options = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
"login": username,
|
login: username,
|
||||||
"password": password,
|
password,
|
||||||
"undelete": false,
|
undelete: false,
|
||||||
"captcha_key": captcha
|
captcha_key: captcha
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-type": "application/json; charset=UTF-8",
|
"Content-type": "application/json; charset=UTF-8",
|
||||||
|
@ -283,10 +280,10 @@ async function login(username, password, captcha) {
|
||||||
try {
|
try {
|
||||||
const info = JSON.parse(localStorage.getItem("instanceinfo"));
|
const info = JSON.parse(localStorage.getItem("instanceinfo"));
|
||||||
const api = info.login + (info.login.startsWith("/") ? "/" : "");
|
const api = info.login + (info.login.startsWith("/") ? "/" : "");
|
||||||
return await fetch(api + '/auth/login', options).then(response => response.json())
|
return await fetch(api + "/auth/login", options).then(response => response.json())
|
||||||
.then((response) => {
|
.then(response => {
|
||||||
console.log(response, response.message);
|
console.log(response, response.message);
|
||||||
if ("Invalid Form Body" === response.message) {
|
if (response.message === "Invalid Form Body") {
|
||||||
return response.errors.login._errors[0].message;
|
return response.errors.login._errors[0].message;
|
||||||
console.log("test");
|
console.log("test");
|
||||||
}
|
}
|
||||||
|
@ -306,13 +303,14 @@ async function login(username, password, captcha) {
|
||||||
else {
|
else {
|
||||||
eval("hcaptcha.reset()");
|
eval("hcaptcha.reset()");
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
if (response.ticket) {
|
if (response.ticket) {
|
||||||
let onetimecode = "";
|
let onetimecode = "";
|
||||||
new Dialog(["vdiv", ["title", "2FA code:"], ["textbox", "", "", function () { onetimecode = this.value; }], ["button", "", "Submit", function () {
|
new Dialog(["vdiv", ["title", "2FA code:"], ["textbox", "", "", function () {
|
||||||
|
onetimecode = this.value;
|
||||||
|
}], ["button", "", "Submit", function () {
|
||||||
fetch(api + "/auth/mfa/totp", {
|
fetch(api + "/auth/mfa/totp", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -336,7 +334,7 @@ async function login(username, password, captcha) {
|
||||||
window.location.href = redir;
|
window.location.href = redir;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
window.location.href = '/channels/@me';
|
window.location.href = "/channels/@me";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -352,7 +350,7 @@ async function login(username, password, captcha) {
|
||||||
window.location.href = redir;
|
window.location.href = redir;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
window.location.href = '/channels/@me';
|
window.location.href = "/channels/@me";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -360,13 +358,12 @@ async function login(username, password, captcha) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error('Error:', error);
|
console.error("Error:", error);
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
async function check(e) {
|
async function check(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let h = await login(e.srcElement[1].value, e.srcElement[2].value, e.srcElement[3].value);
|
const h = await login(e.srcElement[1].value, e.srcElement[2].value, e.srcElement[3].value);
|
||||||
document.getElementById("wrong").textContent = h;
|
document.getElementById("wrong").textContent = h;
|
||||||
console.log(h);
|
console.log(h);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ class MarkDown {
|
||||||
return this.makeHTML().textContent;
|
return this.makeHTML().textContent;
|
||||||
}
|
}
|
||||||
makeHTML({ keep = this.keep, stdsize = this.stdsize } = {}) {
|
makeHTML({ keep = this.keep, stdsize = this.stdsize } = {}) {
|
||||||
return this.markdown(this.txt, { keep: keep, stdsize: stdsize });
|
return this.markdown(this.txt, { keep, stdsize });
|
||||||
}
|
}
|
||||||
markdown(text, { keep = false, stdsize = false } = {}) {
|
markdown(text, { keep = false, stdsize = false } = {}) {
|
||||||
let txt;
|
let txt;
|
||||||
|
@ -105,7 +105,7 @@ class MarkDown {
|
||||||
if (keep) {
|
if (keep) {
|
||||||
element.append(keepys);
|
element.append(keepys);
|
||||||
}
|
}
|
||||||
element.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
|
element.appendChild(this.markdown(build, { keep, stdsize }));
|
||||||
span.append(element);
|
span.append(element);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -179,7 +179,7 @@ class MarkDown {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const pre = document.createElement("pre");
|
const pre = document.createElement("pre");
|
||||||
if (build[build.length - 1] === "\n") {
|
if (build.at(-1) === "\n") {
|
||||||
build = build.substring(0, build.length - 1);
|
build = build.substring(0, build.length - 1);
|
||||||
}
|
}
|
||||||
if (txt[i] === "\n") {
|
if (txt[i] === "\n") {
|
||||||
|
@ -224,7 +224,7 @@ class MarkDown {
|
||||||
if (keep) {
|
if (keep) {
|
||||||
i.append(stars);
|
i.append(stars);
|
||||||
}
|
}
|
||||||
i.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
|
i.appendChild(this.markdown(build, { keep, stdsize }));
|
||||||
if (keep) {
|
if (keep) {
|
||||||
i.append(stars);
|
i.append(stars);
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ class MarkDown {
|
||||||
if (keep) {
|
if (keep) {
|
||||||
b.append(stars);
|
b.append(stars);
|
||||||
}
|
}
|
||||||
b.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
|
b.appendChild(this.markdown(build, { keep, stdsize }));
|
||||||
if (keep) {
|
if (keep) {
|
||||||
b.append(stars);
|
b.append(stars);
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,7 @@ class MarkDown {
|
||||||
if (keep) {
|
if (keep) {
|
||||||
b.append(stars);
|
b.append(stars);
|
||||||
}
|
}
|
||||||
b.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
|
b.appendChild(this.markdown(build, { keep, stdsize }));
|
||||||
if (keep) {
|
if (keep) {
|
||||||
b.append(stars);
|
b.append(stars);
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,7 @@ class MarkDown {
|
||||||
if (keep) {
|
if (keep) {
|
||||||
i.append(underscores);
|
i.append(underscores);
|
||||||
}
|
}
|
||||||
i.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
|
i.appendChild(this.markdown(build, { keep, stdsize }));
|
||||||
if (keep) {
|
if (keep) {
|
||||||
i.append(underscores);
|
i.append(underscores);
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ class MarkDown {
|
||||||
if (keep) {
|
if (keep) {
|
||||||
u.append(underscores);
|
u.append(underscores);
|
||||||
}
|
}
|
||||||
u.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
|
u.appendChild(this.markdown(build, { keep, stdsize }));
|
||||||
if (keep) {
|
if (keep) {
|
||||||
u.append(underscores);
|
u.append(underscores);
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ class MarkDown {
|
||||||
if (keep) {
|
if (keep) {
|
||||||
i.append(underscores);
|
i.append(underscores);
|
||||||
}
|
}
|
||||||
i.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
|
i.appendChild(this.markdown(build, { keep, stdsize }));
|
||||||
if (keep) {
|
if (keep) {
|
||||||
i.append(underscores);
|
i.append(underscores);
|
||||||
}
|
}
|
||||||
|
@ -325,7 +325,7 @@ class MarkDown {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (txt[i] === "~" && txt[i + 1] === "~") {
|
if (txt[i] === "~" && txt[i + 1] === "~") {
|
||||||
let count = 2;
|
const count = 2;
|
||||||
let build = [];
|
let build = [];
|
||||||
let find = 0;
|
let find = 0;
|
||||||
let j = i + 2;
|
let j = i + 2;
|
||||||
|
@ -350,7 +350,7 @@ class MarkDown {
|
||||||
if (keep) {
|
if (keep) {
|
||||||
s.append(tildes);
|
s.append(tildes);
|
||||||
}
|
}
|
||||||
s.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
|
s.appendChild(this.markdown(build, { keep, stdsize }));
|
||||||
if (keep) {
|
if (keep) {
|
||||||
s.append(tildes);
|
s.append(tildes);
|
||||||
}
|
}
|
||||||
|
@ -360,7 +360,7 @@ class MarkDown {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (txt[i] === "|" && txt[i + 1] === "|") {
|
if (txt[i] === "|" && txt[i + 1] === "|") {
|
||||||
let count = 2;
|
const count = 2;
|
||||||
let build = [];
|
let build = [];
|
||||||
let find = 0;
|
let find = 0;
|
||||||
let j = i + 2;
|
let j = i + 2;
|
||||||
|
@ -385,7 +385,7 @@ class MarkDown {
|
||||||
if (keep) {
|
if (keep) {
|
||||||
j.append(pipes);
|
j.append(pipes);
|
||||||
}
|
}
|
||||||
j.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
|
j.appendChild(this.markdown(build, { keep, stdsize }));
|
||||||
j.classList.add("spoiler");
|
j.classList.add("spoiler");
|
||||||
j.onclick = MarkDown.unspoil;
|
j.onclick = MarkDown.unspoil;
|
||||||
if (keep) {
|
if (keep) {
|
||||||
|
@ -459,7 +459,7 @@ class MarkDown {
|
||||||
i = j;
|
i = j;
|
||||||
const isEmojiOnly = txt.join("").trim() === buildjoin.trim();
|
const isEmojiOnly = txt.join("").trim() === buildjoin.trim();
|
||||||
const owner = (this.owner instanceof Channel) ? this.owner.guild : this.owner;
|
const owner = (this.owner instanceof Channel) ? this.owner.guild : this.owner;
|
||||||
const emoji = new Emoji({ name: buildjoin, id: parts[2], animated: !!parts[1] }, owner);
|
const emoji = new Emoji({ name: buildjoin, id: parts[2], animated: Boolean(parts[1]) }, owner);
|
||||||
span.appendChild(emoji.getHTML(isEmojiOnly));
|
span.appendChild(emoji.getHTML(isEmojiOnly));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -479,7 +479,6 @@ class MarkDown {
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
else if (partsFound === 1 && txt[j] === ")") {
|
else if (partsFound === 1 && txt[j] === ")") {
|
||||||
partsFound++;
|
partsFound++;
|
||||||
|
@ -529,7 +528,7 @@ class MarkDown {
|
||||||
return;
|
return;
|
||||||
console.log(_.clipboardData.types);
|
console.log(_.clipboardData.types);
|
||||||
const data = _.clipboardData.getData("text");
|
const data = _.clipboardData.getData("text");
|
||||||
document.execCommand('insertHTML', false, data);
|
document.execCommand("insertHTML", false, data);
|
||||||
_.preventDefault();
|
_.preventDefault();
|
||||||
if (!box.onkeyup)
|
if (!box.onkeyup)
|
||||||
return;
|
return;
|
||||||
|
@ -568,25 +567,25 @@ class MarkDown {
|
||||||
}
|
}
|
||||||
//solution from https://stackoverflow.com/questions/4576694/saving-and-restoring-caret-position-for-contenteditable-div
|
//solution from https://stackoverflow.com/questions/4576694/saving-and-restoring-caret-position-for-contenteditable-div
|
||||||
function saveCaretPosition(context) {
|
function saveCaretPosition(context) {
|
||||||
var selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
if (!selection)
|
if (!selection)
|
||||||
return;
|
return;
|
||||||
var range = selection.getRangeAt(0);
|
const range = selection.getRangeAt(0);
|
||||||
range.setStart(context, 0);
|
range.setStart(context, 0);
|
||||||
var len = range.toString().length;
|
const len = range.toString().length;
|
||||||
return function restore() {
|
return function restore() {
|
||||||
if (!selection)
|
if (!selection)
|
||||||
return;
|
return;
|
||||||
var pos = getTextNodeAtPosition(context, len);
|
const pos = getTextNodeAtPosition(context, len);
|
||||||
selection.removeAllRanges();
|
selection.removeAllRanges();
|
||||||
var range = new Range();
|
const range = new Range();
|
||||||
range.setStart(pos.node, pos.position);
|
range.setStart(pos.node, pos.position);
|
||||||
selection.addRange(range);
|
selection.addRange(range);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function getTextNodeAtPosition(root, index) {
|
function getTextNodeAtPosition(root, index) {
|
||||||
const NODE_TYPE = NodeFilter.SHOW_TEXT;
|
const NODE_TYPE = NodeFilter.SHOW_TEXT;
|
||||||
var treeWalker = document.createTreeWalker(root, NODE_TYPE, function next(elem) {
|
const treeWalker = document.createTreeWalker(root, NODE_TYPE, elem => {
|
||||||
if (!elem.textContent)
|
if (!elem.textContent)
|
||||||
return 0;
|
return 0;
|
||||||
if (index > elem.textContent.length) {
|
if (index > elem.textContent.length) {
|
||||||
|
@ -595,7 +594,7 @@ function getTextNodeAtPosition(root, index) {
|
||||||
}
|
}
|
||||||
return NodeFilter.FILTER_ACCEPT;
|
return NodeFilter.FILTER_ACCEPT;
|
||||||
});
|
});
|
||||||
var c = treeWalker.nextNode();
|
const c = treeWalker.nextNode();
|
||||||
return {
|
return {
|
||||||
node: c ? c : root,
|
node: c ? c : root,
|
||||||
position: index
|
position: index
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Member {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (thing === "roles") {
|
if (thing === "roles") {
|
||||||
for (const strrole of memberjson["roles"]) {
|
for (const strrole of memberjson.roles) {
|
||||||
const role = SnowFlake.getSnowFlakeFromID(strrole, Role).getObject();
|
const role = SnowFlake.getSnowFlakeFromID(strrole, Role).getObject();
|
||||||
this.roles.push(role);
|
this.roles.push(role);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ class Member {
|
||||||
}
|
}
|
||||||
if (this.localuser.userMap.has(this?.id)) {
|
if (this.localuser.userMap.has(this?.id)) {
|
||||||
this.user = this.localuser.userMap.get(this?.id);
|
this.user = this.localuser.userMap.get(this?.id);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get guild() {
|
get guild() {
|
||||||
|
@ -89,7 +88,6 @@ class Member {
|
||||||
const membjson = await membpromise;
|
const membjson = await membpromise;
|
||||||
if (membjson === undefined) {
|
if (membjson === undefined) {
|
||||||
res(undefined);
|
res(undefined);
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const member = new Member(membjson, guild);
|
const member = new Member(membjson, guild);
|
||||||
|
@ -149,7 +147,6 @@ class Member {
|
||||||
if (!this) {
|
if (!this) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
/*
|
/*
|
||||||
if(this.error){
|
if(this.error){
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,9 @@ class Message {
|
||||||
return this.snowflake.id;
|
return this.snowflake.id;
|
||||||
}
|
}
|
||||||
static setup() {
|
static setup() {
|
||||||
this.del = new Promise(_ => { this.resolve = _; });
|
this.del = new Promise(_ => {
|
||||||
|
this.resolve = _;
|
||||||
|
});
|
||||||
Message.setupcmenu();
|
Message.setupcmenu();
|
||||||
}
|
}
|
||||||
static setupcmenu() {
|
static setupcmenu() {
|
||||||
|
@ -63,7 +65,7 @@ class Message {
|
||||||
Message.contextmenu.addbutton("Edit", function () {
|
Message.contextmenu.addbutton("Edit", function () {
|
||||||
this.channel.editing = this;
|
this.channel.editing = this;
|
||||||
const markdown = document.getElementById("typebox")["markdown"];
|
const markdown = document.getElementById("typebox")["markdown"];
|
||||||
markdown.txt = this.content.rawString.split('');
|
markdown.txt = this.content.rawString.split("");
|
||||||
markdown.boxupdate(document.getElementById("typebox"));
|
markdown.boxupdate(document.getElementById("typebox"));
|
||||||
}, null, function () {
|
}, null, function () {
|
||||||
return this.author.id === this.localuser.user.id;
|
return this.author.id === this.localuser.user.id;
|
||||||
|
@ -199,7 +201,7 @@ class Message {
|
||||||
getimages() {
|
getimages() {
|
||||||
const build = [];
|
const build = [];
|
||||||
for (const thing of this.attachments) {
|
for (const thing of this.attachments) {
|
||||||
if (thing.content_type.startsWith('image/')) {
|
if (thing.content_type.startsWith("image/")) {
|
||||||
build.push(thing);
|
build.push(thing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,7 +211,7 @@ class Message {
|
||||||
return await fetch(this.info.api + "/channels/" + this.channel.snowflake + "/messages/" + this.id, {
|
return await fetch(this.info.api + "/channels/" + this.channel.snowflake + "/messages/" + this.id, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({ content: content })
|
body: JSON.stringify({ content })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
delete() {
|
delete() {
|
||||||
|
@ -266,7 +268,7 @@ class Message {
|
||||||
this.generateMessage();
|
this.generateMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
generateMessage(premessage = undefined, ignoredblock = false) {
|
generateMessage(premessage, ignoredblock = false) {
|
||||||
if (!this.div)
|
if (!this.div)
|
||||||
return;
|
return;
|
||||||
if (!premessage) {
|
if (!premessage) {
|
||||||
|
@ -277,21 +279,21 @@ class Message {
|
||||||
div.classList.add("replying");
|
div.classList.add("replying");
|
||||||
}
|
}
|
||||||
div.innerHTML = "";
|
div.innerHTML = "";
|
||||||
const build = document.createElement('div');
|
const build = document.createElement("div");
|
||||||
build.classList.add("flexltr", "message");
|
build.classList.add("flexltr", "message");
|
||||||
div.classList.remove("zeroheight");
|
div.classList.remove("zeroheight");
|
||||||
if (this.author.relationshipType === 2) {
|
if (this.author.relationshipType === 2) {
|
||||||
if (ignoredblock) {
|
if (ignoredblock) {
|
||||||
if (premessage?.author !== this.author) {
|
if (premessage?.author !== this.author) {
|
||||||
const span = document.createElement("span");
|
const span = document.createElement("span");
|
||||||
span.textContent = `You have this user blocked, click to hide these messages.`;
|
span.textContent = "You have this user blocked, click to hide these messages.";
|
||||||
div.append(span);
|
div.append(span);
|
||||||
span.classList.add("blocked");
|
span.classList.add("blocked");
|
||||||
span.onclick = _ => {
|
span.onclick = _ => {
|
||||||
const scroll = this.channel.infinite.scrollTop;
|
const scroll = this.channel.infinite.scrollTop;
|
||||||
let next = this;
|
let next = this;
|
||||||
while (next?.author === this.author) {
|
while (next?.author === this.author) {
|
||||||
next.generateMessage(undefined);
|
next.generateMessage();
|
||||||
next = this.channel.messages.get(this.channel.idToNext.get(next.id));
|
next = this.channel.messages.get(this.channel.idToNext.get(next.id));
|
||||||
}
|
}
|
||||||
if (this.channel.infinite.scroll && scroll) {
|
if (this.channel.infinite.scroll && scroll) {
|
||||||
|
@ -375,7 +377,7 @@ class Message {
|
||||||
}
|
}
|
||||||
div.appendChild(build);
|
div.appendChild(build);
|
||||||
if ({ 0: true, 19: true }[this.type] || this.attachments.length !== 0) {
|
if ({ 0: true, 19: true }[this.type] || this.attachments.length !== 0) {
|
||||||
const pfpRow = document.createElement('div');
|
const pfpRow = document.createElement("div");
|
||||||
pfpRow.classList.add("flexltr");
|
pfpRow.classList.add("flexltr");
|
||||||
let pfpparent, current;
|
let pfpparent, current;
|
||||||
if (premessage != null) {
|
if (premessage != null) {
|
||||||
|
@ -545,7 +547,7 @@ class Message {
|
||||||
if (thing.emoji.name === data.name) {
|
if (thing.emoji.name === data.name) {
|
||||||
thing.count--;
|
thing.count--;
|
||||||
if (thing.count === 0) {
|
if (thing.count === 0) {
|
||||||
this.reactions.splice(+i, 1);
|
this.reactions.splice(Number(i), 1);
|
||||||
this.updateReactions();
|
this.updateReactions();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -565,16 +567,16 @@ class Message {
|
||||||
for (const i in this.reactions) {
|
for (const i in this.reactions) {
|
||||||
const reaction = this.reactions[i];
|
const reaction = this.reactions[i];
|
||||||
if ((reaction.emoji.id && reaction.emoji.id == emoji.id) || (!reaction.emoji.id && reaction.emoji.name == emoji.name)) {
|
if ((reaction.emoji.id && reaction.emoji.id == emoji.id) || (!reaction.emoji.id && reaction.emoji.name == emoji.name)) {
|
||||||
this.reactions.splice(+i, 1);
|
this.reactions.splice(Number(i), 1);
|
||||||
this.updateReactions();
|
this.updateReactions();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildhtml(premessage = undefined) {
|
buildhtml(premessage) {
|
||||||
if (this.div) {
|
if (this.div) {
|
||||||
console.error(`HTML for ${this.snowflake} already exists, aborting`);
|
console.error(`HTML for ${this.snowflake} already exists, aborting`);
|
||||||
return;
|
return this.div;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
|
@ -585,15 +587,16 @@ class Message {
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
return this.div;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let now = new Date().toLocaleDateString();
|
const now = new Date().toLocaleDateString();
|
||||||
const yesterday = new Date(now);
|
const yesterday = new Date(now);
|
||||||
yesterday.setDate(new Date().getDate() - 1);
|
yesterday.setDate(new Date().getDate() - 1);
|
||||||
let yesterdayStr = yesterday.toLocaleDateString();
|
const yesterdayStr = yesterday.toLocaleDateString();
|
||||||
function formatTime(date) {
|
function formatTime(date) {
|
||||||
const datestring = date.toLocaleDateString();
|
const datestring = date.toLocaleDateString();
|
||||||
const formatTime = (date) => date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
const formatTime = (date) => date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
||||||
if (datestring === now) {
|
if (datestring === now) {
|
||||||
return `Today at ${formatTime(date)}`;
|
return `Today at ${formatTime(date)}`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@ class Permissions {
|
||||||
deny;
|
deny;
|
||||||
hasDeny;
|
hasDeny;
|
||||||
constructor(allow, deny = "") {
|
constructor(allow, deny = "") {
|
||||||
this.hasDeny = !!deny;
|
this.hasDeny = Boolean(deny);
|
||||||
try {
|
try {
|
||||||
this.allow = BigInt(allow);
|
this.allow = BigInt(allow);
|
||||||
this.deny = BigInt(deny);
|
this.deny = BigInt(deny);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch {
|
||||||
this.allow = 0n;
|
this.allow = 0n;
|
||||||
this.deny = 0n;
|
this.deny = 0n;
|
||||||
console.error(`Something really stupid happened with a permission with allow being ${allow} and deny being, ${deny}, execution will still happen, but something really stupid happened, please report if you know what caused this.`);
|
console.error(`Something really stupid happened with a permission with allow being ${allow} and deny being, ${deny}, execution will still happen, but something really stupid happened, please report if you know what caused this.`);
|
||||||
|
|
|
@ -17,9 +17,9 @@ async function registertry(e) {
|
||||||
await fetch(apiurl + "/auth/register", {
|
await fetch(apiurl + "/auth/register", {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
date_of_birth: dateofbirth,
|
date_of_birth: dateofbirth,
|
||||||
email: email,
|
email,
|
||||||
username: username,
|
username,
|
||||||
password: password,
|
password,
|
||||||
consent: elements[6].checked,
|
consent: elements[6].checked,
|
||||||
captcha_key: elements[7]?.value
|
captcha_key: elements[7]?.value
|
||||||
}),
|
}),
|
||||||
|
@ -67,14 +67,14 @@ async function registertry(e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
adduser({ serverurls: JSON.parse(localStorage.getItem("instanceinfo")), email: email, token: e.token }).username = username;
|
adduser({ serverurls: JSON.parse(localStorage.getItem("instanceinfo")), email, token: e.token }).username = username;
|
||||||
localStorage.setItem("token", e.token);
|
localStorage.setItem("token", e.token);
|
||||||
const redir = new URLSearchParams(window.location.search).get("goback");
|
const redir = new URLSearchParams(window.location.search).get("goback");
|
||||||
if (redir) {
|
if (redir) {
|
||||||
window.location.href = redir;
|
window.location.href = redir;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
window.location.href = '/channels/@me';
|
window.location.href = "/channels/@me";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -93,7 +93,9 @@ function error(e, message) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
element.classList.remove("suberror");
|
element.classList.remove("suberror");
|
||||||
setTimeout(_ => { element.classList.add("suberror"); }, 100);
|
setTimeout(_ => {
|
||||||
|
element.classList.add("suberror");
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
element.textContent = message;
|
element.textContent = message;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ class Role {
|
||||||
if (this.color === 0) {
|
if (this.color === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
return `#${this.color.toString(16)}`;
|
return `#${this.color.toString(16)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +54,6 @@ class PermissionToggle {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
watchForChange() { }
|
watchForChange() { }
|
||||||
;
|
|
||||||
generateHTML() {
|
generateHTML() {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
div.classList.add("setting");
|
div.classList.add("setting");
|
||||||
|
@ -80,7 +78,6 @@ class PermissionToggle {
|
||||||
if (state === 1) {
|
if (state === 1) {
|
||||||
on.checked = true;
|
on.checked = true;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
on.onclick = _ => {
|
on.onclick = _ => {
|
||||||
this.permissions.setPermission(this.rolejson.name, 1);
|
this.permissions.setPermission(this.rolejson.name, 1);
|
||||||
this.owner.changed();
|
this.owner.changed();
|
||||||
|
@ -92,7 +89,6 @@ class PermissionToggle {
|
||||||
if (state === 0) {
|
if (state === 0) {
|
||||||
no.checked = true;
|
no.checked = true;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
no.onclick = _ => {
|
no.onclick = _ => {
|
||||||
this.permissions.setPermission(this.rolejson.name, 0);
|
this.permissions.setPermission(this.rolejson.name, 0);
|
||||||
this.owner.changed();
|
this.owner.changed();
|
||||||
|
@ -105,7 +101,6 @@ class PermissionToggle {
|
||||||
if (state === -1) {
|
if (state === -1) {
|
||||||
off.checked = true;
|
off.checked = true;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
off.onclick = _ => {
|
off.onclick = _ => {
|
||||||
this.permissions.setPermission(this.rolejson.name, -1);
|
this.permissions.setPermission(this.rolejson.name, -1);
|
||||||
this.owner.changed();
|
this.owner.changed();
|
||||||
|
|
|
@ -4,7 +4,7 @@ function deleteoldcache() {
|
||||||
}
|
}
|
||||||
async function putInCache(request, response) {
|
async function putInCache(request, response) {
|
||||||
console.log(request, response);
|
console.log(request, response);
|
||||||
const cache = await caches.open('cache');
|
const cache = await caches.open("cache");
|
||||||
console.log("Grabbed");
|
console.log("Grabbed");
|
||||||
try {
|
try {
|
||||||
console.log(await cache.put(request, response));
|
console.log(await cache.put(request, response));
|
||||||
|
@ -13,7 +13,6 @@ async function putInCache(request, response) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
|
||||||
console.log("test");
|
console.log("test");
|
||||||
let lastcache;
|
let lastcache;
|
||||||
self.addEventListener("activate", async (event) => {
|
self.addEventListener("activate", async (event) => {
|
||||||
|
@ -37,7 +36,9 @@ async function checkCache() {
|
||||||
putInCache("/getupdates", data.clone());
|
putInCache("/getupdates", data.clone());
|
||||||
}
|
}
|
||||||
checkedrecently = true;
|
checkedrecently = true;
|
||||||
setTimeout(_ => { checkedrecently = false; }, 1000 * 60 * 30);
|
setTimeout(_ => {
|
||||||
|
checkedrecently = false;
|
||||||
|
}, 1000 * 60 * 30);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var checkedrecently = false;
|
var checkedrecently = false;
|
||||||
|
@ -83,7 +84,7 @@ async function getfile(event) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.addEventListener('fetch', (event) => {
|
self.addEventListener("fetch", (event) => {
|
||||||
try {
|
try {
|
||||||
event.respondWith(getfile(event));
|
event.respondWith(getfile(event));
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Buttons {
|
||||||
this.buttons = [];
|
this.buttons = [];
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
add(name, thing = undefined) {
|
add(name, thing) {
|
||||||
if (!thing) {
|
if (!thing) {
|
||||||
thing = new Options(name, this);
|
thing = new Options(name, this);
|
||||||
}
|
}
|
||||||
|
@ -380,7 +380,6 @@ class FileInput {
|
||||||
if (this.onchange) {
|
if (this.onchange) {
|
||||||
this.onchange(null);
|
this.onchange(null);
|
||||||
}
|
}
|
||||||
;
|
|
||||||
this.value = null;
|
this.value = null;
|
||||||
this.owner.changed();
|
this.owner.changed();
|
||||||
};
|
};
|
||||||
|
@ -424,7 +423,6 @@ class HtmlArea {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
watchForChange() { }
|
watchForChange() { }
|
||||||
;
|
|
||||||
}
|
}
|
||||||
class Options {
|
class Options {
|
||||||
name;
|
name;
|
||||||
|
@ -451,7 +449,6 @@ class Options {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
watchForChange() { }
|
watchForChange() { }
|
||||||
;
|
|
||||||
addOptions(name, { ltr = false } = {}) {
|
addOptions(name, { ltr = false } = {}) {
|
||||||
const options = new Options(name, this, { ltr });
|
const options = new Options(name, this, { ltr });
|
||||||
this.options.push(options);
|
this.options.push(options);
|
||||||
|
@ -467,7 +464,7 @@ class Options {
|
||||||
this.generateContainter();
|
this.generateContainter();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw Error("Tried to make a subOptions when the options weren't rendered");
|
throw new Error("Tried to make a subOptions when the options weren't rendered");
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
@ -479,7 +476,7 @@ class Options {
|
||||||
this.generateContainter();
|
this.generateContainter();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw Error("Tried to make a subForm when the options weren't rendered");
|
throw new Error("Tried to make a subForm when the options weren't rendered");
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
@ -758,7 +755,6 @@ class Form {
|
||||||
watchForChange(func) {
|
watchForChange(func) {
|
||||||
this.onSubmit = func;
|
this.onSubmit = func;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
changed() {
|
changed() {
|
||||||
if (this.traditionalSubmit) {
|
if (this.traditionalSubmit) {
|
||||||
this.owner.changed();
|
this.owner.changed();
|
||||||
|
@ -819,7 +815,6 @@ class Form {
|
||||||
if (!(errors instanceof Object)) {
|
if (!(errors instanceof Object)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
for (const error of Object.keys(errors)) {
|
for (const error of Object.keys(errors)) {
|
||||||
const elm = this.names.get(error);
|
const elm = this.names.get(error);
|
||||||
if (elm) {
|
if (elm) {
|
||||||
|
@ -858,7 +853,9 @@ class Form {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
element.classList.remove("suberror");
|
element.classList.remove("suberror");
|
||||||
setTimeout(_ => { element.classList.add("suberror"); }, 100);
|
setTimeout(_ => {
|
||||||
|
element.classList.add("suberror");
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
element.textContent = message;
|
element.textContent = message;
|
||||||
}
|
}
|
||||||
|
@ -887,7 +884,9 @@ class Settings extends Buttons {
|
||||||
exit.textContent = "✖";
|
exit.textContent = "✖";
|
||||||
exit.classList.add("exitsettings");
|
exit.classList.add("exitsettings");
|
||||||
background.append(exit);
|
background.append(exit);
|
||||||
exit.onclick = _ => { this.hide(); };
|
exit.onclick = _ => {
|
||||||
|
this.hide();
|
||||||
|
};
|
||||||
document.body.append(background);
|
document.body.append(background);
|
||||||
this.html = background;
|
this.html = background;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ class User {
|
||||||
});
|
});
|
||||||
this.contextmenu.addbutton("Message user", function () {
|
this.contextmenu.addbutton("Message user", function () {
|
||||||
fetch(this.info.api + "/users/@me/channels", { method: "POST",
|
fetch(this.info.api + "/users/@me/channels", { method: "POST",
|
||||||
body: JSON.stringify({ "recipients": [this.id] }),
|
body: JSON.stringify({ recipients: [this.id] }),
|
||||||
headers: this.localuser.headers
|
headers: this.localuser.headers
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -97,7 +97,7 @@ class User {
|
||||||
});
|
});
|
||||||
this.contextmenu.addbutton("Kick member", function (member) {
|
this.contextmenu.addbutton("Kick member", function (member) {
|
||||||
member.kick();
|
member.kick();
|
||||||
}, null, function (member) {
|
}, null, member => {
|
||||||
if (!member)
|
if (!member)
|
||||||
return false;
|
return false;
|
||||||
const us = member.guild.member;
|
const us = member.guild.member;
|
||||||
|
@ -111,7 +111,7 @@ class User {
|
||||||
});
|
});
|
||||||
this.contextmenu.addbutton("Ban member", function (member) {
|
this.contextmenu.addbutton("Ban member", function (member) {
|
||||||
member.ban();
|
member.ban();
|
||||||
}, null, function (member) {
|
}, null, member => {
|
||||||
if (!member)
|
if (!member)
|
||||||
return false;
|
return false;
|
||||||
const us = member.guild.member;
|
const us = member.guild.member;
|
||||||
|
@ -192,7 +192,7 @@ class User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildpfp() {
|
buildpfp() {
|
||||||
const pfp = document.createElement('img');
|
const pfp = document.createElement("img");
|
||||||
pfp.loading = "lazy";
|
pfp.loading = "lazy";
|
||||||
pfp.src = this.getpfpsrc();
|
pfp.src = this.getpfpsrc();
|
||||||
pfp.classList.add("pfp");
|
pfp.classList.add("pfp");
|
||||||
|
@ -419,7 +419,7 @@ class User {
|
||||||
}
|
}
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
profileclick(obj, guild = undefined) {
|
profileclick(obj, guild) {
|
||||||
obj.onclick = e => {
|
obj.onclick = e => {
|
||||||
this.buildprofile(e.clientX, e.clientY, guild);
|
this.buildprofile(e.clientX, e.clientY, guild);
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
158
emoji-packer.js
158
emoji-packer.js
|
@ -5,111 +5,109 @@ const buffer=new ArrayBuffer(2**26);
|
||||||
const view = new DataView(buffer, 0);
|
const view = new DataView(buffer, 0);
|
||||||
let i=0;
|
let i=0;
|
||||||
function write16(numb){
|
function write16(numb){
|
||||||
view.setUint16(i,numb);
|
view.setUint16(i,numb);
|
||||||
i+=2;
|
i+=2;
|
||||||
}
|
}
|
||||||
function write8(numb){
|
function write8(numb){
|
||||||
view.setUint8(i,numb);
|
view.setUint8(i,numb);
|
||||||
i+=1;
|
i+=1;
|
||||||
}
|
}
|
||||||
function writeString8(str){
|
function writeString8(str){
|
||||||
const encode=new TextEncoder("utf-8").encode(str);
|
const encode=new TextEncoder("utf-8").encode(str);
|
||||||
write8(encode.length);
|
write8(encode.length);
|
||||||
for(const thing of encode){
|
for(const thing of encode){
|
||||||
write8(thing);
|
write8(thing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function writeString16(str){
|
function writeString16(str){
|
||||||
const encode=new TextEncoder("utf-8").encode(str);
|
const encode=new TextEncoder("utf-8").encode(str);
|
||||||
write16(encode.length);
|
write16(encode.length);
|
||||||
for(const thing of encode){
|
for(const thing of encode){
|
||||||
write8(thing);
|
write8(thing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function writeStringNo(str){
|
function writeStringNo(str){
|
||||||
const encode=new TextEncoder("utf-8").encode(str);
|
const encode=new TextEncoder("utf-8").encode(str);
|
||||||
for(const thing of encode){
|
for(const thing of encode){
|
||||||
write8(thing);
|
write8(thing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
write16(emojilist.length);
|
write16(emojilist.length);
|
||||||
for(const thing of emojilist){
|
for(const thing of emojilist){
|
||||||
writeString16(thing.name);
|
writeString16(thing.name);
|
||||||
write16(thing.emojis.length);
|
write16(thing.emojis.length);
|
||||||
for(const emoji of thing.emojis){
|
for(const emoji of thing.emojis){
|
||||||
writeString8(emoji.name);
|
writeString8(emoji.name);
|
||||||
write8(new TextEncoder("utf-8").encode(emoji.emoji).length+128*emoji.skin_tone_support);
|
write8(new TextEncoder("utf-8").encode(emoji.emoji).length+128*emoji.skin_tone_support);
|
||||||
writeStringNo(emoji.emoji);
|
writeStringNo(emoji.emoji);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const out=new ArrayBuffer(i);
|
const out=new ArrayBuffer(i);
|
||||||
const ar=new Uint8Array(out);
|
const ar=new Uint8Array(out);
|
||||||
const br=new Uint8Array(buffer)
|
const br=new Uint8Array(buffer);
|
||||||
for(const thing in ar){
|
for(const thing in ar){
|
||||||
ar[thing]=br[thing];
|
ar[thing]=br[thing];
|
||||||
}
|
}
|
||||||
console.log(i,ar);
|
console.log(i,ar);
|
||||||
|
|
||||||
function decodeEmojiList(buffer){
|
function decodeEmojiList(buffer){
|
||||||
const view = new DataView(buffer, 0);
|
const view = new DataView(buffer, 0);
|
||||||
let i=0;
|
let i=0;
|
||||||
function read16(){
|
function read16(){
|
||||||
const int=view.getUint16(i);
|
const int=view.getUint16(i);
|
||||||
i+=2;
|
i+=2;
|
||||||
return int;
|
return int;
|
||||||
}
|
}
|
||||||
function read8(){
|
function read8(){
|
||||||
const int=view.getUint8(i);
|
const int=view.getUint8(i);
|
||||||
i+=1;
|
i+=1;
|
||||||
return int;
|
return int;
|
||||||
}
|
}
|
||||||
function readString8(){
|
function readString8(){
|
||||||
return readStringNo(read8());
|
return readStringNo(read8());
|
||||||
}
|
}
|
||||||
function readString16(){
|
function readString16(){
|
||||||
return readStringNo(read16());
|
return readStringNo(read16());
|
||||||
}
|
}
|
||||||
function readStringNo(length){
|
function readStringNo(length){
|
||||||
const array=new Uint8Array(length);
|
const array=new Uint8Array(length);
|
||||||
|
|
||||||
for(let i=0;i<length;i++){
|
for(let i=0;i<length;i++){
|
||||||
array[i]=read8();
|
array[i]=read8();
|
||||||
}
|
}
|
||||||
const decoded=new TextDecoder("utf-8").decode(array.buffer);;
|
//console.log(array);
|
||||||
|
return new TextDecoder("utf-8").decode(array.buffer);
|
||||||
|
}
|
||||||
|
const build=[];
|
||||||
|
let cats=read16();
|
||||||
|
|
||||||
//console.log(array);
|
for(;cats!==0;cats--){
|
||||||
return decoded;
|
const name=readString16();
|
||||||
}
|
const emojis=[];
|
||||||
const build=[];
|
let emojinumber=read16();
|
||||||
let cats=read16();
|
for(;emojinumber!==0;emojinumber--){
|
||||||
|
//console.log(emojis);
|
||||||
for(;cats!==0;cats--){
|
const name=readString8();
|
||||||
const name=readString16();
|
const len=read8();
|
||||||
const emojis=[];
|
const skin_tone_support=len>127;
|
||||||
let emojinumber=read16();
|
const emoji=readStringNo(len-skin_tone_support*128);
|
||||||
for(;emojinumber!==0;emojinumber--){
|
emojis.push({
|
||||||
//console.log(emojis);
|
name,
|
||||||
const name=readString8();
|
skin_tone_support,
|
||||||
const len=read8();
|
emoji
|
||||||
const skin_tone_support=len>127;
|
});
|
||||||
const emoji=readStringNo(len-skin_tone_support*128);
|
}
|
||||||
emojis.push({
|
build.push({
|
||||||
name,
|
name,
|
||||||
skin_tone_support,
|
emojis
|
||||||
emoji
|
});
|
||||||
})
|
}
|
||||||
}
|
return build;
|
||||||
build.push({
|
|
||||||
name,
|
|
||||||
emojis
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return build;
|
|
||||||
}
|
}
|
||||||
console.log(JSON.stringify(decodeEmojiList(out)));
|
console.log(JSON.stringify(decodeEmojiList(out)));
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require("node:fs");
|
||||||
fs.writeFile("./webpage/emoji.bin",new Uint8Array(out),_=>{
|
fs.writeFile("./webpage/emoji.bin",new Uint8Array(out),_=>{
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,10 +10,10 @@ const tsParser = require("@typescript-eslint/parser");
|
||||||
|
|
||||||
const linterOptions = {
|
const linterOptions = {
|
||||||
reportUnusedDisableDirectives: "error"
|
reportUnusedDisableDirectives: "error"
|
||||||
}
|
};
|
||||||
const global = {
|
const global = {
|
||||||
...globals.browser
|
...globals.browser
|
||||||
}
|
};
|
||||||
|
|
||||||
const rules = {
|
const rules = {
|
||||||
"array-callback-return": 2,
|
"array-callback-return": 2,
|
||||||
|
@ -227,7 +227,7 @@ const rules = {
|
||||||
"sonarjs/prefer-while": 2,
|
"sonarjs/prefer-while": 2,
|
||||||
"sonarjs/no-gratuitous-expressions": 2,
|
"sonarjs/no-gratuitous-expressions": 2,
|
||||||
"sonarjs/no-duplicated-branches": 2
|
"sonarjs/no-duplicated-branches": 2
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{
|
{
|
||||||
|
@ -307,4 +307,4 @@ module.exports = [
|
||||||
"@html-eslint/require-img-alt": 1
|
"@html-eslint/require-img-alt": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
];
|
||||||
|
|
293
index.js
293
index.js
|
@ -1,119 +1,118 @@
|
||||||
#! /usr/bin/env node
|
#! /usr/bin/env node
|
||||||
const compression = require('compression')
|
const compression = require("compression");
|
||||||
|
|
||||||
const express = require('express');
|
const express = require("express");
|
||||||
const fs = require('fs');
|
const fs = require("node:fs");
|
||||||
const app = express();
|
const app = express();
|
||||||
const instances=require("./webpage/instances.json");
|
const instances=require("./webpage/instances.json");
|
||||||
const stats=require("./stats.js");
|
const stats=require("./stats.js");
|
||||||
const instancenames=new Map();
|
const instancenames=new Map();
|
||||||
for(const instance of instances){
|
for(const instance of instances){
|
||||||
instancenames.set(instance.name,instance);
|
instancenames.set(instance.name,instance);
|
||||||
}
|
}
|
||||||
app.use(compression())
|
app.use(compression());
|
||||||
fetch("https://raw.githubusercontent.com/spacebarchat/spacebarchat/master/instances/instances.json").then(_=>_.json()).then(json=>{
|
fetch("https://raw.githubusercontent.com/spacebarchat/spacebarchat/master/instances/instances.json").then(_=>_.json()).then(json=>{
|
||||||
for(const instance of json){
|
for(const instance of json){
|
||||||
if(!instancenames.has(instance.name)){
|
if(!instancenames.has(instance.name)){
|
||||||
instances.push(instance);
|
instances.push(instance);
|
||||||
}else{
|
}else{
|
||||||
const ofinst=instancenames.get(instance.name)
|
const ofinst=instancenames.get(instance.name);
|
||||||
for(const key of Object.keys(instance)){
|
for(const key of Object.keys(instance)){
|
||||||
if(!ofinst[key]){
|
if(!ofinst[key]){
|
||||||
ofinst[key]=instance[key];
|
ofinst[key]=instance[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stats.observe(instances)
|
stats.observe(instances);
|
||||||
})
|
|
||||||
|
|
||||||
app.use("/getupdates",(req, res) => {
|
|
||||||
const out=fs.statSync(`${__dirname}/webpage`);
|
|
||||||
res.send(out.mtimeMs+"");
|
|
||||||
});
|
});
|
||||||
let debugging=true;//Do not turn this off, the service worker is all kinds of jank as is, it'll really mess your day up if you disable this
|
|
||||||
|
app.use("/getupdates",(req, res)=>{
|
||||||
|
const out=fs.statSync(`${__dirname}/webpage`);
|
||||||
|
res.send(out.mtimeMs+"");
|
||||||
|
});
|
||||||
|
const debugging=true;//Do not turn this off, the service worker is all kinds of jank as is, it'll really mess your day up if you disable this
|
||||||
function isembed(str){
|
function isembed(str){
|
||||||
return str.includes("discord")||str.includes("Spacebar");
|
return str.includes("discord")||str.includes("Spacebar");
|
||||||
}
|
}
|
||||||
async function getapiurls(str){
|
async function getapiurls(str){
|
||||||
if(str[str.length-1]!=="/"){
|
if(str.at(-1)!=="/"){
|
||||||
str+="/"
|
str+="/";
|
||||||
}
|
}
|
||||||
let api;
|
let api;
|
||||||
try{
|
try{
|
||||||
const info=await fetch(`${str}/.well-known/spacebar`).then((x) => x.json());
|
const info=await fetch(`${str}/.well-known/spacebar`).then(x=>x.json());
|
||||||
api=info.api;
|
api=info.api;
|
||||||
}catch{
|
}catch{
|
||||||
return false
|
return false;
|
||||||
}
|
}
|
||||||
const url = new URL(api);
|
const url = new URL(api);
|
||||||
try{
|
try{
|
||||||
|
const info=await fetch(`${api}${url.pathname.includes("api") ? "" : "api"}/policies/instance/domains`).then(x=>x.json());
|
||||||
const info=await fetch(`${api}${url.pathname.includes("api") ? "" : "api"}/policies/instance/domains`).then((x) => x.json());
|
return{
|
||||||
return {
|
api: info.apiEndpoint,
|
||||||
api: info.apiEndpoint,
|
gateway: info.gateway,
|
||||||
gateway: info.gateway,
|
cdn: info.cdn,
|
||||||
cdn: info.cdn,
|
wellknown: str,
|
||||||
wellknown: str,
|
};
|
||||||
};
|
}catch{
|
||||||
}catch{
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function inviteres(req,res){
|
async function inviteres(req,res){
|
||||||
let url;
|
let url;
|
||||||
if(URL.canParse(req.query.url)){
|
if(URL.canParse(req.query.url)){
|
||||||
url=new URL(req.query.url);
|
url=new URL(req.query.url);
|
||||||
}else{
|
}else{
|
||||||
const scheme = req.secure ? 'https' : 'http';
|
const scheme = req.secure ? "https" : "http";
|
||||||
const host=`${scheme}://${req.get("Host")}`;
|
const host=`${scheme}://${req.get("Host")}`;
|
||||||
url=new URL(host);
|
url=new URL(host);
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
if(url.pathname.startsWith("invite")){
|
if(url.pathname.startsWith("invite")){
|
||||||
throw -1;
|
throw-1;
|
||||||
}
|
}
|
||||||
const code=url.pathname.split("/")[2];
|
const code=url.pathname.split("/")[2];
|
||||||
let title="";
|
let title="";
|
||||||
let description="";
|
let description="";
|
||||||
let thumbnail="";
|
let thumbnail="";
|
||||||
const urls=await getapiurls(url.searchParams.get("instance"));
|
const urls=await getapiurls(url.searchParams.get("instance"));
|
||||||
await fetch(`${urls.api}/invites/${code}`,{
|
await fetch(`${urls.api}/invites/${code}`,{
|
||||||
method:"GET"
|
method: "GET"
|
||||||
}).then(_=>_.json()).then(json=>{
|
}).then(_=>_.json()).then(json=>{
|
||||||
title=json.guild.name;
|
title=json.guild.name;
|
||||||
if(json.inviter){
|
if(json.inviter){
|
||||||
description=json.inviter.username+" Has invited you to "+json.guild.name+(json.guild.description?json.guild.description+"\n":"");
|
description=json.inviter.username+" Has invited you to "+json.guild.name+(json.guild.description?json.guild.description+"\n":"");
|
||||||
}else{
|
}else{
|
||||||
description="you've been invited to "+json.guild.name+(json.guild.description?json.guild.description+"\n":"");
|
description="you've been invited to "+json.guild.name+(json.guild.description?json.guild.description+"\n":"");
|
||||||
}
|
}
|
||||||
if(json.guild.icon){
|
if(json.guild.icon){
|
||||||
thumbnail=`${urls.cdn}/icons/${json.guild.id}/${json.guild.icon}.png`;
|
thumbnail=`${urls.cdn}/icons/${json.guild.id}/${json.guild.icon}.png`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const json={
|
const json={
|
||||||
type:"link",
|
type: "link",
|
||||||
version:"1.0",
|
version: "1.0",
|
||||||
title,
|
title,
|
||||||
thumbnail,
|
thumbnail,
|
||||||
description,
|
description,
|
||||||
};
|
};
|
||||||
res.send(JSON.stringify(json));
|
res.send(JSON.stringify(json));
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.error(e);
|
console.error(e);
|
||||||
const json={
|
const json={
|
||||||
type:"link",
|
type: "link",
|
||||||
version:"1.0",
|
version: "1.0",
|
||||||
title:"Jank Client",
|
title: "Jank Client",
|
||||||
thumbnail:"/logo.webp",
|
thumbnail: "/logo.webp",
|
||||||
description:"A spacebar client that has DMs, replying and more",
|
description: "A spacebar client that has DMs, replying and more",
|
||||||
url:url.toString()
|
url: url.toString()
|
||||||
};
|
};
|
||||||
res.send(JSON.stringify(json));
|
res.send(JSON.stringify(json));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
function htmlEnc(s) {//https://stackoverflow.com/a/11561642
|
function htmlEnc(s) {//https://stackoverflow.com/a/11561642
|
||||||
return s.replaceAll(/&/g, '&')
|
return s.replaceAll(/&/g, '&')
|
||||||
.replaceAll(/</g, '<')
|
.replaceAll(/</g, '<')
|
||||||
|
@ -143,60 +142,56 @@ async function inviteres(req,res){
|
||||||
return false;
|
return false;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
app.use('/services/oembed', (req, res) => {
|
app.use("/services/oembed", (req, res)=>{
|
||||||
inviteres(req, res);
|
inviteres(req, res);
|
||||||
})
|
});
|
||||||
app.use("/uptime",(req,res)=>{
|
app.use("/uptime",(req,res)=>{
|
||||||
console.log(req.query.name)
|
console.log(req.query.name);
|
||||||
const uptime=stats.uptime[req.query.name];
|
const uptime=stats.uptime[req.query.name];
|
||||||
console.log(req.query.name,uptime,stats.uptime)
|
console.log(req.query.name,uptime,stats.uptime);
|
||||||
res.send(uptime);
|
res.send(uptime);
|
||||||
})
|
});
|
||||||
app.use('/', async (req, res) => {
|
app.use("/", async (req, res)=>{
|
||||||
const scheme = req.secure ? 'https' : 'http';
|
const scheme = req.secure ? "https" : "http";
|
||||||
const host=`${scheme}://${req.get("Host")}`;
|
const host=`${scheme}://${req.get("Host")}`;
|
||||||
const ref=host+req.originalUrl;
|
const ref=host+req.originalUrl;
|
||||||
if(host&&ref){
|
if(host&&ref){
|
||||||
|
const link=`${host}/services/oembed?url=${encodeURIComponent(ref)}`;
|
||||||
const link=`${host}/services/oembed?url=${encodeURIComponent(ref)}`;
|
res.set("Link",`<${link}>; rel="alternate"; type="application/json+oembed"; title="Jank Client oEmbed format"`);
|
||||||
res.set("Link",`<${link}>; rel="alternate"; type="application/json+oembed"; title="Jank Client oEmbed format"`);
|
}else{
|
||||||
}else{
|
console.log(req);
|
||||||
console.log(req);
|
}
|
||||||
}
|
if(req.path==="/"){
|
||||||
if(req.path==="/"){
|
res.sendFile("./webpage/home.html", {root: __dirname});
|
||||||
res.sendFile(`./webpage/home.html`, {root: __dirname});
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if(debugging&&req.path.startsWith("/service.js")){
|
||||||
if(debugging&&req.path.startsWith("/service.js")){
|
res.send("dud");
|
||||||
res.send("dud");
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if(req.path.startsWith("/instances.json")){
|
||||||
if(req.path.startsWith("/instances.json")){
|
res.send(JSON.stringify(instances));
|
||||||
res.send(JSON.stringify(instances));
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if(req.path.startsWith("/invite/")){
|
||||||
if(req.path.startsWith("/invite/")){
|
res.sendFile("./webpage/invite.html", {root: __dirname});
|
||||||
res.sendFile(`./webpage/invite.html`, {root: __dirname});
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if(fs.existsSync(`${__dirname}/webpage${req.path}`)){
|
||||||
if(fs.existsSync(`${__dirname}/webpage${req.path}`)) {
|
res.sendFile(`./webpage${req.path}`, {root: __dirname});
|
||||||
res.sendFile(`./webpage${req.path}`, {root: __dirname});
|
}else if(req.path.endsWith(".js") && fs.existsSync(`${__dirname}/.dist${req.path}`)){
|
||||||
}else if(req.path.endsWith(".js") && fs.existsSync(`${__dirname}/.dist${req.path}`)){
|
const dir=`./.dist${req.path}`;
|
||||||
const dir=`./.dist${req.path}`;
|
res.sendFile(dir, {root: __dirname});
|
||||||
res.sendFile(dir, {root: __dirname});
|
}else if(fs.existsSync(`${__dirname}/webpage${req.path}.html`)){
|
||||||
return;
|
res.sendFile(`./webpage${req.path}.html`, {root: __dirname});
|
||||||
}
|
}else{
|
||||||
else if(fs.existsSync(`${__dirname}/webpage${req.path}.html`)) {
|
res.sendFile("./webpage/index.html", {root: __dirname});
|
||||||
res.sendFile(`./webpage${req.path}.html`, {root: __dirname});
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
res.sendFile("./webpage/index.html", {root: __dirname});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const PORT = process.env.PORT || +process.argv[1] || 8080;
|
const PORT = process.env.PORT || Number(process.argv[1]) || 8080;
|
||||||
app.listen(PORT, () => {});
|
app.listen(PORT, ()=>{});
|
||||||
console.log("this ran :P");
|
console.log("this ran :P");
|
||||||
|
|
||||||
exports.getapiurls=getapiurls;
|
exports.getapiurls=getapiurls;
|
||||||
|
|
278
stats.js
278
stats.js
|
@ -1,152 +1,164 @@
|
||||||
const index = require('./index.js');
|
const index = require("./index.js");
|
||||||
const fs=require("fs");
|
const fs=require("node:fs");
|
||||||
let uptimeObject={};
|
let uptimeObject={};
|
||||||
if(fs.existsSync("./uptime.json")){
|
if(fs.existsSync("./uptime.json")){
|
||||||
try{
|
try{
|
||||||
uptimeObject=JSON.parse(fs.readFileSync('./uptime.json', 'utf8'));
|
uptimeObject=JSON.parse(fs.readFileSync("./uptime.json", "utf8"));
|
||||||
|
}catch{
|
||||||
}catch{
|
uptimeObject={};
|
||||||
uptimeObject={};
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(uptimeObject["undefined"]){
|
if(uptimeObject.undefined){
|
||||||
delete uptimeObject["undefined"];
|
delete uptimeObject.undefined;
|
||||||
updatejson();
|
updatejson();
|
||||||
}
|
}
|
||||||
async function observe(instances){
|
async function observe(instances){
|
||||||
const active=new Set();
|
const active=new Set();
|
||||||
async function resolveinstance(instance){
|
async function resolveinstance(instance){
|
||||||
calcStats(instance);
|
try{
|
||||||
let api;
|
calcStats(instance);
|
||||||
if(instance.urls){
|
}catch(e){
|
||||||
api=instance.urls.api;
|
console.error(e);
|
||||||
}else if(instance.url){
|
}
|
||||||
const urls=await index.getapiurls(instance.url);
|
let api;
|
||||||
if(urls){
|
if(instance.urls){
|
||||||
api=urls.api;
|
api=instance.urls.api;
|
||||||
}
|
}else if(instance.url){
|
||||||
}
|
const urls=await index.getapiurls(instance.url);
|
||||||
if(!api||api===""){
|
if(urls){
|
||||||
|
api=urls.api;
|
||||||
setStatus(instance,false);
|
}
|
||||||
console.warn(instance.name+" does not resolve api URL");
|
}
|
||||||
setTimeout(_=>{resolveinstance(instance)},1000*60*30,);
|
if(!api||api===""){
|
||||||
return
|
setStatus(instance,false);
|
||||||
}
|
console.warn(instance.name+" does not resolve api URL");
|
||||||
active.add(instance.name);
|
setTimeout(_=>{
|
||||||
api+=api.endsWith("/")?"":"/"
|
resolveinstance(instance);
|
||||||
function check(){
|
},1000*60*30,);
|
||||||
fetch(api+"ping").then(_=>{
|
return;
|
||||||
setStatus(instance,_.ok);
|
}
|
||||||
})
|
active.add(instance.name);
|
||||||
}
|
api+=api.endsWith("/")?"":"/";
|
||||||
setTimeout(
|
function check(){
|
||||||
_=>{
|
fetch(api+"ping",{method: "HEAD"}).then(_=>{
|
||||||
check();
|
setStatus(instance,_.ok);
|
||||||
setInterval(_=>{
|
});
|
||||||
check();
|
}
|
||||||
},1000*60*30)
|
setTimeout(
|
||||||
},Math.random()*1000*60*10
|
_=>{
|
||||||
)
|
check();
|
||||||
}
|
setInterval(_=>{
|
||||||
const promlist=[];
|
check();
|
||||||
for(const instance of instances){
|
},1000*60*30);
|
||||||
promlist.push(resolveinstance(instance));
|
},Math.random()*1000*60*10
|
||||||
}
|
);
|
||||||
await Promise.allSettled(promlist);
|
}
|
||||||
for(const key of Object.keys(uptimeObject)){
|
const promlist=[];
|
||||||
if(!active.has(key)){
|
for(const instance of instances){
|
||||||
setStatus(key,false);
|
promlist.push(resolveinstance(instance));
|
||||||
}
|
}
|
||||||
}
|
await Promise.allSettled(promlist);
|
||||||
|
for(const key of Object.keys(uptimeObject)){
|
||||||
|
if(!active.has(key)){
|
||||||
|
setStatus(key,false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function calcStats(instance){
|
function calcStats(instance){
|
||||||
let obj=uptimeObject[instance.name];
|
const obj=uptimeObject[instance.name];
|
||||||
if(!obj) return;
|
if(!obj)return;
|
||||||
const day=Date.now()-1000*60*60*24;
|
const day=Date.now()-1000*60*60*24;
|
||||||
const week=Date.now()-1000*60*60*24*7;
|
const week=Date.now()-1000*60*60*24*7;
|
||||||
let alltime=-1;
|
let alltime=-1;
|
||||||
let totalTimePassed=0;
|
let totalTimePassed=0;
|
||||||
let laststamp=0;
|
let daytime=-1;
|
||||||
let daytime=-1;
|
let weektime=-1;
|
||||||
let weektime=-1;
|
let online=false;
|
||||||
let online=false;
|
let i=0;
|
||||||
for(const thing of obj){
|
for(const thing of obj){
|
||||||
const stamp=thing.time;
|
online=thing.online;
|
||||||
if(alltime===-1){
|
const stamp=thing.time;
|
||||||
laststamp=stamp;
|
if(alltime===-1){
|
||||||
alltime=0;
|
alltime=0;
|
||||||
}
|
}
|
||||||
const timepassed=stamp-laststamp;
|
let timepassed;
|
||||||
totalTimePassed+=timepassed;
|
if(obj[i+1]){
|
||||||
alltime+=online*timepassed;
|
timepassed=obj[i+1].time-stamp;
|
||||||
if(stamp>week){
|
}else{
|
||||||
if(weektime===-1){
|
timepassed=Date.now()-stamp;
|
||||||
weektime=online*(stamp-week);
|
}
|
||||||
}else{
|
totalTimePassed+=timepassed;
|
||||||
weektime+=online*timepassed;
|
alltime+=online*timepassed;
|
||||||
}
|
if(stamp>week){
|
||||||
if(stamp>day){
|
if(weektime===-1){
|
||||||
if(daytime===-1){
|
weektime=online*(stamp-week);
|
||||||
daytime=online*(stamp-day);
|
}else{
|
||||||
}else{
|
weektime+=online*timepassed;
|
||||||
daytime+=online*timepassed;
|
}
|
||||||
}
|
if(stamp>day){
|
||||||
}
|
if(daytime===-1){
|
||||||
}
|
daytime=online*(stamp-day);
|
||||||
online=thing.online;
|
}else{
|
||||||
}
|
daytime+=online*timepassed;
|
||||||
instance.online=online;
|
}
|
||||||
const timepassed=Date.now()-laststamp;
|
}
|
||||||
totalTimePassed+=timepassed;
|
}
|
||||||
daytime+=online*Math.min(timepassed,1000*60*60*24);
|
|
||||||
weektime+=online*Math.min(timepassed,1000*60*60*24*7);
|
i++;
|
||||||
alltime+=online*timepassed;
|
}
|
||||||
alltime/=totalTimePassed;
|
console.log(daytime);
|
||||||
if(timepassed>1000*60*60*24){
|
instance.online=online;
|
||||||
daytime/=1000*60*60*24;
|
alltime/=totalTimePassed;
|
||||||
if(timepassed>1000*60*60*24*7){
|
if(totalTimePassed>1000*60*60*24){
|
||||||
weektime/=1000*60*60*24*7;
|
if(daytime===-1){
|
||||||
}else{
|
daytime=online*1000*60*60*24;
|
||||||
weektime=alltime;
|
}
|
||||||
}
|
daytime/=1000*60*60*24;
|
||||||
}else{
|
if(totalTimePassed>1000*60*60*24*7){
|
||||||
weektime=alltime
|
if(weektime===-1){
|
||||||
daytime=alltime;
|
weektime=online*1000*60*60*24*7;
|
||||||
}
|
}
|
||||||
instance.uptime={daytime,weektime,alltime}
|
weektime/=1000*60*60*24*7;
|
||||||
|
}else{
|
||||||
|
weektime=alltime;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
weektime=alltime;
|
||||||
|
daytime=alltime;
|
||||||
|
}
|
||||||
|
instance.uptime={daytime,weektime,alltime};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param {string|Object} instance
|
* @param {string|Object} instance
|
||||||
* @param {boolean} status
|
* @param {boolean} status
|
||||||
*/
|
*/
|
||||||
function setStatus(instance,status){
|
function setStatus(instance,status){
|
||||||
let name=instance.name;
|
let name=instance.name;
|
||||||
if(typeof instance==="string" ){
|
if(typeof instance==="string"){
|
||||||
name=instance;
|
name=instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
let obj=uptimeObject[name];
|
let obj=uptimeObject[name];
|
||||||
let needSetting=false;
|
let needSetting=false;
|
||||||
if(!obj){
|
if(!obj){
|
||||||
obj=[];
|
obj=[];
|
||||||
uptimeObject[name]=obj;
|
uptimeObject[name]=obj;
|
||||||
needSetting=true;
|
needSetting=true;
|
||||||
}else{
|
}else{
|
||||||
if(obj[obj.length-1].online!==status){
|
if(obj.at(-1).online!==status){
|
||||||
needSetting=true;
|
needSetting=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(needSetting){
|
if(needSetting){
|
||||||
obj.push({time:Date.now(),online:status});
|
obj.push({time: Date.now(),online: status});
|
||||||
updatejson();
|
updatejson();
|
||||||
}
|
}
|
||||||
if(typeof instance!=="string" ){
|
if(typeof instance!=="string"){
|
||||||
calcStats(instance);
|
calcStats(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function updatejson(){
|
function updatejson(){
|
||||||
fs.writeFile('./uptime.json',JSON.stringify(uptimeObject),_=>{});
|
fs.writeFile("./uptime.json",JSON.stringify(uptimeObject),_=>{});
|
||||||
}
|
}
|
||||||
exports.observe=observe;
|
exports.observe=observe;
|
||||||
exports.uptime=uptimeObject;
|
exports.uptime=uptimeObject;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"removeComments": false,
|
"removeComments": false,
|
||||||
"noImplicitThis":true,
|
"noImplicitThis":true,
|
||||||
"useUnknownInCatchVariables":true,
|
"useUnknownInCatchVariables":true,
|
||||||
"strictNullChecks":false
|
"strictNullChecks":true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./webpage/*.ts"
|
"./webpage/*.ts"
|
||||||
|
|
304
webpage/audio.ts
304
webpage/audio.ts
|
@ -1,146 +1,164 @@
|
||||||
import {getBulkInfo} from "./login.js";
|
import{getBulkInfo}from"./login.js";
|
||||||
|
|
||||||
class Voice{
|
class Voice{
|
||||||
audioCtx:AudioContext;
|
audioCtx:AudioContext;
|
||||||
info:{wave:string|Function,freq:number};
|
info:{wave:string|Function,freq:number};
|
||||||
playing:boolean;
|
playing:boolean;
|
||||||
myArrayBuffer:AudioBuffer;
|
myArrayBuffer:AudioBuffer;
|
||||||
gainNode:GainNode;
|
gainNode:GainNode;
|
||||||
buffer:Float32Array;
|
buffer:Float32Array;
|
||||||
source:AudioBufferSourceNode;
|
source:AudioBufferSourceNode;
|
||||||
constructor(wave:string|Function,freq:number,volume=1){
|
constructor(wave:string|Function,freq:number,volume=1){
|
||||||
this.audioCtx = new (window.AudioContext)();
|
this.audioCtx = new (window.AudioContext)();
|
||||||
this.info={wave:wave,freq:freq}
|
this.info={wave,freq};
|
||||||
this.playing=false;
|
this.playing=false;
|
||||||
this.myArrayBuffer=this.audioCtx.createBuffer(
|
this.myArrayBuffer=this.audioCtx.createBuffer(
|
||||||
1,
|
1,
|
||||||
this.audioCtx.sampleRate,
|
this.audioCtx.sampleRate,
|
||||||
this.audioCtx.sampleRate,
|
this.audioCtx.sampleRate,
|
||||||
);
|
);
|
||||||
this.gainNode = this.audioCtx.createGain();
|
this.gainNode = this.audioCtx.createGain();
|
||||||
this.gainNode.gain.value=volume;
|
this.gainNode.gain.value=volume;
|
||||||
this.gainNode.connect(this.audioCtx.destination);
|
this.gainNode.connect(this.audioCtx.destination);
|
||||||
this.buffer=this.myArrayBuffer.getChannelData(0);
|
this.buffer=this.myArrayBuffer.getChannelData(0);
|
||||||
this.source = this.audioCtx.createBufferSource();
|
this.source = this.audioCtx.createBufferSource();
|
||||||
this.source.buffer = this.myArrayBuffer;
|
this.source.buffer = this.myArrayBuffer;
|
||||||
this.source.loop=true;
|
this.source.loop=true;
|
||||||
this.source.start();
|
this.source.start();
|
||||||
this.updateWave();
|
this.updateWave();
|
||||||
}
|
}
|
||||||
get wave():string|Function{
|
get wave():string|Function{
|
||||||
return this.info.wave;
|
return this.info.wave;
|
||||||
}
|
}
|
||||||
get freq():number{
|
get freq():number{
|
||||||
return this.info.freq;
|
return this.info.freq;
|
||||||
}
|
}
|
||||||
set wave(wave:string|Function){
|
set wave(wave:string|Function){
|
||||||
this.info.wave=wave;
|
this.info.wave=wave;
|
||||||
this.updateWave();
|
this.updateWave();
|
||||||
}
|
}
|
||||||
set freq(freq:number){
|
set freq(freq:number){
|
||||||
this.info.freq=freq;
|
this.info.freq=freq;
|
||||||
this.updateWave();
|
this.updateWave();
|
||||||
}
|
}
|
||||||
updateWave():void{
|
updateWave():void{
|
||||||
const func=this.waveFunction();
|
const func=this.waveFunction();
|
||||||
for (let i = 0; i < this.buffer.length; i++) {
|
for(let i = 0; i < this.buffer.length; i++){
|
||||||
this.buffer[i]=func(i/this.audioCtx.sampleRate,this.freq);
|
this.buffer[i]=func(i/this.audioCtx.sampleRate,this.freq);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
waveFunction():Function{
|
||||||
waveFunction():Function{
|
if(typeof this.wave === "function"){
|
||||||
if(typeof this.wave === 'function'){
|
return this.wave;
|
||||||
return this.wave;
|
}
|
||||||
}
|
switch(this.wave){
|
||||||
switch(this.wave){
|
case"sin":
|
||||||
case "sin":
|
return(t:number,freq:number)=>{
|
||||||
return (t:number,freq:number)=>{
|
return Math.sin(t*Math.PI*2*freq);
|
||||||
return Math.sin(t*Math.PI*2*freq);
|
};
|
||||||
}
|
case"triangle":
|
||||||
case "triangle":
|
return(t:number,freq:number)=>{
|
||||||
return (t:number,freq:number)=>{
|
return Math.abs((4*t*freq)%4-2)-1;
|
||||||
return Math.abs((4*t*freq)%4-2)-1;
|
};
|
||||||
}
|
case"sawtooth":
|
||||||
case "sawtooth":
|
return(t:number,freq:number)=>{
|
||||||
return (t:number,freq:number)=>{
|
return((t*freq)%1)*2-1;
|
||||||
return ((t*freq)%1)*2-1;
|
};
|
||||||
}
|
case"square":
|
||||||
case "square":
|
return(t:number,freq:number)=>{
|
||||||
return (t:number,freq:number)=>{
|
return(t*freq)%2<1?1:-1;
|
||||||
return (t*freq)%2<1?1:-1;
|
};
|
||||||
}
|
case"white":
|
||||||
case "white":
|
return(_t:number,_freq:number)=>{
|
||||||
return (_t:number,_freq:number)=>{
|
return Math.random()*2-1;
|
||||||
return Math.random()*2-1;
|
};
|
||||||
}
|
case"noise":
|
||||||
case "noise":
|
return(_t:number,_freq:number)=>{
|
||||||
return (_t:number,_freq:number)=>{
|
return 0;
|
||||||
return 0;
|
};
|
||||||
}
|
}
|
||||||
}
|
return new Function();
|
||||||
return new Function();
|
}
|
||||||
}
|
play():void{
|
||||||
play():void{
|
if(this.playing){
|
||||||
if(this.playing){
|
return;
|
||||||
return;
|
}
|
||||||
}
|
this.source.connect(this.gainNode);
|
||||||
this.source.connect(this.gainNode);
|
this.playing=true;
|
||||||
this.playing=true;
|
}
|
||||||
|
stop():void{
|
||||||
}
|
if(this.playing){
|
||||||
stop():void{
|
this.source.disconnect();
|
||||||
if(this.playing){
|
this.playing=false;
|
||||||
this.source.disconnect();
|
}
|
||||||
this.playing=false;
|
}
|
||||||
}
|
static noises(noise:string):void{
|
||||||
}
|
switch(noise){
|
||||||
static noises(noise:string):void{
|
case"three":{
|
||||||
switch(noise){
|
const voicy=new Voice("sin",800);
|
||||||
case "three":{
|
voicy.play();
|
||||||
const voicy=new Voice("sin",800);
|
setTimeout(_=>{
|
||||||
voicy.play();
|
voicy.freq=1000;
|
||||||
setTimeout(_=>{voicy.freq=1000},50);
|
},50);
|
||||||
setTimeout(_=>{voicy.freq=1300},100);
|
setTimeout(_=>{
|
||||||
setTimeout(_=>{voicy.stop()},150);
|
voicy.freq=1300;
|
||||||
break;
|
},100);
|
||||||
}
|
setTimeout(_=>{
|
||||||
case "zip":{
|
voicy.stop();
|
||||||
const voicy=new Voice((t:number,freq:number)=>{
|
},150);
|
||||||
return Math.sin(((t+2)**(Math.cos(t*4)))*Math.PI*2*freq);
|
break;
|
||||||
},700);
|
}
|
||||||
voicy.play();
|
case"zip":{
|
||||||
setTimeout(_=>{voicy.stop()},150);
|
const voicy=new Voice((t:number,freq:number)=>{
|
||||||
break;
|
return Math.sin(((t+2)**(Math.cos(t*4)))*Math.PI*2*freq);
|
||||||
}
|
},700);
|
||||||
case "square":{
|
voicy.play();
|
||||||
const voicy=new Voice("square",600,.4);
|
setTimeout(_=>{
|
||||||
voicy.play()
|
voicy.stop();
|
||||||
setTimeout(_=>{voicy.freq=800},50);
|
},150);
|
||||||
setTimeout(_=>{voicy.freq=1000},100);
|
break;
|
||||||
setTimeout(_=>{voicy.stop()},150);
|
}
|
||||||
break;
|
case"square":{
|
||||||
}
|
const voicy=new Voice("square",600,0.4);
|
||||||
case "beep":{
|
voicy.play();
|
||||||
const voicy=new Voice("sin",800);
|
setTimeout(_=>{
|
||||||
voicy.play();
|
voicy.freq=800;
|
||||||
setTimeout(_=>{voicy.stop()},50);
|
},50);
|
||||||
setTimeout(_=>{voicy.play();},100);
|
setTimeout(_=>{
|
||||||
setTimeout(_=>{voicy.stop()},150);
|
voicy.freq=1000;
|
||||||
break;
|
},100);
|
||||||
}
|
setTimeout(_=>{
|
||||||
}
|
voicy.stop();
|
||||||
}
|
},150);
|
||||||
static get sounds(){
|
break;
|
||||||
return ["three","zip","square","beep"];
|
}
|
||||||
}
|
case"beep":{
|
||||||
static setNotificationSound(sound:string){
|
const voicy=new Voice("sin",800);
|
||||||
let userinfos=getBulkInfo();
|
voicy.play();
|
||||||
userinfos.preferences.notisound=sound;
|
setTimeout(_=>{
|
||||||
localStorage.setItem("userinfos",JSON.stringify(userinfos));
|
voicy.stop();
|
||||||
}
|
},50);
|
||||||
static getNotificationSound(){
|
setTimeout(_=>{
|
||||||
let userinfos=getBulkInfo();
|
voicy.play();
|
||||||
return userinfos.preferences.notisound;
|
},100);
|
||||||
}
|
setTimeout(_=>{
|
||||||
|
voicy.stop();
|
||||||
|
},150);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static get sounds(){
|
||||||
|
return["three","zip","square","beep"];
|
||||||
|
}
|
||||||
|
static setNotificationSound(sound:string){
|
||||||
|
const userinfos=getBulkInfo();
|
||||||
|
userinfos.preferences.notisound=sound;
|
||||||
|
localStorage.setItem("userinfos",JSON.stringify(userinfos));
|
||||||
|
}
|
||||||
|
static getNotificationSound(){
|
||||||
|
const userinfos=getBulkInfo();
|
||||||
|
return userinfos.preferences.notisound;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export {Voice as Voice};
|
export{Voice};
|
||||||
|
|
2119
webpage/channel.ts
2119
webpage/channel.ts
File diff suppressed because it is too large
Load diff
|
@ -1,82 +1,88 @@
|
||||||
class Contextmenu<x,y>{
|
class Contextmenu<x,y>{
|
||||||
static currentmenu;
|
static currentmenu;
|
||||||
name:string;
|
name:string;
|
||||||
buttons:[string,(this:x,arg:y,e:MouseEvent)=>void,string|null,(this:x,arg:y)=>boolean,(this:x,arg:y)=>boolean,string][];
|
buttons:[string,(this:x,arg:y,e:MouseEvent)=>void,string|null,(this:x,arg:y)=>boolean,(this:x,arg:y)=>boolean,string][];
|
||||||
div:HTMLDivElement;
|
div:HTMLDivElement;
|
||||||
static setup(){
|
static setup(){
|
||||||
Contextmenu.currentmenu="";
|
Contextmenu.currentmenu="";
|
||||||
document.addEventListener('click', function(event) {
|
document.addEventListener("click", event=>{
|
||||||
if(Contextmenu.currentmenu==""){
|
if(Contextmenu.currentmenu==""){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!Contextmenu.currentmenu.contains(event.target)) {
|
if(!Contextmenu.currentmenu.contains(event.target)){
|
||||||
Contextmenu.currentmenu.remove();
|
Contextmenu.currentmenu.remove();
|
||||||
Contextmenu.currentmenu="";
|
Contextmenu.currentmenu="";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
constructor(name:string){
|
constructor(name:string){
|
||||||
this.name=name;
|
this.name=name;
|
||||||
this.buttons=[]
|
this.buttons=[];
|
||||||
}
|
}
|
||||||
addbutton(text:string,onclick:(this:x,arg:y,e:MouseEvent)=>void,img:null|string=null,shown:(this:x,arg:y)=>boolean=_=>true,enabled:(this:x,arg:y)=>boolean=_=>true){
|
addbutton(text:string,onclick:(this:x,arg:y,e:MouseEvent)=>void,img:null|string=null,shown:(this:x,arg:y)=>boolean=_=>true,enabled:(this:x,arg:y)=>boolean=_=>true){
|
||||||
this.buttons.push([text,onclick,img,shown,enabled,"button"]);
|
this.buttons.push([text,onclick,img,shown,enabled,"button"]);
|
||||||
return {};
|
return{};
|
||||||
}
|
}
|
||||||
addsubmenu(text:string,onclick:(this:x,arg:y,e:MouseEvent)=>void,img=null,shown:(this:x,arg:y)=>boolean=_=>true,enabled:(this:x,arg:y)=>boolean=_=>true){
|
addsubmenu(text:string,onclick:(this:x,arg:y,e:MouseEvent)=>void,img=null,shown:(this:x,arg:y)=>boolean=_=>true,enabled:(this:x,arg:y)=>boolean=_=>true){
|
||||||
this.buttons.push([text,onclick,img,shown,enabled,"submenu"])
|
this.buttons.push([text,onclick,img,shown,enabled,"submenu"]);
|
||||||
return {};
|
return{};
|
||||||
}
|
}
|
||||||
makemenu(x:number,y:number,addinfo:any,other:y){
|
makemenu(x:number,y:number,addinfo:any,other:y){
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
div.classList.add("contextmenu","flexttb");
|
div.classList.add("contextmenu","flexttb");
|
||||||
for(const thing of this.buttons){
|
|
||||||
if(!thing[3].bind(addinfo)(other)){continue;}
|
|
||||||
const intext=document.createElement("button")
|
|
||||||
intext.disabled=!thing[4].bind(addinfo)(other);
|
|
||||||
intext.classList.add("contextbutton")
|
|
||||||
intext.textContent=thing[0]
|
|
||||||
console.log(thing)
|
|
||||||
if(thing[5]==="button"||thing[5]==="submenu"){
|
|
||||||
intext.onclick=thing[1].bind(addinfo,other);
|
|
||||||
}
|
|
||||||
|
|
||||||
div.appendChild(intext);
|
let visibleButtons=0;
|
||||||
}
|
for(const thing of this.buttons){
|
||||||
if(Contextmenu.currentmenu!=""){
|
if(!thing[3].bind(addinfo)(other))continue;
|
||||||
Contextmenu.currentmenu.remove();
|
visibleButtons++;
|
||||||
}
|
|
||||||
div.style.top = y+'px';
|
const intext=document.createElement("button");
|
||||||
div.style.left = x+'px';
|
intext.disabled=!thing[4].bind(addinfo)(other);
|
||||||
document.body.appendChild(div);
|
intext.classList.add("contextbutton");
|
||||||
Contextmenu.keepOnScreen(div);
|
intext.textContent=thing[0];
|
||||||
console.log(div)
|
console.log(thing);
|
||||||
Contextmenu.currentmenu=div;
|
if(thing[5]==="button"||thing[5]==="submenu"){
|
||||||
return this.div;
|
intext.onclick=thing[1].bind(addinfo,other);
|
||||||
}
|
}
|
||||||
bindContextmenu(obj:HTMLElement,addinfo:x,other:y){
|
|
||||||
const func=(event) => {
|
div.appendChild(intext);
|
||||||
event.preventDefault();
|
}
|
||||||
event.stopImmediatePropagation();
|
if(visibleButtons == 0)return;
|
||||||
this.makemenu(event.clientX,event.clientY,addinfo,other);
|
|
||||||
}
|
if(Contextmenu.currentmenu!=""){
|
||||||
obj.addEventListener("contextmenu", func);
|
Contextmenu.currentmenu.remove();
|
||||||
return func;
|
}
|
||||||
}
|
div.style.top = y+"px";
|
||||||
static keepOnScreen(obj:HTMLElement){
|
div.style.left = x+"px";
|
||||||
const html = document.documentElement.getBoundingClientRect();
|
document.body.appendChild(div);
|
||||||
const docheight=html.height
|
Contextmenu.keepOnScreen(div);
|
||||||
const docwidth=html.width
|
console.log(div);
|
||||||
const box=obj.getBoundingClientRect();
|
Contextmenu.currentmenu=div;
|
||||||
console.log(box,docheight,docwidth);
|
return this.div;
|
||||||
if(box.right>docwidth){
|
}
|
||||||
console.log("test")
|
bindContextmenu(obj:HTMLElement,addinfo:x,other:y){
|
||||||
obj.style.left = docwidth-box.width+'px';
|
const func=event=>{
|
||||||
}
|
event.preventDefault();
|
||||||
if(box.bottom>docheight){
|
event.stopImmediatePropagation();
|
||||||
obj.style.top = docheight-box.height+'px';
|
this.makemenu(event.clientX,event.clientY,addinfo,other);
|
||||||
}
|
};
|
||||||
}
|
obj.addEventListener("contextmenu", func);
|
||||||
|
return func;
|
||||||
|
}
|
||||||
|
static keepOnScreen(obj:HTMLElement){
|
||||||
|
const html = document.documentElement.getBoundingClientRect();
|
||||||
|
const docheight=html.height;
|
||||||
|
const docwidth=html.width;
|
||||||
|
const box=obj.getBoundingClientRect();
|
||||||
|
console.log(box,docheight,docwidth);
|
||||||
|
if(box.right>docwidth){
|
||||||
|
console.log("test");
|
||||||
|
obj.style.left = docwidth-box.width+"px";
|
||||||
|
}
|
||||||
|
if(box.bottom>docheight){
|
||||||
|
obj.style.top = docheight-box.height+"px";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Contextmenu.setup();
|
Contextmenu.setup();
|
||||||
export {Contextmenu as Contextmenu}
|
export{Contextmenu};
|
||||||
|
|
|
@ -1,251 +1,254 @@
|
||||||
|
|
||||||
class Dialog{
|
class Dialog{
|
||||||
layout;
|
layout;
|
||||||
onclose: Function;
|
onclose: Function;
|
||||||
onopen: Function;
|
onopen: Function;
|
||||||
html:HTMLDivElement;
|
html:HTMLDivElement;
|
||||||
background: HTMLDivElement;
|
background: HTMLDivElement;
|
||||||
constructor(layout,onclose=_=>{},onopen=_=>{}){
|
constructor(layout,onclose=_=>{},onopen=_=>{}){
|
||||||
this.layout=layout;
|
this.layout=layout;
|
||||||
this.onclose=onclose;
|
this.onclose=onclose;
|
||||||
this.onopen=onopen;
|
this.onopen=onopen;
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
div.appendChild(this.tohtml(layout))
|
div.appendChild(this.tohtml(layout));
|
||||||
this.html=div;
|
this.html=div;
|
||||||
this.html.classList.add("centeritem");
|
this.html.classList.add("centeritem");
|
||||||
if(!(layout[0]==="img")){
|
if(!(layout[0]==="img")){
|
||||||
|
this.html.classList.add("nonimagecenter");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tohtml(array:any[]){
|
||||||
|
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);
|
||||||
|
|
||||||
this.html.classList.add("nonimagecenter");
|
for(const thing of array){
|
||||||
}
|
if(thing==="hdiv"){
|
||||||
}
|
continue;
|
||||||
tohtml(array:any[]){
|
}
|
||||||
switch(array[0]){
|
const td=document.createElement("td");
|
||||||
case "img":
|
td.appendChild(this.tohtml(thing));
|
||||||
const img=document.createElement("img");
|
tr.appendChild(td);
|
||||||
img.src=array[1];
|
}
|
||||||
if(array[2]!=undefined){
|
return hdiv;
|
||||||
if(array[2].length==2){
|
case"vdiv":
|
||||||
img.width=array[2][0];
|
const vdiv=document.createElement("table");
|
||||||
img.height=array[2][1];
|
for(const thing of array){
|
||||||
}else if(array[2][0]=="fit"){
|
if(thing==="vdiv"){
|
||||||
img.classList.add("imgfit")
|
continue;
|
||||||
}
|
}
|
||||||
}
|
const tr=document.createElement("tr");
|
||||||
return img;
|
tr.appendChild(this.tohtml(thing));
|
||||||
case "hdiv":
|
vdiv.appendChild(tr);
|
||||||
const hdiv=document.createElement("table");
|
}
|
||||||
const tr=document.createElement("tr");
|
return vdiv;
|
||||||
hdiv.appendChild(tr)
|
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");
|
||||||
|
|
||||||
for(const thing of array){
|
const label=document.createElement("span");
|
||||||
if(thing==="hdiv"){continue;}
|
input.textContent=array[2];
|
||||||
const td=document.createElement("td");
|
label.textContent=array[1];
|
||||||
td.appendChild(this.tohtml(thing));
|
div.appendChild(label);
|
||||||
tr.appendChild(td);
|
div.appendChild(input);
|
||||||
}
|
input.addEventListener("click",array[3]);
|
||||||
return hdiv;
|
return div;
|
||||||
case "vdiv":
|
}
|
||||||
const vdiv=document.createElement("table");
|
case"mdbox":
|
||||||
for(const thing of array){
|
{
|
||||||
if(thing==="vdiv"){continue;}
|
const div=document.createElement("div");
|
||||||
const tr=document.createElement("tr");
|
const input=document.createElement("textarea");
|
||||||
tr.appendChild(this.tohtml(thing));
|
input.value=array[2];
|
||||||
vdiv.appendChild(tr);
|
const label=document.createElement("span");
|
||||||
}
|
label.textContent=array[1];
|
||||||
return vdiv;
|
input.addEventListener("input",array[3]);
|
||||||
case "checkbox":
|
div.appendChild(label);
|
||||||
{
|
div.appendChild(document.createElement("br"));
|
||||||
const div=document.createElement("div");
|
div.appendChild(input);
|
||||||
const checkbox = document.createElement('input');
|
return div;
|
||||||
div.appendChild(checkbox)
|
}
|
||||||
const label=document.createElement("span");
|
case"textbox":
|
||||||
checkbox.checked=array[2];
|
{
|
||||||
label.textContent=array[1];
|
const div=document.createElement("div");
|
||||||
div.appendChild(label);
|
const input=document.createElement("input");
|
||||||
checkbox.addEventListener("change",array[3]);
|
input.value=array[2];
|
||||||
checkbox.type = "checkbox";
|
input.type="text";
|
||||||
return div;
|
const label=document.createElement("span");
|
||||||
}
|
label.textContent=array[1];
|
||||||
case "button":
|
console.log(array[3]);
|
||||||
{
|
input.addEventListener("input",array[3]);
|
||||||
const div=document.createElement("div");
|
div.appendChild(label);
|
||||||
const input = document.createElement('button');
|
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",()=>{
|
||||||
|
let i=-1;
|
||||||
|
for(const thing of fieldset.children){
|
||||||
|
i++;
|
||||||
|
if(i===0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const checkbox = thing.children[0].children[0] as HTMLInputElement;
|
||||||
|
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");
|
||||||
|
|
||||||
const label=document.createElement("span");
|
label.appendChild(input);
|
||||||
input.textContent=array[2];
|
const span=document.createElement("span");
|
||||||
label.textContent=array[1];
|
span.textContent=thing;
|
||||||
div.appendChild(label);
|
label.appendChild(span);
|
||||||
div.appendChild(input)
|
div.appendChild(label);
|
||||||
input.addEventListener("click",array[3]);
|
fieldset.appendChild(div);
|
||||||
return div;
|
i++;
|
||||||
}
|
}
|
||||||
case "mdbox":
|
div.appendChild(fieldset);
|
||||||
{
|
return div;
|
||||||
const div=document.createElement("div");
|
}
|
||||||
const input=document.createElement("textarea");
|
case"html":
|
||||||
input.value=array[2];
|
return array[1];
|
||||||
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] as HTMLInputElement;
|
|
||||||
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);
|
case"select":{
|
||||||
const span=document.createElement("span");
|
const div=document.createElement("div");
|
||||||
span.textContent=thing;
|
const label=document.createElement("label");
|
||||||
label.appendChild(span);
|
const select=document.createElement("select");
|
||||||
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];
|
label.textContent=array[1];
|
||||||
div.append(label);
|
div.append(label);
|
||||||
div.appendChild(select);
|
div.appendChild(select);
|
||||||
for(const thing of array[2]){
|
for(const thing of array[2]){
|
||||||
const option = document.createElement("option");
|
const option = document.createElement("option");
|
||||||
option.textContent=thing;
|
option.textContent=thing;
|
||||||
select.appendChild(option);
|
select.appendChild(option);
|
||||||
}
|
}
|
||||||
select.selectedIndex=array[4];
|
select.selectedIndex=array[4];
|
||||||
select.addEventListener("change",array[3]);
|
select.addEventListener("change",array[3]);
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
case "tabs":{
|
case"tabs":{
|
||||||
const table=document.createElement("table");
|
const table=document.createElement("table");
|
||||||
const tabs=document.createElement("tr");
|
const tabs=document.createElement("tr");
|
||||||
tabs.classList.add("tabbed-head");
|
tabs.classList.add("tabbed-head");
|
||||||
table.appendChild(tabs);
|
table.appendChild(tabs);
|
||||||
const td=document.createElement("td");
|
const td=document.createElement("td");
|
||||||
tabs.appendChild(td);
|
tabs.appendChild(td);
|
||||||
const content=document.createElement("tr");
|
const content=document.createElement("tr");
|
||||||
content.classList.add("tabbed-content");
|
content.classList.add("tabbed-content");
|
||||||
table.appendChild(content);
|
table.appendChild(content);
|
||||||
|
|
||||||
let shown;
|
let shown;
|
||||||
for(const thing of array[1]){
|
for(const thing of array[1]){
|
||||||
|
const button=document.createElement("button");
|
||||||
const button=document.createElement("button");
|
button.textContent=thing[0];
|
||||||
button.textContent=thing[0];
|
td.appendChild(button);
|
||||||
td.appendChild(button);
|
|
||||||
|
|
||||||
|
|
||||||
const tdcontent=document.createElement("td");
|
const tdcontent=document.createElement("td");
|
||||||
tdcontent.colSpan=array[1].length;
|
tdcontent.colSpan=array[1].length;
|
||||||
tdcontent.appendChild(this.tohtml(thing[1]));
|
tdcontent.appendChild(this.tohtml(thing[1]));
|
||||||
content.appendChild(tdcontent);
|
content.appendChild(tdcontent);
|
||||||
if(!shown){
|
if(!shown){
|
||||||
shown=tdcontent;
|
shown=tdcontent;
|
||||||
}else{
|
}else{
|
||||||
tdcontent.hidden=true;
|
tdcontent.hidden=true;
|
||||||
}
|
}
|
||||||
button.addEventListener("click",_=>{
|
button.addEventListener("click",_=>{
|
||||||
shown.hidden=true;
|
shown.hidden=true;
|
||||||
tdcontent.hidden=false;
|
tdcontent.hidden=false;
|
||||||
shown=tdcontent;
|
shown=tdcontent;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
console.error("can't find element:"+array[0]," full element:"+array)
|
console.error("can't find element:"+array[0]," full element:"+array);
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
show(){
|
||||||
show(){
|
this.onopen();
|
||||||
this.onopen();
|
console.log("fullscreen");
|
||||||
console.log("fullscreen")
|
this.background=document.createElement("div");
|
||||||
this.background=document.createElement("div");
|
this.background.classList.add("background");
|
||||||
this.background.classList.add("background");
|
document.body.appendChild(this.background);
|
||||||
document.body.appendChild(this.background);
|
document.body.appendChild(this.html);
|
||||||
document.body.appendChild(this.html);
|
this.background.onclick = _=>{
|
||||||
this.background.onclick = _=>{this.hide()};
|
this.hide();
|
||||||
}
|
};
|
||||||
hide(){
|
}
|
||||||
document.body.removeChild(this.background);
|
hide(){
|
||||||
document.body.removeChild(this.html);
|
document.body.removeChild(this.background);
|
||||||
}
|
document.body.removeChild(this.html);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export {Dialog};
|
export{Dialog};
|
||||||
|
|
|
@ -1,61 +1,61 @@
|
||||||
import {Guild} from "./guild.js";
|
import{Guild}from"./guild.js";
|
||||||
import { Channel } from "./channel.js";
|
import{ Channel }from"./channel.js";
|
||||||
import { Message } from "./message.js";
|
import{ Message }from"./message.js";
|
||||||
import { Localuser } from "./localuser.js";
|
import{ Localuser }from"./localuser.js";
|
||||||
import {User} from "./user.js";
|
import{User}from"./user.js";
|
||||||
import { Member } from "./member.js";
|
import{ Member }from"./member.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import{ SnowFlake }from"./snowflake.js";
|
||||||
import { dirrectjson, memberjson } from "./jsontypes.js";
|
import{ dirrectjson, memberjson }from"./jsontypes.js";
|
||||||
import { Permissions } from "./permissions.js";
|
import{ Permissions }from"./permissions.js";
|
||||||
|
|
||||||
class Direct extends Guild{
|
class Direct extends Guild{
|
||||||
constructor(json:dirrectjson[],owner:Localuser){
|
constructor(json:dirrectjson[],owner:Localuser){
|
||||||
super(-1,owner,null);
|
super(-1,owner,null);
|
||||||
this.message_notifications=0;
|
this.message_notifications=0;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
if(!this.localuser){
|
if(!this.localuser){
|
||||||
console.error("Owner was not included, please fix")
|
console.error("Owner was not included, please fix");
|
||||||
}
|
}
|
||||||
this.headers=this.localuser.headers;
|
this.headers=this.localuser.headers;
|
||||||
this.channels=[];
|
this.channels=[];
|
||||||
this.channelids={};
|
this.channelids={};
|
||||||
this.snowflake=new SnowFlake("@me",this);
|
this.snowflake=new SnowFlake("@me",this);
|
||||||
this.properties={};
|
this.properties={};
|
||||||
this.roles=[];
|
this.roles=[];
|
||||||
this.roleids=new Map();
|
this.roleids=new Map();
|
||||||
this.prevchannel=undefined;
|
this.prevchannel=undefined;
|
||||||
this.properties.name="Direct Messages";
|
this.properties.name="Direct Messages";
|
||||||
for(const thing of json){
|
for(const thing of json){
|
||||||
const temp=new Group(thing,this);
|
const temp=new Group(thing,this);
|
||||||
this.channels.push(temp);
|
this.channels.push(temp);
|
||||||
this.channelids[temp.id]=temp;
|
this.channelids[temp.id]=temp;
|
||||||
}
|
}
|
||||||
this.headchannels=this.channels;
|
this.headchannels=this.channels;
|
||||||
}
|
}
|
||||||
createChannelpac(json){
|
createChannelpac(json){
|
||||||
const thischannel=new Group(json,this);
|
const thischannel=new Group(json,this);
|
||||||
this.channelids[json.id]=thischannel;
|
this.channelids[json.id]=thischannel;
|
||||||
this.channels.push(thischannel);
|
this.channels.push(thischannel);
|
||||||
this.calculateReorder();
|
this.calculateReorder();
|
||||||
this.printServers();
|
this.printServers();
|
||||||
}
|
}
|
||||||
giveMember(_member:memberjson){
|
giveMember(_member:memberjson){
|
||||||
console.error("not a real guild, can't give member object")
|
console.error("not a real guild, can't give member object");
|
||||||
}
|
}
|
||||||
getRole(ID:string){
|
getRole(ID:string){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
hasRole(r:string){
|
hasRole(r:string){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
isAdmin(){
|
isAdmin(){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
unreaddms(){
|
unreaddms(){
|
||||||
for(const thing of this.channels){
|
for(const thing of this.channels){
|
||||||
(thing as Group).unreads();
|
(thing as Group).unreads();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dmPermissions = new Permissions("0");
|
const dmPermissions = new Permissions("0");
|
||||||
|
@ -82,139 +82,139 @@ dmPermissions.setPermission("STREAM",1);
|
||||||
dmPermissions.setPermission("USE_VAD",1);
|
dmPermissions.setPermission("USE_VAD",1);
|
||||||
|
|
||||||
class Group extends Channel{
|
class Group extends Channel{
|
||||||
user:User;
|
user:User;
|
||||||
constructor(json:dirrectjson,owner:Direct){
|
constructor(json:dirrectjson,owner:Direct){
|
||||||
super(-1,owner);
|
super(-1,owner);
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.headers=this.guild.headers;
|
this.headers=this.guild.headers;
|
||||||
this.name=json.recipients[0]?.username;
|
this.name=json.recipients[0]?.username;
|
||||||
if(json.recipients[0]){
|
if(json.recipients[0]){
|
||||||
this.user=new User(json.recipients[0],this.localuser);
|
this.user=new User(json.recipients[0],this.localuser);
|
||||||
}else{
|
}else{
|
||||||
this.user=this.localuser.user;
|
this.user=this.localuser.user;
|
||||||
}
|
}
|
||||||
this.name??=this.localuser.user.username;
|
this.name??=this.localuser.user.username;
|
||||||
this.snowflake=new SnowFlake(json.id,this);
|
this.snowflake=new SnowFlake(json.id,this);
|
||||||
this.parent_id=null;
|
this.parent_id=null;
|
||||||
this.parent=null;
|
this.parent=null;
|
||||||
this.children=[];
|
this.children=[];
|
||||||
this.guild_id="@me";
|
this.guild_id="@me";
|
||||||
this.messageids=new Map();
|
this.messageids=new Map();
|
||||||
this.permission_overwrites=new Map();
|
this.permission_overwrites=new Map();
|
||||||
this.lastmessageid=json.last_message_id;
|
this.lastmessageid=json.last_message_id;
|
||||||
this.lastmessageid??=null;
|
this.mentions=0;
|
||||||
this.mentions=0;
|
this.setUpInfiniteScroller();
|
||||||
this.setUpInfiniteScroller();
|
if(this.lastmessageid){
|
||||||
if(this.lastmessageid){
|
this.position=Number((BigInt(this.lastmessageid)>>22n)+1420070400000n);
|
||||||
this.position=Number((BigInt(this.lastmessageid)>>22n)+1420070400000n);
|
}
|
||||||
}
|
this.position=-Math.max(this.position,this.snowflake.getUnixTime());
|
||||||
this.position=-Math.max(this.position,this.snowflake.getUnixTime());
|
}
|
||||||
}
|
createguildHTML(){
|
||||||
createguildHTML(){
|
const div=document.createElement("div");
|
||||||
const div=document.createElement("div")
|
div.classList.add("channeleffects");
|
||||||
div.classList.add("channeleffects");
|
const myhtml=document.createElement("span");
|
||||||
const myhtml=document.createElement("span");
|
myhtml.textContent=this.name;
|
||||||
myhtml.textContent=this.name;
|
div.appendChild(this.user.buildpfp());
|
||||||
div.appendChild(this.user.buildpfp());
|
div.appendChild(myhtml);
|
||||||
div.appendChild(myhtml);
|
div["myinfo"]=this;
|
||||||
div["myinfo"]=this;
|
div.onclick=_=>{
|
||||||
div.onclick=_=>{
|
this.getHTML();
|
||||||
this.getHTML();
|
};
|
||||||
}
|
return div;
|
||||||
return div;
|
}
|
||||||
}
|
async getHTML(){
|
||||||
async getHTML(){
|
const id=++Channel.genid;
|
||||||
const id=++Channel.genid;
|
if(this.guild!==this.localuser.lookingguild){
|
||||||
if(this.guild!==this.localuser.lookingguild){
|
this.guild.loadGuild();
|
||||||
this.guild.loadGuild();
|
}
|
||||||
}
|
this.guild.prevchannel=this;
|
||||||
this.guild.prevchannel=this;
|
this.localuser.channelfocus=this;
|
||||||
this.localuser.channelfocus=this;
|
const prom=this.infinite.delete();
|
||||||
const prom=this.infinite.delete();
|
await this.putmessages();
|
||||||
await this.putmessages();
|
await prom;
|
||||||
await prom;
|
if(id!==Channel.genid){
|
||||||
if(id!==Channel.genid){
|
return;
|
||||||
return;
|
}
|
||||||
}
|
this.buildmessages();
|
||||||
this.buildmessages();
|
history.pushState(null, "","/channels/"+this.guild_id+"/"+this.id);
|
||||||
history.pushState(null, "","/channels/"+this.guild_id+"/"+this.id);
|
this.localuser.pageTitle("@"+this.name);
|
||||||
this.localuser.pageTitle("@"+this.name);
|
(document.getElementById("channelTopic") as HTMLElement).setAttribute("hidden","");
|
||||||
(document.getElementById("channelTopic") as HTMLElement).setAttribute("hidden","");
|
(document.getElementById("typebox") as HTMLDivElement).contentEditable=""+true;
|
||||||
(document.getElementById("typebox") as HTMLDivElement).contentEditable=""+true;
|
}
|
||||||
}
|
messageCreate(messagep){
|
||||||
messageCreate(messagep){
|
const messagez=new Message(messagep.d,this);
|
||||||
const messagez=new Message(messagep.d,this);
|
if(this.lastmessageid){
|
||||||
if(this.lastmessageid){
|
this.idToNext.set(this.lastmessageid,messagez.id);
|
||||||
this.idToNext.set(this.lastmessageid,messagez.id);
|
this.idToPrev.set(messagez.id,this.lastmessageid);
|
||||||
}
|
}
|
||||||
this.idToPrev.set(messagez.id,this.lastmessageid);
|
this.lastmessageid=messagez.id;
|
||||||
this.lastmessageid=messagez.id;
|
this.messageids.set(messagez.snowflake,messagez);
|
||||||
this.messageids.set(messagez.snowflake,messagez);
|
if(messagez.author===this.localuser.user){
|
||||||
if(messagez.author===this.localuser.user){
|
this.lastreadmessageid=messagez.id;
|
||||||
this.lastreadmessageid=messagez.id;
|
if(this.myhtml){
|
||||||
if(this.myhtml){
|
this.myhtml.classList.remove("cunread");
|
||||||
this.myhtml.classList.remove("cunread");
|
}
|
||||||
}
|
}else{
|
||||||
}else{
|
if(this.myhtml){
|
||||||
if(this.myhtml){
|
this.myhtml.classList.add("cunread");
|
||||||
this.myhtml.classList.add("cunread");
|
}
|
||||||
}
|
}
|
||||||
}
|
this.unreads();
|
||||||
this.unreads();
|
this.infinite.addedBottom();
|
||||||
this.infinite.addedBottom();
|
if(messagez.author===this.localuser.user){
|
||||||
if(messagez.author===this.localuser.user){
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if(this.localuser.lookingguild?.prevchannel===this&&document.hasFocus()){
|
||||||
if(this.localuser.lookingguild?.prevchannel===this&&document.hasFocus()){
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if(this.notification==="all"){
|
||||||
if(this.notification==="all"){
|
this.notify(messagez);
|
||||||
this.notify(messagez);
|
}else if(this.notification==="mentions"&&messagez.mentionsuser(this.localuser.user)){
|
||||||
}else if(this.notification==="mentions"&&messagez.mentionsuser(this.localuser.user)){
|
this.notify(messagez);
|
||||||
this.notify(messagez);
|
}
|
||||||
}
|
}
|
||||||
}
|
notititle(message){
|
||||||
notititle(message){
|
return message.author.username;
|
||||||
return message.author.username;
|
}
|
||||||
}
|
unreads(){
|
||||||
unreads(){
|
const sentdms=document.getElementById("sentdms") as HTMLDivElement;//Need to change sometime
|
||||||
const sentdms=document.getElementById("sentdms") as HTMLDivElement;//Need to change sometime
|
let current:HTMLElement|null=null;
|
||||||
let current:HTMLElement|null=null;
|
for(const thing of sentdms.children){
|
||||||
for(const thing of sentdms.children){
|
if(thing["all"]===this){
|
||||||
if(thing["all"]===this){
|
current=thing as HTMLElement;
|
||||||
current=thing as HTMLElement;
|
}
|
||||||
}
|
}
|
||||||
}
|
if(this.hasunreads){
|
||||||
if(this.hasunreads){
|
if(current){
|
||||||
if(current){current["noti"].textContent=this.mentions;return;}
|
current["noti"].textContent=this.mentions;return;
|
||||||
const div=document.createElement("div");
|
}
|
||||||
div.classList.add("servernoti");
|
const div=document.createElement("div");
|
||||||
const noti=document.createElement("div");
|
div.classList.add("servernoti");
|
||||||
noti.classList.add("unread","notiunread","pinged");
|
const noti=document.createElement("div");
|
||||||
noti.textContent=""+this.mentions;
|
noti.classList.add("unread","notiunread","pinged");
|
||||||
div["noti"]=noti;
|
noti.textContent=""+this.mentions;
|
||||||
div.append(noti)
|
div["noti"]=noti;
|
||||||
const buildpfp=this.user.buildpfp();
|
div.append(noti);
|
||||||
div["all"]=this;
|
const buildpfp=this.user.buildpfp();
|
||||||
buildpfp.classList.add("mentioned");
|
div["all"]=this;
|
||||||
div.append(buildpfp)
|
buildpfp.classList.add("mentioned");
|
||||||
sentdms.append(div);
|
div.append(buildpfp);
|
||||||
div.onclick=_=>{
|
sentdms.append(div);
|
||||||
this.guild.loadGuild();
|
div.onclick=_=>{
|
||||||
this.getHTML();
|
this.guild.loadGuild();
|
||||||
}
|
this.getHTML();
|
||||||
}else if(current){
|
};
|
||||||
|
}else if(current){
|
||||||
|
current.remove();
|
||||||
|
}else{
|
||||||
|
|
||||||
current.remove();
|
}
|
||||||
}else{
|
}
|
||||||
|
isAdmin(): boolean{
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
isAdmin(): boolean {
|
hasPermission(name: string): boolean{
|
||||||
return false;
|
return dmPermissions.hasPermission(name);
|
||||||
}
|
}
|
||||||
hasPermission(name: string): boolean {
|
|
||||||
return dmPermissions.hasPermission(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
export {Direct, Group};
|
export{Direct, Group};
|
||||||
|
|
446
webpage/embed.ts
446
webpage/embed.ts
|
@ -1,230 +1,232 @@
|
||||||
import {Dialog} from "./dialog.js";
|
import{Dialog}from"./dialog.js";
|
||||||
import {Message} from "./message.js";
|
import{Message}from"./message.js";
|
||||||
import {MarkDown} from "./markdown.js";
|
import{MarkDown}from"./markdown.js";
|
||||||
import { embedjson } from "./jsontypes.js";
|
import{ embedjson }from"./jsontypes.js";
|
||||||
|
|
||||||
class Embed{
|
class Embed{
|
||||||
type:string;
|
type:string;
|
||||||
owner:Message;
|
owner:Message;
|
||||||
json:embedjson;
|
json:embedjson;
|
||||||
constructor(json:embedjson, owner:Message){
|
constructor(json:embedjson, owner:Message){
|
||||||
this.type=this.getType(json);
|
this.type=this.getType(json);
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.json=json;
|
this.json=json;
|
||||||
}
|
}
|
||||||
getType(json:embedjson){
|
getType(json:embedjson){
|
||||||
return json.type||"rich";
|
return json.type||"rich";
|
||||||
}
|
}
|
||||||
generateHTML(){
|
generateHTML(){
|
||||||
switch(this.type){
|
switch(this.type){
|
||||||
case "rich":
|
case"rich":
|
||||||
return this.generateRich();
|
return this.generateRich();
|
||||||
case "image":
|
case"image":
|
||||||
return this.generateImage();
|
return this.generateImage();
|
||||||
case "link":
|
case"link":
|
||||||
return this.generateLink();
|
return this.generateLink();
|
||||||
case "article":
|
case"article":
|
||||||
return this.generateArticle();
|
return this.generateArticle();
|
||||||
default:
|
default:
|
||||||
console.warn(`unsupported embed type ${this.type}, please add support dev :3`,this.json);
|
console.warn(`unsupported embed type ${this.type}, please add support dev :3`,this.json);
|
||||||
return document.createElement("div");//prevent errors by giving blank div
|
return document.createElement("div");//prevent errors by giving blank div
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get message(){
|
get message(){
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
get channel(){
|
get channel(){
|
||||||
return this.message.channel;
|
return this.message.channel;
|
||||||
}
|
}
|
||||||
get guild(){
|
get guild(){
|
||||||
return this.channel.guild;
|
return this.channel.guild;
|
||||||
}
|
}
|
||||||
get localuser(){
|
get localuser(){
|
||||||
return this.guild.localuser;
|
return this.guild.localuser;
|
||||||
}
|
}
|
||||||
generateRich(){
|
generateRich(){
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
if(this.json.color){
|
if(this.json.color){
|
||||||
div.style.backgroundColor="#"+this.json.color.toString(16);
|
div.style.backgroundColor="#"+this.json.color.toString(16);
|
||||||
}
|
}
|
||||||
div.classList.add("embed-color");
|
div.classList.add("embed-color");
|
||||||
|
|
||||||
const embed=document.createElement("div");
|
const embed=document.createElement("div");
|
||||||
embed.classList.add("embed");
|
embed.classList.add("embed");
|
||||||
div.append(embed);
|
div.append(embed);
|
||||||
|
|
||||||
if(this.json.author){
|
if(this.json.author){
|
||||||
const authorline=document.createElement("div");
|
const authorline=document.createElement("div");
|
||||||
if(this.json.author.icon_url){
|
if(this.json.author.icon_url){
|
||||||
const img=document.createElement("img");
|
const img=document.createElement("img");
|
||||||
img.classList.add("embedimg");
|
img.classList.add("embedimg");
|
||||||
img.src=this.json.author.icon_url;
|
img.src=this.json.author.icon_url;
|
||||||
authorline.append(img);
|
authorline.append(img);
|
||||||
}
|
}
|
||||||
const a=document.createElement("a");
|
const a=document.createElement("a");
|
||||||
a.textContent=this.json.author.name as string;
|
a.textContent=this.json.author.name as string;
|
||||||
if(this.json.author.url){
|
if(this.json.author.url){
|
||||||
a.href=this.json.author.url
|
a.href=this.json.author.url;
|
||||||
}
|
}
|
||||||
a.classList.add("username")
|
a.classList.add("username");
|
||||||
authorline.append(a);
|
authorline.append(a);
|
||||||
embed.append(authorline);
|
embed.append(authorline);
|
||||||
}
|
}
|
||||||
if(this.json.title){
|
if(this.json.title){
|
||||||
const title=document.createElement("a");
|
const title=document.createElement("a");
|
||||||
title.append(new MarkDown(this.json.title,this.channel).makeHTML());
|
title.append(new MarkDown(this.json.title,this.channel).makeHTML());
|
||||||
if(this.json.url){
|
if(this.json.url){
|
||||||
title.href=this.json.url;
|
title.href=this.json.url;
|
||||||
}
|
}
|
||||||
title.classList.add("embedtitle");
|
title.classList.add("embedtitle");
|
||||||
embed.append(title);
|
embed.append(title);
|
||||||
}
|
}
|
||||||
if(this.json.description){
|
if(this.json.description){
|
||||||
const p=document.createElement("p");
|
const p=document.createElement("p");
|
||||||
p.append(new MarkDown(this.json.description,this.channel).makeHTML());
|
p.append(new MarkDown(this.json.description,this.channel).makeHTML());
|
||||||
embed.append(p);
|
embed.append(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
embed.append(document.createElement("br"));
|
embed.append(document.createElement("br"));
|
||||||
if(this.json.fields){
|
if(this.json.fields){
|
||||||
for(const thing of this.json.fields){
|
for(const thing of this.json.fields){
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
const b=document.createElement("b");
|
const b=document.createElement("b");
|
||||||
b.textContent=thing.name;
|
b.textContent=thing.name;
|
||||||
div.append(b);
|
div.append(b);
|
||||||
const p=document.createElement("p")
|
const p=document.createElement("p");
|
||||||
p.append(new MarkDown(thing.value,this.channel).makeHTML());
|
p.append(new MarkDown(thing.value,this.channel).makeHTML());
|
||||||
p.classList.add("embedp");
|
p.classList.add("embedp");
|
||||||
div.append(p);
|
div.append(p);
|
||||||
|
|
||||||
if(thing.inline){div.classList.add("inline");}
|
if(thing.inline){
|
||||||
embed.append(div);
|
div.classList.add("inline");
|
||||||
}
|
}
|
||||||
}
|
embed.append(div);
|
||||||
if(this.json.footer||this.json.timestamp){
|
}
|
||||||
const footer=document.createElement("div");
|
}
|
||||||
if(this.json?.footer?.icon_url){
|
if(this.json.footer||this.json.timestamp){
|
||||||
const img=document.createElement("img");
|
const footer=document.createElement("div");
|
||||||
img.src=this.json.footer.icon_url;
|
if(this.json?.footer?.icon_url){
|
||||||
img.classList.add("embedicon");
|
const img=document.createElement("img");
|
||||||
footer.append(img);
|
img.src=this.json.footer.icon_url;
|
||||||
}
|
img.classList.add("embedicon");
|
||||||
if(this.json?.footer?.text){
|
footer.append(img);
|
||||||
const span=document.createElement("span");
|
}
|
||||||
span.textContent=this.json.footer.text;
|
if(this.json?.footer?.text){
|
||||||
span.classList.add("spaceright");
|
const span=document.createElement("span");
|
||||||
footer.append(span);
|
span.textContent=this.json.footer.text;
|
||||||
}
|
span.classList.add("spaceright");
|
||||||
if(this.json?.footer&&this.json?.timestamp){
|
footer.append(span);
|
||||||
const span=document.createElement("span");
|
}
|
||||||
span.textContent="•";
|
if(this.json?.footer&&this.json?.timestamp){
|
||||||
span.classList.add("spaceright");
|
const span=document.createElement("span");
|
||||||
footer.append(span);
|
span.textContent="•";
|
||||||
}
|
span.classList.add("spaceright");
|
||||||
if(this.json?.timestamp){
|
footer.append(span);
|
||||||
const span=document.createElement("span")
|
}
|
||||||
span.textContent=new Date(this.json.timestamp).toLocaleString();;
|
if(this.json?.timestamp){
|
||||||
footer.append(span);
|
const span=document.createElement("span");
|
||||||
}
|
span.textContent=new Date(this.json.timestamp).toLocaleString();
|
||||||
embed.append(footer);
|
footer.append(span);
|
||||||
}
|
}
|
||||||
return div;
|
embed.append(footer);
|
||||||
}
|
}
|
||||||
generateImage(){
|
return div;
|
||||||
const img=document.createElement("img");
|
}
|
||||||
img.classList.add("messageimg")
|
generateImage(){
|
||||||
img.onclick=function(){
|
const img=document.createElement("img");
|
||||||
const full=new Dialog(["img",img.src,["fit"]]);
|
img.classList.add("messageimg");
|
||||||
full.show();
|
img.onclick=function(){
|
||||||
}
|
const full=new Dialog(["img",img.src,["fit"]]);
|
||||||
img.src=this.json.thumbnail.proxy_url;
|
full.show();
|
||||||
if(this.json.thumbnail.width){
|
};
|
||||||
let scale=1;
|
img.src=this.json.thumbnail.proxy_url;
|
||||||
const max=96*3;
|
if(this.json.thumbnail.width){
|
||||||
scale=Math.max(scale,this.json.thumbnail.width/max);
|
let scale=1;
|
||||||
scale=Math.max(scale,this.json.thumbnail.height/max);
|
const max=96*3;
|
||||||
this.json.thumbnail.width/=scale;
|
scale=Math.max(scale,this.json.thumbnail.width/max);
|
||||||
this.json.thumbnail.height/=scale;
|
scale=Math.max(scale,this.json.thumbnail.height/max);
|
||||||
}
|
this.json.thumbnail.width/=scale;
|
||||||
img.style.width=this.json.thumbnail.width+"px";
|
this.json.thumbnail.height/=scale;
|
||||||
img.style.height=this.json.thumbnail.height+"px";
|
}
|
||||||
console.log(this.json,"Image fix");
|
img.style.width=this.json.thumbnail.width+"px";
|
||||||
return img;
|
img.style.height=this.json.thumbnail.height+"px";
|
||||||
}
|
console.log(this.json,"Image fix");
|
||||||
generateLink(){
|
return img;
|
||||||
const table=document.createElement("table");
|
}
|
||||||
table.classList.add("embed","linkembed");
|
generateLink(){
|
||||||
const trtop=document.createElement("tr");
|
const table=document.createElement("table");
|
||||||
table.append(trtop);
|
table.classList.add("embed","linkembed");
|
||||||
if(this.json.url&&this.json.title){
|
const trtop=document.createElement("tr");
|
||||||
const td=document.createElement("td");
|
table.append(trtop);
|
||||||
const a=document.createElement("a");
|
if(this.json.url&&this.json.title){
|
||||||
a.href=this.json.url;
|
const td=document.createElement("td");
|
||||||
a.textContent=this.json.title;
|
const a=document.createElement("a");
|
||||||
td.append(a);
|
a.href=this.json.url;
|
||||||
trtop.append(td);
|
a.textContent=this.json.title;
|
||||||
}
|
td.append(a);
|
||||||
{
|
trtop.append(td);
|
||||||
const td=document.createElement("td");
|
}
|
||||||
const img=document.createElement("img");
|
{
|
||||||
if(this.json.thumbnail){
|
const td=document.createElement("td");
|
||||||
img.classList.add("embedimg");
|
const img=document.createElement("img");
|
||||||
img.onclick=function(){
|
if(this.json.thumbnail){
|
||||||
const full=new Dialog(["img",img.src,["fit"]]);
|
img.classList.add("embedimg");
|
||||||
full.show();
|
img.onclick=function(){
|
||||||
}
|
const full=new Dialog(["img",img.src,["fit"]]);
|
||||||
img.src=this.json.thumbnail.proxy_url;
|
full.show();
|
||||||
td.append(img);
|
};
|
||||||
}
|
img.src=this.json.thumbnail.proxy_url;
|
||||||
trtop.append(td);
|
td.append(img);
|
||||||
}
|
}
|
||||||
const bottomtr=document.createElement("tr");
|
trtop.append(td);
|
||||||
const td=document.createElement("td");
|
}
|
||||||
if(this.json.description){
|
const bottomtr=document.createElement("tr");
|
||||||
const span=document.createElement("span");
|
const td=document.createElement("td");
|
||||||
span.textContent=this.json.description;
|
if(this.json.description){
|
||||||
td.append(span);
|
const span=document.createElement("span");
|
||||||
}
|
span.textContent=this.json.description;
|
||||||
bottomtr.append(td);
|
td.append(span);
|
||||||
table.append(bottomtr)
|
}
|
||||||
return table;
|
bottomtr.append(td);
|
||||||
}
|
table.append(bottomtr);
|
||||||
generateArticle(){
|
return table;
|
||||||
const colordiv=document.createElement("div");
|
}
|
||||||
colordiv.style.backgroundColor="#000000";
|
generateArticle(){
|
||||||
colordiv.classList.add("embed-color");
|
const colordiv=document.createElement("div");
|
||||||
|
colordiv.style.backgroundColor="#000000";
|
||||||
|
colordiv.classList.add("embed-color");
|
||||||
|
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
div.classList.add("embed");
|
div.classList.add("embed");
|
||||||
if(this.json.provider){
|
if(this.json.provider){
|
||||||
const provider=document.createElement("p");
|
const provider=document.createElement("p");
|
||||||
provider.classList.add("provider");
|
provider.classList.add("provider");
|
||||||
provider.textContent=this.json.provider.name;
|
provider.textContent=this.json.provider.name;
|
||||||
div.append(provider);
|
div.append(provider);
|
||||||
}
|
}
|
||||||
const a=document.createElement("a");
|
const a=document.createElement("a");
|
||||||
if(this.json.url&&this.json.url){
|
if(this.json.url&&this.json.url){
|
||||||
a.href=this.json.url;
|
a.href=this.json.url;
|
||||||
a.textContent=this.json.url;
|
a.textContent=this.json.url;
|
||||||
div.append(a);
|
div.append(a);
|
||||||
}
|
}
|
||||||
if(this.json.description){
|
if(this.json.description){
|
||||||
const description=document.createElement("p");
|
const description=document.createElement("p");
|
||||||
description.textContent=this.json.description;
|
description.textContent=this.json.description;
|
||||||
div.append(description);
|
div.append(description);
|
||||||
}
|
}
|
||||||
if(this.json.thumbnail){
|
if(this.json.thumbnail){
|
||||||
const img=document.createElement("img");
|
const img=document.createElement("img");
|
||||||
img.classList.add("bigembedimg");
|
img.classList.add("bigembedimg");
|
||||||
img.onclick=function(){
|
img.onclick=function(){
|
||||||
const full=new Dialog(["img",img.src,["fit"]]);
|
const full=new Dialog(["img",img.src,["fit"]]);
|
||||||
full.show();
|
full.show();
|
||||||
}
|
};
|
||||||
img.src=this.json.thumbnail.proxy_url||this.json.thumbnail.url;
|
img.src=this.json.thumbnail.proxy_url||this.json.thumbnail.url;
|
||||||
div.append(img);
|
div.append(img);
|
||||||
}
|
}
|
||||||
colordiv.append(div);
|
colordiv.append(div);
|
||||||
return colordiv;
|
return colordiv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export {Embed};
|
export{Embed};
|
||||||
|
|
396
webpage/emoji.ts
396
webpage/emoji.ts
|
@ -1,226 +1,226 @@
|
||||||
import { Contextmenu } from "./contextmenu.js";
|
import{ Contextmenu }from"./contextmenu.js";
|
||||||
import { Guild } from "./guild.js";
|
import{ Guild }from"./guild.js";
|
||||||
import { emojijson } from "./jsontypes.js";
|
import{ emojijson }from"./jsontypes.js";
|
||||||
import { Localuser } from "./localuser.js";
|
import{ Localuser }from"./localuser.js";
|
||||||
|
|
||||||
class Emoji{
|
class Emoji{
|
||||||
static emojis:{
|
static emojis:{
|
||||||
name:string,
|
name:string,
|
||||||
emojis:{
|
emojis:{
|
||||||
name:string,
|
name:string,
|
||||||
emoji:string,
|
emoji:string,
|
||||||
}[]
|
}[]
|
||||||
}[];
|
}[];
|
||||||
name:string;
|
name:string;
|
||||||
id:string;
|
id:string;
|
||||||
animated:boolean;
|
animated:boolean;
|
||||||
owner:Guild|Localuser;
|
owner:Guild|Localuser;
|
||||||
get guild(){
|
get guild(){
|
||||||
if(this.owner instanceof Guild){
|
if(this.owner instanceof Guild){
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get localuser(){
|
get localuser(){
|
||||||
if(this.owner instanceof Guild){
|
if(this.owner instanceof Guild){
|
||||||
return this.owner.localuser;
|
return this.owner.localuser;
|
||||||
}else{
|
}else{
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get info(){
|
get info(){
|
||||||
return this.owner.info;
|
return this.owner.info;
|
||||||
}
|
}
|
||||||
constructor(json:{name:string,id:string,animated:boolean},owner:Guild|Localuser){
|
constructor(json:{name:string,id:string,animated:boolean},owner:Guild|Localuser){
|
||||||
this.name=json.name;
|
this.name=json.name;
|
||||||
this.id=json.id;
|
this.id=json.id;
|
||||||
this.animated=json.animated
|
this.animated=json.animated;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
}
|
}
|
||||||
getHTML(bigemoji:boolean=false){
|
getHTML(bigemoji:boolean=false){
|
||||||
const emojiElem=document.createElement("img");
|
const emojiElem=document.createElement("img");
|
||||||
emojiElem.classList.add("md-emoji");
|
emojiElem.classList.add("md-emoji");
|
||||||
emojiElem.classList.add(bigemoji ? "bigemoji" : "smallemoji");
|
emojiElem.classList.add(bigemoji ? "bigemoji" : "smallemoji");
|
||||||
emojiElem.crossOrigin="anonymous";
|
emojiElem.crossOrigin="anonymous";
|
||||||
emojiElem.src=this.info.cdn + "/emojis/" + this.id + "." + (this.animated ? "gif" : "png") + "?size=32";
|
emojiElem.src=this.info.cdn + "/emojis/" + this.id + "." + (this.animated ? "gif" : "png") + "?size=32";
|
||||||
|
|
||||||
emojiElem.alt=this.name;
|
emojiElem.alt=this.name;
|
||||||
emojiElem.loading="lazy";
|
emojiElem.loading="lazy";
|
||||||
return emojiElem;
|
return emojiElem;
|
||||||
}
|
}
|
||||||
static decodeEmojiList(buffer:ArrayBuffer){
|
static decodeEmojiList(buffer:ArrayBuffer){
|
||||||
const view = new DataView(buffer, 0);
|
const view = new DataView(buffer, 0);
|
||||||
let i=0;
|
let i=0;
|
||||||
function read16(){
|
function read16(){
|
||||||
const int=view.getUint16(i);
|
const int=view.getUint16(i);
|
||||||
i+=2;
|
i+=2;
|
||||||
return int;
|
return int;
|
||||||
}
|
}
|
||||||
function read8(){
|
function read8(){
|
||||||
const int=view.getUint8(i);
|
const int=view.getUint8(i);
|
||||||
i+=1;
|
i+=1;
|
||||||
return int;
|
return int;
|
||||||
}
|
}
|
||||||
function readString8(){
|
function readString8(){
|
||||||
return readStringNo(read8());
|
return readStringNo(read8());
|
||||||
}
|
}
|
||||||
function readString16(){
|
function readString16(){
|
||||||
return readStringNo(read16());
|
return readStringNo(read16());
|
||||||
}
|
}
|
||||||
function readStringNo(length:number){
|
function readStringNo(length:number){
|
||||||
const array=new Uint8Array(length);
|
const array=new Uint8Array(length);
|
||||||
|
|
||||||
for(let i=0;i<length;i++){
|
for(let i=0;i<length;i++){
|
||||||
array[i]=read8();
|
array[i]=read8();
|
||||||
}
|
}
|
||||||
const decoded=new TextDecoder("utf-8").decode(array.buffer);;
|
//console.log(array);
|
||||||
|
return new TextDecoder("utf-8").decode(array.buffer);
|
||||||
|
}
|
||||||
|
const build:{name:string,emojis:{name:string,emoji:string}[]}[]=[];
|
||||||
|
let cats=read16();
|
||||||
|
|
||||||
//console.log(array);
|
for(;cats!==0;cats--){
|
||||||
return decoded;
|
const name=readString16();
|
||||||
}
|
const emojis:{
|
||||||
const build:{name:string,emojis:{name:string,emoji:string}[]}[]=[];
|
|
||||||
let cats=read16();
|
|
||||||
|
|
||||||
for(;cats!==0;cats--){
|
|
||||||
const name=readString16();
|
|
||||||
const emojis:{
|
|
||||||
name:string,
|
name:string,
|
||||||
skin_tone_support:boolean,
|
skin_tone_support:boolean,
|
||||||
emoji:string
|
emoji:string
|
||||||
}[]=[];
|
}[]=[];
|
||||||
let emojinumber=read16();
|
let emojinumber=read16();
|
||||||
for(;emojinumber!==0;emojinumber--){
|
for(;emojinumber!==0;emojinumber--){
|
||||||
//console.log(emojis);
|
//console.log(emojis);
|
||||||
const name=readString8();
|
const name=readString8();
|
||||||
const len=read8();
|
const len=read8();
|
||||||
const skin_tone_support=len>127;
|
const skin_tone_support=len>127;
|
||||||
const emoji=readStringNo(len-(+skin_tone_support*128));
|
const emoji=readStringNo(len-(Number(skin_tone_support)*128));
|
||||||
emojis.push({
|
emojis.push({
|
||||||
name,
|
name,
|
||||||
skin_tone_support,
|
skin_tone_support,
|
||||||
emoji
|
emoji
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
build.push({
|
build.push({
|
||||||
name,
|
name,
|
||||||
emojis
|
emojis
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
this.emojis=build;
|
this.emojis=build;
|
||||||
console.log(build);
|
console.log(build);
|
||||||
}
|
}
|
||||||
static grabEmoji(){
|
static grabEmoji(){
|
||||||
fetch("/emoji.bin").then(e=>{
|
fetch("/emoji.bin").then(e=>{
|
||||||
return e.arrayBuffer()
|
return e.arrayBuffer();
|
||||||
}).then(e=>{
|
}).then(e=>{
|
||||||
Emoji.decodeEmojiList(e);
|
Emoji.decodeEmojiList(e);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
static async emojiPicker(x:number,y:number, localuser:Localuser):Promise<Emoji|string>{
|
static async emojiPicker(x:number,y:number, localuser:Localuser):Promise<Emoji|string>{
|
||||||
let res:(r:Emoji|string)=>void;
|
let res:(r:Emoji|string)=>void;
|
||||||
const promise:Promise<Emoji|string>=new Promise((r)=>{res=r;})
|
const promise:Promise<Emoji|string>=new Promise(r=>{
|
||||||
const menu=document.createElement("div");
|
res=r;
|
||||||
menu.classList.add("flextttb", "emojiPicker")
|
});
|
||||||
menu.style.top=y+"px";
|
const menu=document.createElement("div");
|
||||||
menu.style.left=x+"px";
|
menu.classList.add("flextttb", "emojiPicker");
|
||||||
|
menu.style.top=y+"px";
|
||||||
|
menu.style.left=x+"px";
|
||||||
|
|
||||||
const title=document.createElement("h2");
|
const title=document.createElement("h2");
|
||||||
title.textContent=Emoji.emojis[0].name;
|
title.textContent=Emoji.emojis[0].name;
|
||||||
title.classList.add("emojiTitle");
|
title.classList.add("emojiTitle");
|
||||||
menu.append(title);
|
menu.append(title);
|
||||||
const selection=document.createElement("div");
|
const selection=document.createElement("div");
|
||||||
selection.classList.add("flexltr","dontshrink","emojirow");
|
selection.classList.add("flexltr","dontshrink","emojirow");
|
||||||
const body=document.createElement("div");
|
const body=document.createElement("div");
|
||||||
body.classList.add("emojiBody");
|
body.classList.add("emojiBody");
|
||||||
|
|
||||||
let isFirst = true;
|
let isFirst = true;
|
||||||
localuser.guilds.filter(guild => guild.id != "@me" && guild.emojis.length > 0).forEach(guild => {
|
localuser.guilds.filter(guild=>guild.id != "@me" && guild.emojis.length > 0).forEach(guild=>{
|
||||||
const select = document.createElement("div")
|
const select = document.createElement("div");
|
||||||
select.classList.add("emojiSelect")
|
select.classList.add("emojiSelect");
|
||||||
|
|
||||||
if (guild.properties.icon) {
|
if(guild.properties.icon){
|
||||||
const img = document.createElement("img")
|
const img = document.createElement("img");
|
||||||
img.classList.add("pfp", "servericon", "emoji-server")
|
img.classList.add("pfp", "servericon", "emoji-server");
|
||||||
img.crossOrigin = "anonymous"
|
img.crossOrigin = "anonymous";
|
||||||
img.src = localuser.info.cdn + "/icons/" + guild.properties.id + "/" + guild.properties.icon + ".png?size=48"
|
img.src = localuser.info.cdn + "/icons/" + guild.properties.id + "/" + guild.properties.icon + ".png?size=48";
|
||||||
img.alt = "Server: " + guild.properties.name
|
img.alt = "Server: " + guild.properties.name;
|
||||||
select.appendChild(img)
|
select.appendChild(img);
|
||||||
} else {
|
}else{
|
||||||
const div = document.createElement("span")
|
const div = document.createElement("span");
|
||||||
div.textContent = guild.properties.name.replace(/'s /g, " ").replace(/\w+/g, word => word[0]).replace(/\s/g, "")
|
div.textContent = guild.properties.name.replace(/'s /g, " ").replace(/\w+/g, word=>word[0]).replace(/\s/g, "");
|
||||||
select.append(div)
|
select.append(div);
|
||||||
}
|
}
|
||||||
|
|
||||||
selection.append(select)
|
selection.append(select);
|
||||||
|
|
||||||
const clickEvent = () => {
|
const clickEvent = ()=>{
|
||||||
title.textContent = guild.properties.name
|
title.textContent = guild.properties.name;
|
||||||
body.innerHTML = ""
|
body.innerHTML = "";
|
||||||
for (const emojit of guild.emojis) {
|
for(const emojit of guild.emojis){
|
||||||
const emojiElem = document.createElement("div")
|
const emojiElem = document.createElement("div");
|
||||||
emojiElem.classList.add("emojiSelect")
|
emojiElem.classList.add("emojiSelect");
|
||||||
|
|
||||||
const emojiClass = new Emoji({
|
const emojiClass = new Emoji({
|
||||||
id: emojit.id as string,
|
id: emojit.id as string,
|
||||||
name: emojit.name,
|
name: emojit.name,
|
||||||
animated: emojit.animated as boolean
|
animated: emojit.animated as boolean
|
||||||
},localuser)
|
},localuser);
|
||||||
emojiElem.append(emojiClass.getHTML())
|
emojiElem.append(emojiClass.getHTML());
|
||||||
body.append(emojiElem)
|
body.append(emojiElem);
|
||||||
|
|
||||||
emojiElem.addEventListener("click", () => {
|
emojiElem.addEventListener("click", ()=>{
|
||||||
res(emojiClass)
|
res(emojiClass);
|
||||||
Contextmenu.currentmenu.remove()
|
Contextmenu.currentmenu.remove();
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
select.addEventListener("click", clickEvent)
|
select.addEventListener("click", clickEvent);
|
||||||
if (isFirst) {
|
if(isFirst){
|
||||||
clickEvent()
|
clickEvent();
|
||||||
isFirst = false
|
isFirst = false;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
if(Contextmenu.currentmenu!=""){
|
if(Contextmenu.currentmenu!=""){
|
||||||
Contextmenu.currentmenu.remove();
|
Contextmenu.currentmenu.remove();
|
||||||
}
|
}
|
||||||
document.body.append(menu);
|
document.body.append(menu);
|
||||||
Contextmenu.currentmenu=menu;
|
Contextmenu.currentmenu=menu;
|
||||||
Contextmenu.keepOnScreen(menu);
|
Contextmenu.keepOnScreen(menu);
|
||||||
},10)
|
},10);
|
||||||
|
|
||||||
|
|
||||||
let i=0;
|
let i=0;
|
||||||
for(const thing of Emoji.emojis){
|
for(const thing of Emoji.emojis){
|
||||||
const select=document.createElement("div");
|
const select=document.createElement("div");
|
||||||
select.textContent=thing.emojis[0].emoji;
|
select.textContent=thing.emojis[0].emoji;
|
||||||
select.classList.add("emojiSelect");
|
select.classList.add("emojiSelect");
|
||||||
selection.append(select);
|
selection.append(select);
|
||||||
const clickEvent=()=>{
|
const clickEvent=()=>{
|
||||||
title.textContent=thing.name;
|
title.textContent=thing.name;
|
||||||
body.innerHTML="";
|
body.innerHTML="";
|
||||||
for(const emojit of thing.emojis){
|
for(const emojit of thing.emojis){
|
||||||
const emoji=document.createElement("div");
|
const emoji=document.createElement("div");
|
||||||
emoji.classList.add("emojiSelect");
|
emoji.classList.add("emojiSelect");
|
||||||
emoji.textContent=emojit.emoji;
|
emoji.textContent=emojit.emoji;
|
||||||
body.append(emoji);
|
body.append(emoji);
|
||||||
emoji.onclick=_=>{
|
emoji.onclick=_=>{
|
||||||
res(emojit.emoji);
|
res(emojit.emoji);
|
||||||
Contextmenu.currentmenu.remove();
|
Contextmenu.currentmenu.remove();
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
select.onclick=clickEvent
|
select.onclick=clickEvent;
|
||||||
if(i===0){
|
if(i===0){
|
||||||
clickEvent();
|
clickEvent();
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
menu.append(selection);
|
menu.append(selection);
|
||||||
menu.append(body);
|
menu.append(body);
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Emoji.grabEmoji();
|
Emoji.grabEmoji();
|
||||||
export {Emoji};
|
export{Emoji};
|
||||||
|
|
282
webpage/file.ts
282
webpage/file.ts
|
@ -1,145 +1,145 @@
|
||||||
import { Message } from "./message.js";
|
import{ Message }from"./message.js";
|
||||||
import { Dialog } from "./dialog.js";
|
import{ Dialog }from"./dialog.js";
|
||||||
import { filejson } from "./jsontypes.js";
|
import{ filejson }from"./jsontypes.js";
|
||||||
|
|
||||||
class File{
|
class File{
|
||||||
owner:Message|null;
|
owner:Message|null;
|
||||||
id:string;
|
id:string;
|
||||||
filename:string;
|
filename:string;
|
||||||
content_type:string;
|
content_type:string;
|
||||||
width:number|undefined;
|
width:number|undefined;
|
||||||
height:number|undefined;
|
height:number|undefined;
|
||||||
proxy_url:string|undefined;
|
proxy_url:string|undefined;
|
||||||
url:string;
|
url:string;
|
||||||
size:number;
|
size:number;
|
||||||
constructor(fileJSON:filejson,owner:Message|null){
|
constructor(fileJSON:filejson,owner:Message|null){
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.id=fileJSON.id;
|
this.id=fileJSON.id;
|
||||||
this.filename=fileJSON.filename;
|
this.filename=fileJSON.filename;
|
||||||
this.content_type=fileJSON.content_type;
|
this.content_type=fileJSON.content_type;
|
||||||
this.width=fileJSON.width;
|
this.width=fileJSON.width;
|
||||||
this.height=fileJSON.height;
|
this.height=fileJSON.height;
|
||||||
this.url=fileJSON.url;
|
this.url=fileJSON.url;
|
||||||
this.proxy_url=fileJSON.proxy_url;
|
this.proxy_url=fileJSON.proxy_url;
|
||||||
this.content_type=fileJSON.content_type;
|
this.content_type=fileJSON.content_type;
|
||||||
this.size=fileJSON.size;
|
this.size=fileJSON.size;
|
||||||
}
|
}
|
||||||
getHTML(temp:boolean=false):HTMLElement{
|
getHTML(temp:boolean=false):HTMLElement{
|
||||||
const src=this.proxy_url||this.url;
|
const src=this.proxy_url||this.url;
|
||||||
if(this.width&&this.height){
|
if(this.width&&this.height){
|
||||||
let scale=1;
|
let scale=1;
|
||||||
const max=96*3;
|
const max=96*3;
|
||||||
scale=Math.max(scale,this.width/max);
|
scale=Math.max(scale,this.width/max);
|
||||||
scale=Math.max(scale,this.height/max);
|
scale=Math.max(scale,this.height/max);
|
||||||
this.width/=scale;
|
this.width/=scale;
|
||||||
this.height/=scale;
|
this.height/=scale;
|
||||||
}
|
}
|
||||||
if(this.content_type.startsWith('image/')){
|
if(this.content_type.startsWith("image/")){
|
||||||
const div=document.createElement("div")
|
const div=document.createElement("div");
|
||||||
const img=document.createElement("img");
|
const img=document.createElement("img");
|
||||||
img.classList.add("messageimg");
|
img.classList.add("messageimg");
|
||||||
div.classList.add("messageimgdiv")
|
div.classList.add("messageimgdiv");
|
||||||
img.onclick=function(){
|
img.onclick=function(){
|
||||||
const full=new Dialog(["img",img.src,["fit"]]);
|
const full=new Dialog(["img",img.src,["fit"]]);
|
||||||
full.show();
|
full.show();
|
||||||
}
|
};
|
||||||
img.src=src;
|
img.src=src;
|
||||||
div.append(img)
|
div.append(img);
|
||||||
if(this.width){
|
if(this.width){
|
||||||
div.style.width=this.width+"px";
|
div.style.width=this.width+"px";
|
||||||
div.style.height=this.height+"px";
|
div.style.height=this.height+"px";
|
||||||
}
|
}
|
||||||
console.log(img);
|
console.log(img);
|
||||||
console.log(this.width,this.height)
|
console.log(this.width,this.height);
|
||||||
return div;
|
return div;
|
||||||
}else if(this.content_type.startsWith('video/')){
|
}else if(this.content_type.startsWith("video/")){
|
||||||
const video=document.createElement("video");
|
const video=document.createElement("video");
|
||||||
const source=document.createElement("source");
|
const source=document.createElement("source");
|
||||||
source.src=src;
|
source.src=src;
|
||||||
video.append(source);
|
video.append(source);
|
||||||
source.type=this.content_type;
|
source.type=this.content_type;
|
||||||
video.controls=!temp;
|
video.controls=!temp;
|
||||||
if(this.width&&this.height){
|
if(this.width&&this.height){
|
||||||
video.width=this.width;
|
video.width=this.width;
|
||||||
video.height=this.height;
|
video.height=this.height;
|
||||||
}
|
}
|
||||||
return video;
|
return video;
|
||||||
}else if(this.content_type.startsWith('audio/')){
|
}else if(this.content_type.startsWith("audio/")){
|
||||||
const audio=document.createElement("audio");
|
const audio=document.createElement("audio");
|
||||||
const source=document.createElement("source");
|
const source=document.createElement("source");
|
||||||
source.src=src;
|
source.src=src;
|
||||||
audio.append(source);
|
audio.append(source);
|
||||||
source.type=this.content_type;
|
source.type=this.content_type;
|
||||||
audio.controls=!temp;
|
audio.controls=!temp;
|
||||||
return audio;
|
return audio;
|
||||||
}else{
|
}else{
|
||||||
return this.createunknown();
|
return this.createunknown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
upHTML(files:Blob[],file:globalThis.File):HTMLElement{
|
upHTML(files:Blob[],file:globalThis.File):HTMLElement{
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
const contained=this.getHTML(true);
|
const contained=this.getHTML(true);
|
||||||
div.classList.add("containedFile");
|
div.classList.add("containedFile");
|
||||||
div.append(contained);
|
div.append(contained);
|
||||||
const controls=document.createElement("div");
|
const controls=document.createElement("div");
|
||||||
const garbage=document.createElement("button");
|
const garbage=document.createElement("button");
|
||||||
garbage.textContent="🗑";
|
garbage.textContent="🗑";
|
||||||
garbage.onclick=_=>{
|
garbage.onclick=_=>{
|
||||||
div.remove();
|
div.remove();
|
||||||
files.splice(files.indexOf(file),1);
|
files.splice(files.indexOf(file),1);
|
||||||
}
|
};
|
||||||
controls.classList.add("controls");
|
controls.classList.add("controls");
|
||||||
div.append(controls);
|
div.append(controls);
|
||||||
controls.append(garbage);
|
controls.append(garbage);
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
static initFromBlob(file:globalThis.File){
|
static initFromBlob(file:globalThis.File){
|
||||||
return new File({
|
return new File({
|
||||||
filename:file.name,
|
filename: file.name,
|
||||||
size:file.size,
|
size: file.size,
|
||||||
id:"null",
|
id: "null",
|
||||||
content_type:file.type,
|
content_type: file.type,
|
||||||
width:undefined,
|
width: undefined,
|
||||||
height:undefined,
|
height: undefined,
|
||||||
url:URL.createObjectURL(file),
|
url: URL.createObjectURL(file),
|
||||||
proxy_url:undefined
|
proxy_url: undefined
|
||||||
},null)
|
},null);
|
||||||
}
|
}
|
||||||
createunknown():HTMLElement{
|
createunknown():HTMLElement{
|
||||||
console.log("🗎")
|
console.log("🗎");
|
||||||
const src=this.proxy_url||this.url;
|
const src=this.proxy_url||this.url;
|
||||||
const div=document.createElement("table");
|
const div=document.createElement("table");
|
||||||
div.classList.add("unknownfile");
|
div.classList.add("unknownfile");
|
||||||
const nametr=document.createElement("tr");
|
const nametr=document.createElement("tr");
|
||||||
div.append(nametr);
|
div.append(nametr);
|
||||||
const fileicon=document.createElement("td");
|
const fileicon=document.createElement("td");
|
||||||
nametr.append(fileicon);
|
nametr.append(fileicon);
|
||||||
fileicon.append("🗎");
|
fileicon.append("🗎");
|
||||||
fileicon.classList.add("fileicon");
|
fileicon.classList.add("fileicon");
|
||||||
fileicon.rowSpan=2;
|
fileicon.rowSpan=2;
|
||||||
const nametd=document.createElement("td");
|
const nametd=document.createElement("td");
|
||||||
if(src){
|
if(src){
|
||||||
const a=document.createElement("a");
|
const a=document.createElement("a");
|
||||||
a.href=src;
|
a.href=src;
|
||||||
a.textContent=this.filename;
|
a.textContent=this.filename;
|
||||||
nametd.append(a);
|
nametd.append(a);
|
||||||
}else{
|
}else{
|
||||||
nametd.textContent=this.filename;
|
nametd.textContent=this.filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
nametd.classList.add("filename");
|
nametd.classList.add("filename");
|
||||||
nametr.append(nametd);
|
nametr.append(nametd);
|
||||||
const sizetr=document.createElement("tr");
|
const sizetr=document.createElement("tr");
|
||||||
const size=document.createElement("td");
|
const size=document.createElement("td");
|
||||||
sizetr.append(size);
|
sizetr.append(size);
|
||||||
size.textContent="Size:"+File.filesizehuman(this.size);
|
size.textContent="Size:"+File.filesizehuman(this.size);
|
||||||
size.classList.add("filesize");
|
size.classList.add("filesize");
|
||||||
div.appendChild(sizetr);
|
div.appendChild(sizetr);
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
static filesizehuman(fsize:number){
|
static filesizehuman(fsize:number){
|
||||||
var i = fsize == 0 ? 0 : Math.floor(Math.log(fsize) / Math.log(1024));
|
const i = fsize == 0 ? 0 : Math.floor(Math.log(fsize) / Math.log(1024));
|
||||||
return +((fsize / Math.pow(1024, i)).toFixed(2)) * 1 + ' ' + ['Bytes', 'Kilobytes', 'Megabytes', 'Gigabytes', 'Terabytes'][i];
|
return Number((fsize / Math.pow(1024, i)).toFixed(2)) * 1 + " " + ["Bytes", "Kilobytes", "Megabytes", "Gigabytes", "Terabytes"][i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export{File}
|
export{File};
|
||||||
|
|
1057
webpage/guild.ts
1057
webpage/guild.ts
File diff suppressed because it is too large
Load diff
|
@ -1,48 +1,48 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Jank Client</title>
|
<title>Jank Client</title>
|
||||||
<meta content="Jank Client" property="og:title" />
|
<meta content="Jank Client" property="og:title">
|
||||||
<meta content="A spacebar client that has DMs, replying and more" property="og:description" />
|
<meta content="A spacebar client that has DMs, replying and more" property="og:description">
|
||||||
<meta content="/logo.webp" property="og:image" />
|
<meta content="/logo.webp" property="og:image">
|
||||||
<meta content="#4b458c" data-react-helmet="true" name="theme-color" />
|
<meta content="#4b458c" data-react-helmet="true" name="theme-color">
|
||||||
<link href="/style.css" rel="stylesheet" type="text/css" />
|
<link href="/style.css" rel="stylesheet">
|
||||||
<link href="/themes.css" rel="stylesheet" type="text/css" id="lightcss"/>
|
<link href="/themes.css" rel="stylesheet" id="lightcss">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="Dark-theme">
|
<body class="Dark-theme">
|
||||||
<div id="titleDiv">
|
<div id="titleDiv">
|
||||||
<img src="/logo.svg" width="40">
|
<img src="/logo.svg" width="40">
|
||||||
<h1 id="pageTitle">Jank Client</h1>
|
<h1 id="pageTitle">Jank Client</h1>
|
||||||
<a href="https://sb-jankclient.vanillaminigames.net/invite/USgYJo?instance=https%3A%2F%2Fspacebar.chat" class="TitleButtons"><h1>Spacebar Guild</h1></a>
|
<a href="https://sb-jankclient.vanillaminigames.net/invite/USgYJo?instance=https%3A%2F%2Fspacebar.chat" class="TitleButtons"><h1>Spacebar Guild</h1></a>
|
||||||
<a href="https://github.com/MathMan05/JankClient" class="TitleButtons"><h1>Github</h1></a>
|
<a href="https://github.com/MathMan05/JankClient" class="TitleButtons"><h1>Github</h1></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="flexttb">
|
<div class="flexttb">
|
||||||
|
|
||||||
<div class="flexttb pagehead"><h1>Welcome to Jank Client</h1></div>
|
<div class="flexttb pagehead"><h1>Welcome to Jank Client</h1></div>
|
||||||
<div class="pagebox">
|
<div class="pagebox">
|
||||||
<p>Jank Client is a spacebar compatible client seeking to be as good as it can be with many features including:</p>
|
<p>Jank Client is a spacebar compatible client seeking to be as good as it can be with many features including:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Direct Messaging</li>
|
<li>Direct Messaging</li>
|
||||||
<li>Reactions support</li>
|
<li>Reactions support</li>
|
||||||
<li>Invites</li>
|
<li>Invites</li>
|
||||||
<li>Account switching</li>
|
<li>Account switching</li>
|
||||||
<li>User settings</li>
|
<li>User settings</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="pagebox">
|
<div class="pagebox">
|
||||||
<h2>Spacebar compatible Instances:</h2>
|
<h2>Spacebar compatible Instances:</h2>
|
||||||
<div id="instancebox">
|
<div id="instancebox">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="pagebox">
|
<div class="pagebox">
|
||||||
<h2>Contribute to Jank Client</h2>
|
<h2>Contribute to Jank Client</h2>
|
||||||
<p>We always appreciate some help, wether that be in the form of bug reports, or code, or even just pointing out some typos.</p><br>
|
<p>We always appreciate some help, wether that be in the form of bug reports, or code, or even just pointing out some typos.</p><br>
|
||||||
</a><a href="https://github.com/MathMan05/JankClient" class="TitleButtons"><h1>Github</h1></a>
|
</a><a href="https://github.com/MathMan05/JankClient" class="TitleButtons"><h1>Github</h1></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script src="/home.js" type="module" ></script>
|
<script src="/home.js" type="module"></script>
|
||||||
</html>
|
</html>
|
||||||
|
|
114
webpage/home.ts
114
webpage/home.ts
|
@ -1,64 +1,64 @@
|
||||||
import {mobile} from "./login.js";
|
import{mobile}from"./login.js";
|
||||||
console.log(mobile);
|
console.log(mobile);
|
||||||
const serverbox=document.getElementById("instancebox") as HTMLDivElement;
|
const serverbox=document.getElementById("instancebox") as HTMLDivElement;
|
||||||
|
|
||||||
fetch("/instances.json").then(_=>_.json()).then((json:{name:string,description?:string,descriptionLong?:string,image?:string,url?:string,display?:boolean,online?:boolean,
|
fetch("/instances.json").then(_=>_.json()).then((json:{name:string,description?:string,descriptionLong?:string,image?:string,url?:string,display?:boolean,online?:boolean,
|
||||||
uptime:{alltime:number,daytime:number,weektime:number},
|
uptime:{alltime:number,daytime:number,weektime:number},
|
||||||
urls:{wellknown:string,api:string,cdn:string,gateway:string,login?:string}}[])=>{
|
urls:{wellknown:string,api:string,cdn:string,gateway:string,login?:string}}[])=>{
|
||||||
console.warn(json);
|
console.warn(json);
|
||||||
for(const instance of json){
|
for(const instance of json){
|
||||||
if(instance.display===false){
|
if(instance.display===false){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
div.classList.add("flexltr","instance");
|
div.classList.add("flexltr","instance");
|
||||||
if(instance.image){
|
if(instance.image){
|
||||||
const img=document.createElement("img");
|
const img=document.createElement("img");
|
||||||
img.src=instance.image;
|
img.src=instance.image;
|
||||||
div.append(img);
|
div.append(img);
|
||||||
}
|
}
|
||||||
const statbox=document.createElement("div");
|
const statbox=document.createElement("div");
|
||||||
statbox.classList.add("flexttb");
|
statbox.classList.add("flexttb");
|
||||||
|
|
||||||
{
|
{
|
||||||
const textbox=document.createElement("div");
|
const textbox=document.createElement("div");
|
||||||
textbox.classList.add("flexttb","instatancetextbox");
|
textbox.classList.add("flexttb","instatancetextbox");
|
||||||
const title=document.createElement("h2");
|
const title=document.createElement("h2");
|
||||||
title.innerText=instance.name;
|
title.innerText=instance.name;
|
||||||
if(instance.online!==undefined){
|
if(instance.online!==undefined){
|
||||||
const status=document.createElement("span");
|
const status=document.createElement("span");
|
||||||
status.innerText=instance.online?"Online":"Offline";
|
status.innerText=instance.online?"Online":"Offline";
|
||||||
status.classList.add("instanceStatus");
|
status.classList.add("instanceStatus");
|
||||||
title.append(status);
|
title.append(status);
|
||||||
}
|
}
|
||||||
textbox.append(title);
|
textbox.append(title);
|
||||||
if(instance.description||instance.descriptionLong){
|
if(instance.description||instance.descriptionLong){
|
||||||
const p=document.createElement("p");
|
const p=document.createElement("p");
|
||||||
if(instance.descriptionLong){
|
if(instance.descriptionLong){
|
||||||
p.innerText=instance.descriptionLong;
|
p.innerText=instance.descriptionLong;
|
||||||
}else{
|
}else if(instance.description){
|
||||||
p.innerText=instance.description;
|
p.innerText=instance.description;
|
||||||
}
|
}
|
||||||
textbox.append(p);
|
textbox.append(p);
|
||||||
}
|
}
|
||||||
statbox.append(textbox)
|
statbox.append(textbox);
|
||||||
}
|
}
|
||||||
if(instance.uptime){
|
if(instance.uptime){
|
||||||
const stats=document.createElement("div");
|
const stats=document.createElement("div");
|
||||||
stats.classList.add("flexltr");
|
stats.classList.add("flexltr");
|
||||||
const span=document.createElement("span");
|
const span=document.createElement("span");
|
||||||
span.innerText=`Uptime: All time: ${Math.floor(instance.uptime.alltime*100)}% This week: ${Math.floor(instance.uptime.weektime*100)}% Today: ${Math.floor(instance.uptime.daytime*100)}%`
|
span.innerText=`Uptime: All time: ${Math.floor(instance.uptime.alltime*100)}% This week: ${Math.floor(instance.uptime.weektime*100)}% Today: ${Math.floor(instance.uptime.daytime*100)}%`;
|
||||||
stats.append(span);
|
stats.append(span);
|
||||||
statbox.append(stats);
|
statbox.append(stats);
|
||||||
}
|
}
|
||||||
div.append(statbox);
|
div.append(statbox);
|
||||||
div.onclick=_=>{
|
div.onclick=_=>{
|
||||||
if(instance.online){
|
if(instance.online){
|
||||||
window.location.href="/register.html?instance="+encodeURI(instance.name);
|
window.location.href="/register.html?instance="+encodeURI(instance.name);
|
||||||
}else{
|
}else{
|
||||||
alert("Instance is offline, can't connect");
|
alert("Instance is offline, can't connect");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
serverbox.append(div);
|
serverbox.append(div);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
|
@ -1,80 +1,80 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
<title>Jank Client</title>
|
<title>Jank Client</title>
|
||||||
<meta content="Jank Client" property="og:title" />
|
<meta content="Jank Client" property="og:title">
|
||||||
<meta content="A spacebar client that has DMs, replying and more" property="og:description" />
|
<meta content="A spacebar client that has DMs, replying and more" property="og:description">
|
||||||
<meta content="/logo.webp" property="og:image" />
|
<meta content="/logo.webp" property="og:image">
|
||||||
<meta content="#4b458c" data-react-helmet="true" name="theme-color" />
|
<meta content="#4b458c" data-react-helmet="true" name="theme-color">
|
||||||
<link href="/style.css" rel="stylesheet" type="text/css" />
|
<link href="/style.css" rel="stylesheet">
|
||||||
<link href="/themes.css" rel="stylesheet" type="text/css" id="lightcss"/>
|
<link href="/themes.css" rel="stylesheet" id="lightcss">
|
||||||
|
|
||||||
<link rel="manifest" href="/manifest.json" />
|
<link rel="manifest" href="/manifest.json">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="Dark-theme">
|
<body class="Dark-theme">
|
||||||
<script src="/index.js" type="module"></script>
|
<script src="/index.js" type="module"></script>
|
||||||
|
|
||||||
<div id="loading" class="loading">
|
<div id="loading" class="loading">
|
||||||
<div id="centerdiv">
|
<div id="centerdiv">
|
||||||
<img src="/logo.svg" style="width:3in;height:3in;">
|
<img src="/logo.svg" style="width:3in;height:3in;">
|
||||||
<h1>Jank Client is loading</h1>
|
<h1>Jank Client is loading</h1>
|
||||||
<h2 id="load-desc">This shouldn't take long</h2>
|
<h2 id="load-desc">This shouldn't take long</h2>
|
||||||
<h1 id="switchaccounts">Switch Accounts</h1>
|
<h1 id="switchaccounts">Switch Accounts</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flexltr" id="page">
|
<div class="flexltr" id="page">
|
||||||
<div id="neunence">
|
<div id="neunence">
|
||||||
<div id="servers"></div>
|
<div id="servers"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flexttb channelflex">
|
<div class="flexttb channelflex">
|
||||||
<div class="servertd" id="servertd">
|
<div class="servertd" id="servertd">
|
||||||
<h2 id="serverName">Server Name</h2>
|
<h2 id="serverName">Server Name</h2>
|
||||||
</div>
|
</div>
|
||||||
<div id="channels"></div>
|
<div id="channels"></div>
|
||||||
<div class="flexltr" id="userdock">
|
<div class="flexltr" id="userdock">
|
||||||
<div class="flexltr" id="userinfo">
|
<div class="flexltr" id="userinfo">
|
||||||
<img id="userpfp" class="pfp">
|
<img id="userpfp" class="pfp">
|
||||||
|
|
||||||
<div class="userflex">
|
<div class="userflex">
|
||||||
<p id="username">USERNAME</p>
|
<p id="username">USERNAME</p>
|
||||||
<p id="status">STATUS</p>
|
<p id="status">STATUS</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="user-actions">
|
<div id="user-actions">
|
||||||
<span id="settings" class="svgtheme svg-settings"></span>
|
<img id="settings" class="svgtheme" src="/icons/settings.svg"></img>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flexttb messageflex">
|
<div class="flexttb messageflex">
|
||||||
<div class="servertd channelnamediv">
|
<div class="servertd channelnamediv">
|
||||||
<span id="mobileback" hidden></span>
|
<span id="mobileback" hidden></span>
|
||||||
<span id="channelname">Channel name</span>
|
<span id="channelname">Channel name</span>
|
||||||
<span id="channelTopic" hidden>Channel topic</span>
|
<span id="channelTopic" hidden>Channel topic</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="channelw">
|
<div id="channelw">
|
||||||
<div id="loadingdiv">
|
<div id="loadingdiv">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="pasteimage"></div>
|
<div id="pasteimage"></div>
|
||||||
<div id="replybox" class="hideReplyBox"></div>
|
<div id="replybox" class="hideReplyBox"></div>
|
||||||
<div id="typediv">
|
<div id="typediv">
|
||||||
<div id="realbox">
|
<div id="realbox">
|
||||||
<div id="typebox" contentEditable="true"></div>
|
<div id="typebox" contentEditable="true"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="typing" class="hidden">
|
<div id="typing" class="hidden">
|
||||||
<p id="typingtext">typing</p>
|
<p id="typingtext">typing</p>
|
||||||
<div class="loading-indicator">
|
<div class="loading-indicator">
|
||||||
<div class="dot"></div>
|
<div class="dot"></div>
|
||||||
<div class="dot"></div>
|
<div class="dot"></div>
|
||||||
<div class="dot"></div>
|
<div class="dot"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
400
webpage/index.ts
400
webpage/index.ts
|
@ -1,183 +1,187 @@
|
||||||
import { Localuser } from "./localuser.js";
|
import{ Localuser }from"./localuser.js";
|
||||||
import {Contextmenu} from "./contextmenu.js";
|
import{Contextmenu}from"./contextmenu.js";
|
||||||
import {mobile, getBulkUsers,setTheme, Specialuser} from "./login.js";
|
import{mobile, getBulkUsers,setTheme, Specialuser}from"./login.js";
|
||||||
import { MarkDown } from "./markdown.js";
|
import{ MarkDown }from"./markdown.js";
|
||||||
import { Message } from "./message.js";
|
import{ Message }from"./message.js";
|
||||||
import { File } from "./file.js";
|
import{ File }from"./file.js";
|
||||||
(async()=>{
|
(async ()=>{
|
||||||
async function waitforload(){
|
async function waitforload(){
|
||||||
let res;
|
let res;
|
||||||
new Promise(r=>{res=r});
|
new Promise(r=>{
|
||||||
document.addEventListener("DOMContentLoaded", function(){
|
res=r;
|
||||||
res();
|
});
|
||||||
});
|
document.addEventListener("DOMContentLoaded", ()=>{
|
||||||
await res;
|
res();
|
||||||
}
|
});
|
||||||
await waitforload();
|
await res;
|
||||||
|
}
|
||||||
|
await waitforload();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const users=getBulkUsers();
|
const users=getBulkUsers();
|
||||||
if(!users.currentuser){
|
if(!users.currentuser){
|
||||||
window.location.href = '/login.html';
|
window.location.href = "/login.html";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function showAccountSwitcher(){
|
function showAccountSwitcher(){
|
||||||
const table=document.createElement("div");
|
const table=document.createElement("div");
|
||||||
for(const thing of Object.values(users.users)){
|
for(const thing of Object.values(users.users)){
|
||||||
const specialuser=thing as Specialuser;
|
const specialuser=thing as Specialuser;
|
||||||
console.log(specialuser.pfpsrc)
|
console.log(specialuser.pfpsrc);
|
||||||
|
|
||||||
const userinfo=document.createElement("div");
|
const userinfo=document.createElement("div");
|
||||||
userinfo.classList.add("flexltr","switchtable");
|
userinfo.classList.add("flexltr","switchtable");
|
||||||
const pfp=document.createElement("img");
|
const pfp=document.createElement("img");
|
||||||
userinfo.append(pfp);
|
userinfo.append(pfp);
|
||||||
|
|
||||||
const user=document.createElement("div");
|
const user=document.createElement("div");
|
||||||
userinfo.append(user);
|
userinfo.append(user);
|
||||||
user.append(specialuser.username);
|
user.append(specialuser.username);
|
||||||
user.append(document.createElement("br"));
|
user.append(document.createElement("br"));
|
||||||
const span=document.createElement("span");
|
const span=document.createElement("span");
|
||||||
span.textContent=specialuser.serverurls.wellknown.replace("https://","").replace("http://","");
|
span.textContent=specialuser.serverurls.wellknown.replace("https://","").replace("http://","");
|
||||||
user.append(span);
|
user.append(span);
|
||||||
user.classList.add("userinfo")
|
user.classList.add("userinfo");
|
||||||
span.classList.add("serverURL")
|
span.classList.add("serverURL");
|
||||||
|
|
||||||
pfp.src=specialuser.pfpsrc;
|
pfp.src=specialuser.pfpsrc;
|
||||||
pfp.classList.add("pfp");
|
pfp.classList.add("pfp");
|
||||||
table.append(userinfo);
|
table.append(userinfo);
|
||||||
userinfo.addEventListener("click",_=>{
|
userinfo.addEventListener("click",_=>{
|
||||||
thisuser.unload();
|
thisuser.unload();
|
||||||
thisuser.swapped=true;
|
thisuser.swapped=true;
|
||||||
const loading=document.getElementById("loading") as HTMLDivElement;
|
const loading=document.getElementById("loading") as HTMLDivElement;
|
||||||
loading.classList.remove("doneloading");
|
loading.classList.remove("doneloading");
|
||||||
loading.classList.add("loading");
|
loading.classList.add("loading");
|
||||||
thisuser=new Localuser(specialuser);
|
thisuser=new Localuser(specialuser);
|
||||||
users["currentuser"]=specialuser.uid;
|
users.currentuser=specialuser.uid;
|
||||||
localStorage.setItem("userinfos",JSON.stringify(users));
|
localStorage.setItem("userinfos",JSON.stringify(users));
|
||||||
thisuser.initwebsocket().then(_=>{
|
thisuser.initwebsocket().then(_=>{
|
||||||
thisuser.loaduser();
|
thisuser.loaduser();
|
||||||
thisuser.init();
|
thisuser.init();
|
||||||
loading.classList.add("doneloading");
|
loading.classList.add("doneloading");
|
||||||
loading.classList.remove("loading");
|
loading.classList.remove("loading");
|
||||||
console.log("done loading")
|
console.log("done loading");
|
||||||
|
});
|
||||||
});
|
userinfo.remove();
|
||||||
userinfo.remove();
|
});
|
||||||
})
|
}
|
||||||
}
|
{
|
||||||
{
|
const td=document.createElement("div");
|
||||||
const td=document.createElement("div");
|
td.classList.add("switchtable");
|
||||||
td.classList.add("switchtable")
|
td.append("Switch accounts ⇌");
|
||||||
td.append("Switch accounts ⇌");
|
td.addEventListener("click",_=>{
|
||||||
td.addEventListener("click",_=>{
|
window.location.href="/login.html";
|
||||||
window.location.href="/login.html";
|
});
|
||||||
})
|
table.append(td);
|
||||||
table.append(td);
|
}
|
||||||
}
|
table.classList.add("accountSwitcher");
|
||||||
table.classList.add("accountSwitcher");
|
if(Contextmenu.currentmenu!=""){
|
||||||
if(Contextmenu.currentmenu!=""){
|
Contextmenu.currentmenu.remove();
|
||||||
Contextmenu.currentmenu.remove();
|
}
|
||||||
}
|
Contextmenu.currentmenu=table;
|
||||||
Contextmenu.currentmenu=table;
|
console.log(table);
|
||||||
console.log(table);
|
document.body.append(table);
|
||||||
document.body.append(table);
|
}
|
||||||
}
|
{
|
||||||
{
|
const userinfo=document.getElementById("userinfo") as HTMLDivElement;
|
||||||
const userinfo=document.getElementById("userinfo") as HTMLDivElement;
|
userinfo.addEventListener("click",_=>{
|
||||||
userinfo.addEventListener("click",_=>{
|
_.stopImmediatePropagation();
|
||||||
_.stopImmediatePropagation();
|
showAccountSwitcher();
|
||||||
showAccountSwitcher();
|
});
|
||||||
})
|
const switchaccounts=document.getElementById("switchaccounts") as HTMLDivElement;
|
||||||
const switchaccounts=document.getElementById("switchaccounts") as HTMLDivElement;
|
switchaccounts.addEventListener("click",_=>{
|
||||||
switchaccounts.addEventListener("click",_=>{
|
_.stopImmediatePropagation();
|
||||||
_.stopImmediatePropagation();
|
showAccountSwitcher();
|
||||||
showAccountSwitcher();
|
});
|
||||||
})
|
console.log("this ran");
|
||||||
console.log("this ran")
|
}
|
||||||
}
|
let thisuser:Localuser;
|
||||||
let thisuser:Localuser;
|
try{
|
||||||
try{
|
console.log(users.users,users.currentuser);
|
||||||
console.log(users.users,users.currentuser)
|
thisuser=new Localuser(users.users[users.currentuser]);
|
||||||
thisuser=new Localuser(users.users[users.currentuser]);
|
thisuser.initwebsocket().then(_=>{
|
||||||
thisuser.initwebsocket().then(_=>{
|
thisuser.loaduser();
|
||||||
thisuser.loaduser();
|
thisuser.init();
|
||||||
thisuser.init();
|
const loading=document.getElementById("loading") as HTMLDivElement;
|
||||||
const loading=document.getElementById("loading") as HTMLDivElement;
|
loading.classList.add("doneloading");
|
||||||
loading.classList.add("doneloading");
|
loading.classList.remove("loading");
|
||||||
loading.classList.remove("loading");
|
console.log("done loading");
|
||||||
console.log("done loading")
|
});
|
||||||
});
|
}catch(e){
|
||||||
}catch(e){
|
console.error(e);
|
||||||
console.error(e);
|
(document.getElementById("load-desc") as HTMLSpanElement).textContent="Account unable to start";
|
||||||
(document.getElementById("load-desc") as HTMLSpanElement).textContent="Account unable to start";
|
thisuser=new Localuser(-1);
|
||||||
thisuser=new Localuser(-1);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const menu=new Contextmenu("create rightclick");//Really should go into the localuser class, but that's a later thing
|
const menu=new Contextmenu("create rightclick");//Really should go into the localuser class, but that's a later thing
|
||||||
menu.addbutton("Create channel",function(){
|
menu.addbutton("Create channel",()=>{
|
||||||
if(thisuser.lookingguild){
|
if(thisuser.lookingguild){
|
||||||
thisuser.lookingguild.createchannels();
|
thisuser.lookingguild.createchannels();
|
||||||
}
|
}
|
||||||
},null,_=>{return thisuser.isAdmin()})
|
},null,_=>{
|
||||||
|
return thisuser.isAdmin();
|
||||||
|
});
|
||||||
|
|
||||||
menu.addbutton("Create category",function(){
|
menu.addbutton("Create category",()=>{
|
||||||
if(thisuser.lookingguild){
|
if(thisuser.lookingguild){
|
||||||
thisuser.lookingguild.createcategory();
|
thisuser.lookingguild.createcategory();
|
||||||
}
|
}
|
||||||
},null,_=>{return thisuser.isAdmin()})
|
},null,_=>{
|
||||||
menu.bindContextmenu(document.getElementById("channels") as HTMLDivElement,0,0)
|
return thisuser.isAdmin();
|
||||||
}
|
});
|
||||||
|
menu.bindContextmenu(document.getElementById("channels") as HTMLDivElement,0,0);
|
||||||
|
}
|
||||||
|
|
||||||
const pasteimage=document.getElementById("pasteimage") as HTMLDivElement;
|
const pasteimage=document.getElementById("pasteimage") as HTMLDivElement;
|
||||||
let replyingto:Message|null=null;
|
let replyingto:Message|null=null;
|
||||||
async function enter(event){
|
async function enter(event){
|
||||||
const channel=thisuser.channelfocus
|
const channel=thisuser.channelfocus;
|
||||||
if(!channel||!thisuser.channelfocus) return;
|
if(!channel||!thisuser.channelfocus)return;
|
||||||
channel.typingstart();
|
channel.typingstart();
|
||||||
if(event.key === "Enter"&&!event.shiftKey){
|
if(event.key === "Enter"&&!event.shiftKey){
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if(channel.editing){
|
if(channel.editing){
|
||||||
channel.editing.edit(markdown.rawString);
|
channel.editing.edit(markdown.rawString);
|
||||||
channel.editing=null;
|
channel.editing=null;
|
||||||
}else{
|
}else{
|
||||||
replyingto= thisuser.channelfocus.replyingto;
|
replyingto= thisuser.channelfocus.replyingto;
|
||||||
let replying=replyingto;
|
const replying=replyingto;
|
||||||
if(replyingto?.div){
|
if(replyingto?.div){
|
||||||
replyingto.div.classList.remove("replying");
|
replyingto.div.classList.remove("replying");
|
||||||
}
|
}
|
||||||
thisuser.channelfocus.replyingto=null;
|
thisuser.channelfocus.replyingto=null;
|
||||||
channel.sendMessage(markdown.rawString,{
|
channel.sendMessage(markdown.rawString,{
|
||||||
attachments:images,
|
attachments: images,
|
||||||
embeds:[],
|
embeds: [],
|
||||||
replyingto:replying
|
replyingto: replying
|
||||||
})
|
});
|
||||||
thisuser.channelfocus.makereplybox();
|
thisuser.channelfocus.makereplybox();
|
||||||
}
|
}
|
||||||
while(images.length!=0){
|
while(images.length!=0){
|
||||||
images.pop();
|
images.pop();
|
||||||
pasteimage.removeChild(imageshtml.pop() as HTMLElement);
|
pasteimage.removeChild(imageshtml.pop() as HTMLElement);
|
||||||
}
|
}
|
||||||
typebox.innerHTML="";
|
typebox.innerHTML="";
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const typebox=document.getElementById("typebox") as HTMLDivElement;
|
const typebox=document.getElementById("typebox") as HTMLDivElement;
|
||||||
const markdown=new MarkDown("",thisuser);
|
const markdown=new MarkDown("",thisuser);
|
||||||
markdown.giveBox(typebox);
|
markdown.giveBox(typebox);
|
||||||
typebox["markdown"]=markdown;
|
typebox["markdown"]=markdown;
|
||||||
typebox.addEventListener("keyup",enter);
|
typebox.addEventListener("keyup",enter);
|
||||||
typebox.addEventListener("keydown",event=>{
|
typebox.addEventListener("keydown",event=>{
|
||||||
if(event.key === "Enter"&&!event.shiftKey) event.preventDefault();
|
if(event.key === "Enter"&&!event.shiftKey) event.preventDefault();
|
||||||
});
|
});
|
||||||
console.log(typebox)
|
console.log(typebox);
|
||||||
typebox.onclick=console.log;
|
typebox.onclick=console.log;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function getguildinfo(){
|
function getguildinfo(){
|
||||||
const path=window.location.pathname.split("/");
|
const path=window.location.pathname.split("/");
|
||||||
const channel=path[3];
|
const channel=path[3];
|
||||||
|
@ -185,41 +189,41 @@ import { File } from "./file.js";
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const images:Blob[]=[];
|
const images:Blob[]=[];
|
||||||
const imageshtml:HTMLElement[]=[];
|
const imageshtml:HTMLElement[]=[];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('paste', async (e) => {
|
document.addEventListener("paste", async e=>{
|
||||||
if(!e.clipboardData) return;
|
if(!e.clipboardData)return;
|
||||||
Array.from(e.clipboardData.files).forEach(async (f) => {
|
Array.from(e.clipboardData.files).forEach(async f=>{
|
||||||
const file=File.initFromBlob(f);
|
const file=File.initFromBlob(f);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const html=file.upHTML(images,f);
|
const html=file.upHTML(images,f);
|
||||||
pasteimage.appendChild(html);
|
pasteimage.appendChild(html);
|
||||||
images.push(f)
|
images.push(f);
|
||||||
imageshtml.push(html);
|
imageshtml.push(html);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
setTheme();
|
setTheme();
|
||||||
|
|
||||||
function userSettings(){
|
function userSettings(){
|
||||||
thisuser.showusersettings();
|
thisuser.showusersettings();
|
||||||
}
|
}
|
||||||
(document.getElementById("settings") as HTMLImageElement).onclick=userSettings;
|
(document.getElementById("settings") as HTMLImageElement).onclick=userSettings;
|
||||||
|
|
||||||
if(mobile){
|
if(mobile){
|
||||||
(document.getElementById("channelw") as HTMLDivElement).onclick=()=>{
|
(document.getElementById("channelw") as HTMLDivElement).onclick=()=>{
|
||||||
((document.getElementById("channels") as HTMLDivElement).parentNode as HTMLElement).classList.add("collapse");
|
((document.getElementById("channels") as HTMLDivElement).parentNode as HTMLElement).classList.add("collapse");
|
||||||
(document.getElementById("servertd") as HTMLDivElement).classList.add("collapse");
|
(document.getElementById("servertd") as HTMLDivElement).classList.add("collapse");
|
||||||
(document.getElementById("servers") as HTMLDivElement).classList.add("collapse");
|
(document.getElementById("servers") as HTMLDivElement).classList.add("collapse");
|
||||||
}
|
};
|
||||||
(document.getElementById("mobileback") as HTMLDivElement).textContent="#";
|
(document.getElementById("mobileback") as HTMLDivElement).textContent="#";
|
||||||
(document.getElementById("mobileback") as HTMLDivElement).onclick=()=>{
|
(document.getElementById("mobileback") as HTMLDivElement).onclick=()=>{
|
||||||
((document.getElementById("channels") as HTMLDivElement).parentNode as HTMLElement).classList.remove("collapse");
|
((document.getElementById("channels") as HTMLDivElement).parentNode as HTMLElement).classList.remove("collapse");
|
||||||
(document.getElementById("servertd") as HTMLDivElement).classList.remove("collapse");
|
(document.getElementById("servertd") as HTMLDivElement).classList.remove("collapse");
|
||||||
(document.getElementById("servers") as HTMLDivElement).classList.remove("collapse");
|
(document.getElementById("servers") as HTMLDivElement).classList.remove("collapse");
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
})()
|
})();
|
||||||
|
|
|
@ -1,305 +1,294 @@
|
||||||
class InfiniteScroller{
|
class InfiniteScroller{
|
||||||
readonly getIDFromOffset:(ID:string,offset:number)=>Promise<string|undefined>;
|
readonly getIDFromOffset:(ID:string,offset:number)=>Promise<string|undefined>;
|
||||||
readonly getHTMLFromID:(ID:string)=>Promise<HTMLElement>;
|
readonly getHTMLFromID:(ID:string)=>Promise<HTMLElement>;
|
||||||
readonly destroyFromID:(ID:string)=>Promise<boolean>;
|
readonly destroyFromID:(ID:string)=>Promise<boolean>;
|
||||||
readonly reachesBottom:()=>void;
|
readonly reachesBottom:()=>void;
|
||||||
private readonly minDist=2000;
|
private readonly minDist=2000;
|
||||||
private readonly fillDist=3000;
|
private readonly fillDist=3000;
|
||||||
private readonly maxDist=6000;
|
private readonly maxDist=6000;
|
||||||
HTMLElements:[HTMLElement,string][]=[];
|
HTMLElements:[HTMLElement,string][]=[];
|
||||||
div:HTMLDivElement|null;
|
div:HTMLDivElement|null;
|
||||||
scroll:HTMLDivElement|null;
|
scroll:HTMLDivElement|null;
|
||||||
constructor(getIDFromOffset:InfiniteScroller["getIDFromOffset"],getHTMLFromID:InfiniteScroller["getHTMLFromID"],destroyFromID:InfiniteScroller["destroyFromID"],reachesBottom:InfiniteScroller["reachesBottom"]=()=>{}){
|
constructor(getIDFromOffset:InfiniteScroller["getIDFromOffset"],getHTMLFromID:InfiniteScroller["getHTMLFromID"],destroyFromID:InfiniteScroller["destroyFromID"],reachesBottom:InfiniteScroller["reachesBottom"]=()=>{}){
|
||||||
this.getIDFromOffset=getIDFromOffset;
|
this.getIDFromOffset=getIDFromOffset;
|
||||||
this.getHTMLFromID=getHTMLFromID;
|
this.getHTMLFromID=getHTMLFromID;
|
||||||
this.destroyFromID=destroyFromID;
|
this.destroyFromID=destroyFromID;
|
||||||
this.reachesBottom=reachesBottom;
|
this.reachesBottom=reachesBottom;
|
||||||
}
|
}
|
||||||
timeout:NodeJS.Timeout|null;
|
timeout:NodeJS.Timeout|null;
|
||||||
async getDiv(initialId:string,bottom=true):Promise<HTMLDivElement>{
|
async getDiv(initialId:string,bottom=true):Promise<HTMLDivElement>{
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
div.classList.add("messagecontainer");
|
div.classList.add("messagecontainer");
|
||||||
//div.classList.add("flexttb")
|
//div.classList.add("flexttb")
|
||||||
const scroll=document.createElement("div");
|
const scroll=document.createElement("div");
|
||||||
scroll.classList.add("flexttb","scroller")
|
scroll.classList.add("flexttb","scroller");
|
||||||
div.appendChild(scroll);
|
div.appendChild(scroll);
|
||||||
this.div=div;
|
this.div=div;
|
||||||
//this.interval=setInterval(this.updatestuff.bind(this,true),100);
|
//this.interval=setInterval(this.updatestuff.bind(this,true),100);
|
||||||
|
|
||||||
this.scroll=scroll;
|
this.scroll=scroll;
|
||||||
this.div.addEventListener("scroll",_=>{
|
this.div.addEventListener("scroll",_=>{
|
||||||
if(this.scroll) this.scrollTop=this.scroll.scrollTop;
|
if(this.scroll)this.scrollTop=this.scroll.scrollTop;
|
||||||
this.watchForChange()
|
this.watchForChange();
|
||||||
});
|
});
|
||||||
this.scroll.addEventListener("scroll",_=>{
|
this.scroll.addEventListener("scroll",_=>{
|
||||||
if(null===this.timeout){
|
if(this.timeout===null){
|
||||||
this.timeout=setTimeout(this.updatestuff.bind(this),300);
|
this.timeout=setTimeout(this.updatestuff.bind(this),300);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.watchForChange()
|
this.watchForChange();
|
||||||
});
|
});
|
||||||
{
|
{
|
||||||
let oldheight=0;
|
let oldheight=0;
|
||||||
new ResizeObserver(_=>{
|
new ResizeObserver(_=>{
|
||||||
this.updatestuff();
|
this.updatestuff();
|
||||||
const change=oldheight-div.offsetHeight;
|
const change=oldheight-div.offsetHeight;
|
||||||
if(change>0&&this.scroll){
|
if(change>0&&this.scroll){
|
||||||
this.scroll.scrollTop+=change;
|
this.scroll.scrollTop+=change;
|
||||||
}
|
}
|
||||||
oldheight=div.offsetHeight;
|
oldheight=div.offsetHeight;
|
||||||
this.watchForChange();
|
this.watchForChange();
|
||||||
}).observe(div);
|
}).observe(div);
|
||||||
}
|
}
|
||||||
new ResizeObserver(this.watchForChange.bind(this)).observe(scroll);
|
new ResizeObserver(this.watchForChange.bind(this)).observe(scroll);
|
||||||
|
|
||||||
await this.firstElement(initialId)
|
await this.firstElement(initialId);
|
||||||
this.updatestuff();
|
this.updatestuff();
|
||||||
await this.watchForChange().then(_=>{
|
await this.watchForChange().then(_=>{
|
||||||
this.updatestuff();
|
this.updatestuff();
|
||||||
})
|
});
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
scrollBottom:number;
|
scrollBottom:number;
|
||||||
scrollTop:number;
|
scrollTop:number;
|
||||||
needsupdate=true;
|
needsupdate=true;
|
||||||
averageheight:number=60;
|
averageheight:number=60;
|
||||||
async updatestuff(){
|
async updatestuff(){
|
||||||
this.timeout=null;
|
this.timeout=null;
|
||||||
if(!this.scroll) return;
|
if(!this.scroll)return;
|
||||||
this.scrollBottom = this.scroll.scrollHeight - this.scroll.scrollTop - this.scroll.clientHeight;
|
this.scrollBottom = this.scroll.scrollHeight - this.scroll.scrollTop - this.scroll.clientHeight;
|
||||||
this.averageheight=this.scroll.scrollHeight/this.HTMLElements.length;
|
this.averageheight=this.scroll.scrollHeight/this.HTMLElements.length;
|
||||||
if(this.averageheight<10){
|
if(this.averageheight<10){
|
||||||
this.averageheight=60;
|
this.averageheight=60;
|
||||||
}
|
}
|
||||||
this.scrollTop=this.scroll.scrollTop;
|
this.scrollTop=this.scroll.scrollTop;
|
||||||
if(!this.scrollBottom){
|
if(!this.scrollBottom && !await this.watchForChange()){
|
||||||
if(!await this.watchForChange()){
|
this.reachesBottom();
|
||||||
this.reachesBottom();
|
}
|
||||||
}
|
if(!this.scrollTop){
|
||||||
}
|
await this.watchForChange();
|
||||||
if(!this.scrollTop){
|
}
|
||||||
await this.watchForChange()
|
this.needsupdate=false;
|
||||||
}
|
//this.watchForChange();
|
||||||
this.needsupdate=false;
|
}
|
||||||
//this.watchForChange();
|
async firstElement(id:string){
|
||||||
}
|
if(!this.scroll)return;
|
||||||
async firstElement(id:string){
|
const html=await this.getHTMLFromID(id);
|
||||||
if(!this.scroll) return;
|
this.scroll.appendChild(html);
|
||||||
const html=await this.getHTMLFromID(id);
|
this.HTMLElements.push([html,id]);
|
||||||
this.scroll.appendChild(html);
|
}
|
||||||
this.HTMLElements.push([html,id]);
|
currrunning:boolean=false;
|
||||||
}
|
async addedBottom(){
|
||||||
currrunning:boolean=false;
|
this.updatestuff();
|
||||||
async addedBottom(){
|
const func=this.snapBottom();
|
||||||
this.updatestuff();
|
await this.watchForChange();
|
||||||
const func=this.snapBottom();
|
func();
|
||||||
await this.watchForChange();
|
}
|
||||||
func();
|
snapBottom(){
|
||||||
}
|
const scrollBottom=this.scrollBottom;
|
||||||
snapBottom(){
|
return()=>{
|
||||||
const scrollBottom=this.scrollBottom;
|
if(this.scroll&&scrollBottom<30){
|
||||||
return ()=>{
|
this.scroll.scrollTop=this.scroll.scrollHeight+20;
|
||||||
if(this.scroll&&scrollBottom<30){
|
}
|
||||||
this.scroll.scrollTop=this.scroll.scrollHeight+20;
|
};
|
||||||
}
|
}
|
||||||
}
|
private async watchForTop(already=false,fragement=new DocumentFragment()):Promise<boolean>{
|
||||||
}
|
if(!this.scroll)return false;
|
||||||
private async watchForTop(already=false,fragement=new DocumentFragment()):Promise<boolean>{
|
try{
|
||||||
if(!this.scroll) return false;
|
let again=false;
|
||||||
try{
|
if(this.scrollTop<(already?this.fillDist:this.minDist)){
|
||||||
let again=false;
|
let nextid:string|undefined;
|
||||||
if(this.scrollTop<(already?this.fillDist:this.minDist)){
|
const firstelm=this.HTMLElements.at(0);
|
||||||
let nextid:string|undefined;
|
if(firstelm){
|
||||||
const firstelm=this.HTMLElements.at(0);
|
const previd=firstelm[1];
|
||||||
if(firstelm){
|
nextid=await this.getIDFromOffset(previd,1);
|
||||||
const previd=firstelm[1];
|
}
|
||||||
nextid=await this.getIDFromOffset(previd,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(!nextid){
|
if(!nextid){
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
const html=await this.getHTMLFromID(nextid);
|
const html=await this.getHTMLFromID(nextid);
|
||||||
if(!html){
|
if(!html){
|
||||||
this.destroyFromID(nextid);
|
this.destroyFromID(nextid);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
again=true;
|
again=true;
|
||||||
fragement.prepend(html);
|
fragement.prepend(html);
|
||||||
this.HTMLElements.unshift([html,nextid]);
|
this.HTMLElements.unshift([html,nextid]);
|
||||||
this.scrollTop+=this.averageheight;
|
this.scrollTop+=this.averageheight;
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
if(this.scrollTop>this.maxDist){
|
if(this.scrollTop>this.maxDist){
|
||||||
|
const html=this.HTMLElements.shift();
|
||||||
|
if(html){
|
||||||
|
again=true;
|
||||||
|
await this.destroyFromID(html[1]);
|
||||||
|
this.scrollTop-=this.averageheight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(again){
|
||||||
|
await this.watchForTop(true,fragement);
|
||||||
|
}
|
||||||
|
return again;
|
||||||
|
}finally{
|
||||||
|
if(!already){
|
||||||
|
if(this.scroll.scrollTop===0){
|
||||||
|
this.scrollTop=1;
|
||||||
|
this.scroll.scrollTop=10;
|
||||||
|
}
|
||||||
|
this.scroll.prepend(fragement,fragement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async watchForBottom(already=false,fragement=new DocumentFragment()):Promise<boolean>{
|
||||||
|
if(!this.scroll)return false;
|
||||||
|
try{
|
||||||
|
let again=false;
|
||||||
|
const scrollBottom = this.scrollBottom;
|
||||||
|
if(scrollBottom<(already?this.fillDist:this.minDist)){
|
||||||
|
let nextid:string|undefined;
|
||||||
|
const lastelm=this.HTMLElements.at(-1);
|
||||||
|
if(lastelm){
|
||||||
|
const previd=lastelm[1];
|
||||||
|
nextid=await this.getIDFromOffset(previd,-1);
|
||||||
|
}
|
||||||
|
if(!nextid){
|
||||||
|
}else{
|
||||||
|
again=true;
|
||||||
|
const html=await this.getHTMLFromID(nextid);
|
||||||
|
fragement.appendChild(html);
|
||||||
|
this.HTMLElements.push([html,nextid]);
|
||||||
|
this.scrollBottom+=this.averageheight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(scrollBottom>this.maxDist){
|
||||||
|
const html=this.HTMLElements.pop();
|
||||||
|
if(html){
|
||||||
|
await this.destroyFromID(html[1]);
|
||||||
|
this.scrollBottom-=this.averageheight;
|
||||||
|
again=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(again){
|
||||||
|
await this.watchForBottom(true,fragement);
|
||||||
|
}
|
||||||
|
return again;
|
||||||
|
}finally{
|
||||||
|
if(!already){
|
||||||
|
this.scroll.append(fragement);
|
||||||
|
if(this.scrollBottom<30){
|
||||||
|
this.scroll.scrollTop=this.scroll.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
watchtime:boolean=false;
|
||||||
|
changePromise:Promise<boolean>|undefined;
|
||||||
|
async watchForChange():Promise<boolean>{
|
||||||
|
if(this.currrunning){
|
||||||
|
this.watchtime=true;
|
||||||
|
if(this.changePromise){
|
||||||
|
return await this.changePromise;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
this.watchtime=false;
|
||||||
|
this.currrunning=true;
|
||||||
|
}
|
||||||
|
this.changePromise=new Promise<boolean>(async res=>{
|
||||||
|
try{
|
||||||
|
try{
|
||||||
|
if(!this.div){
|
||||||
|
res(false);return false;
|
||||||
|
}
|
||||||
|
const out=await Promise.allSettled([this.watchForTop(),this.watchForBottom()]) as {value:boolean}[];
|
||||||
|
const changed=(out[0].value||out[1].value);
|
||||||
|
if(this.timeout===null&&changed){
|
||||||
|
this.timeout=setTimeout(this.updatestuff.bind(this),300);
|
||||||
|
}
|
||||||
|
if(!this.currrunning){
|
||||||
|
console.error("something really bad happened");
|
||||||
|
}
|
||||||
|
|
||||||
|
res(Boolean(changed));
|
||||||
const html=this.HTMLElements.shift();
|
return Boolean(changed);
|
||||||
if(html){
|
}catch(e){
|
||||||
again=true;
|
console.error(e);
|
||||||
await this.destroyFromID(html[1]);
|
}
|
||||||
this.scrollTop-=this.averageheight;
|
res(false);
|
||||||
}
|
return false;
|
||||||
}
|
}catch(e){
|
||||||
if(again){
|
throw e;
|
||||||
await this.watchForTop(true,fragement);
|
}finally{
|
||||||
}
|
setTimeout(_=>{
|
||||||
return again;
|
this.changePromise=undefined;
|
||||||
}finally{
|
this.currrunning=false;
|
||||||
if(!already){
|
if(this.watchtime){
|
||||||
if(this.scroll.scrollTop===0){
|
this.watchForChange();
|
||||||
this.scrollTop=1;
|
}
|
||||||
this.scroll.scrollTop=10;
|
},300);
|
||||||
}
|
}
|
||||||
this.scroll.prepend(fragement,fragement);
|
});
|
||||||
}
|
return await this.changePromise;
|
||||||
}
|
}
|
||||||
}
|
async focus(id:string,flash=true){
|
||||||
async watchForBottom(already=false,fragement=new DocumentFragment()):Promise<boolean>{
|
let element:HTMLElement|undefined;
|
||||||
if(!this.scroll) return false;
|
for(const thing of this.HTMLElements){
|
||||||
try{
|
if(thing[1]===id){
|
||||||
let again=false;
|
element=thing[0];
|
||||||
const scrollBottom = this.scrollBottom;
|
}
|
||||||
if(scrollBottom<(already?this.fillDist:this.minDist)){
|
}
|
||||||
|
console.log(id,element,this.HTMLElements.length,":3");
|
||||||
let nextid:string|undefined;
|
if(element){
|
||||||
const lastelm=this.HTMLElements.at(-1);
|
if(flash){
|
||||||
if(lastelm){
|
element.scrollIntoView({
|
||||||
const previd=lastelm[1];
|
behavior: "smooth",
|
||||||
nextid=await this.getIDFromOffset(previd,-1);
|
block: "center"
|
||||||
}
|
});
|
||||||
if(!nextid){
|
await new Promise(resolve=>setTimeout(resolve, 1000));
|
||||||
}else{
|
element.classList.remove("jumped");
|
||||||
again=true;
|
await new Promise(resolve=>setTimeout(resolve, 100));
|
||||||
const html=await this.getHTMLFromID(nextid);
|
element.classList.add("jumped");
|
||||||
fragement.appendChild(html);
|
}else{
|
||||||
this.HTMLElements.push([html,nextid]);
|
element.scrollIntoView();
|
||||||
this.scrollBottom+=this.averageheight;
|
}
|
||||||
};
|
}else{
|
||||||
}
|
for(const thing of this.HTMLElements){
|
||||||
if(scrollBottom>this.maxDist){
|
await this.destroyFromID(thing[1]);
|
||||||
|
}
|
||||||
|
this.HTMLElements=[];
|
||||||
const html=this.HTMLElements.pop();
|
await this.firstElement(id);
|
||||||
if(html){
|
this.updatestuff();
|
||||||
await this.destroyFromID(html[1]);
|
await this.watchForChange();
|
||||||
this.scrollBottom-=this.averageheight;
|
await new Promise(resolve=>setTimeout(resolve, 100));
|
||||||
again=true;
|
await this.focus(id,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(again){
|
async delete():Promise<void>{
|
||||||
await this.watchForBottom(true,fragement);
|
for(const thing of this.HTMLElements){
|
||||||
}
|
await this.destroyFromID(thing[1]);
|
||||||
return again;
|
}
|
||||||
}finally{
|
this.HTMLElements=[];
|
||||||
if(!already){
|
if(this.timeout){
|
||||||
this.scroll.append(fragement);
|
clearTimeout(this.timeout);
|
||||||
if(this.scrollBottom<30){
|
}
|
||||||
this.scroll.scrollTop=this.scroll.scrollHeight;
|
if(this.div){
|
||||||
}
|
this.div.remove();
|
||||||
}
|
}
|
||||||
}
|
this.scroll=null;
|
||||||
}
|
this.div=null;
|
||||||
watchtime:boolean=false;
|
}
|
||||||
changePromise:Promise<boolean>|undefined;
|
|
||||||
async watchForChange():Promise<boolean>{
|
|
||||||
if(this.currrunning){
|
|
||||||
this.watchtime=true;
|
|
||||||
if(this.changePromise){
|
|
||||||
return await this.changePromise;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
this.watchtime=false;
|
|
||||||
this.currrunning=true;
|
|
||||||
|
|
||||||
}
|
|
||||||
this.changePromise=new Promise<boolean>(async res=>{
|
|
||||||
try{
|
|
||||||
|
|
||||||
try{
|
|
||||||
if(!this.div){res(false);return false}
|
|
||||||
const out=await Promise.allSettled([this.watchForTop(),this.watchForBottom()]) as {value:boolean}[];
|
|
||||||
const changed=(out[0].value||out[1].value);
|
|
||||||
if(null===this.timeout&&changed){
|
|
||||||
this.timeout=setTimeout(this.updatestuff.bind(this),300);
|
|
||||||
}
|
|
||||||
if(!this.currrunning){console.error("something really bad happened")}
|
|
||||||
|
|
||||||
res(!!changed);
|
|
||||||
return !!changed;
|
|
||||||
|
|
||||||
}catch(e){
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
res(false);
|
|
||||||
return false;
|
|
||||||
}catch(e){
|
|
||||||
throw e;
|
|
||||||
}finally{
|
|
||||||
|
|
||||||
|
|
||||||
setTimeout(_=>{
|
|
||||||
this.changePromise=undefined;
|
|
||||||
this.currrunning=false;
|
|
||||||
if(this.watchtime){
|
|
||||||
this.watchForChange();
|
|
||||||
}
|
|
||||||
},300)
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return await this.changePromise;
|
|
||||||
}
|
|
||||||
async focus(id:string,flash=true){
|
|
||||||
|
|
||||||
let element:HTMLElement|undefined;
|
|
||||||
for(const thing of this.HTMLElements){
|
|
||||||
if(thing[1]===id){
|
|
||||||
element=thing[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(id,element,this.HTMLElements.length,":3");
|
|
||||||
if(element){
|
|
||||||
|
|
||||||
if(flash){
|
|
||||||
element.scrollIntoView({
|
|
||||||
behavior:"smooth",
|
|
||||||
block:"center"
|
|
||||||
});
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
||||||
element.classList.remove("jumped");
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 100));
|
|
||||||
element.classList.add("jumped");
|
|
||||||
}else{
|
|
||||||
element.scrollIntoView();
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
for(const thing of this.HTMLElements){
|
|
||||||
await this.destroyFromID(thing[1]);
|
|
||||||
}
|
|
||||||
this.HTMLElements=[];
|
|
||||||
await this.firstElement(id);
|
|
||||||
this.updatestuff();
|
|
||||||
await this.watchForChange();
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 100));
|
|
||||||
await this.focus(id,true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async delete():Promise<void>{
|
|
||||||
for(const thing of this.HTMLElements){
|
|
||||||
await this.destroyFromID(thing[1]);
|
|
||||||
}
|
|
||||||
this.HTMLElements=[];
|
|
||||||
if(this.timeout){
|
|
||||||
clearTimeout(this.timeout);
|
|
||||||
}
|
|
||||||
if(this.div){
|
|
||||||
this.div.remove();
|
|
||||||
}
|
|
||||||
this.scroll=null;
|
|
||||||
this.div=null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
export {InfiniteScroller};
|
export{InfiniteScroller};
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
<body class="Dark-theme">
|
<body class="Dark-theme">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Jank Client</title>
|
<title>Jank Client</title>
|
||||||
<meta content="Invite" property="og:title" />
|
<meta content="Invite" property="og:title">
|
||||||
<meta content="You shouldn't see this, but this is an invite URL" property="og:description" />
|
<meta content="You shouldn't see this, but this is an invite URL" property="og:description">
|
||||||
<meta content="/logo.webp" property="og:image" />
|
<meta content="/logo.webp" property="og:image">
|
||||||
<meta content="#4b458c" data-react-helmet="true" name="theme-color" />
|
<meta content="#4b458c" data-react-helmet="true" name="theme-color">
|
||||||
<link href="/style.css" rel="stylesheet" type="text/css" />
|
<link href="/style.css" rel="stylesheet">
|
||||||
<link href="/themes.css" rel="stylesheet" type="text/css" id="lightcss"/>
|
<link href="/themes.css" rel="stylesheet" id="lightcss">
|
||||||
</head>
|
</head>
|
||||||
<div>
|
<div>
|
||||||
<div id="invitebody">
|
<div id="invitebody">
|
||||||
<div id="inviteimg"></div>
|
<div id="inviteimg"></div>
|
||||||
<h1 id="invitename">Server Name</h1>
|
<h1 id="invitename">Server Name</h1>
|
||||||
<p id="invitedescription">Someone invited you to Server Name</p>
|
<p id="invitedescription">Someone invited you to Server Name</p>
|
||||||
<button id="AcceptInvite">Accept Invite</button>
|
<button id="AcceptInvite">Accept Invite</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script type="module" src="/invite.js"></script>
|
<script type="module" src="/invite.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,120 +1,118 @@
|
||||||
import {getBulkUsers, Specialuser, getapiurls} from "./login.js";
|
import{getBulkUsers, Specialuser, getapiurls}from"./login.js";
|
||||||
(async()=>{
|
(async ()=>{
|
||||||
const users=getBulkUsers();
|
const users=getBulkUsers();
|
||||||
const well=new URLSearchParams(window.location.search).get("instance");
|
const well=new URLSearchParams(window.location.search).get("instance");
|
||||||
const joinable:Specialuser[]=[];
|
const joinable:Specialuser[]=[];
|
||||||
for(const thing in users.users){
|
for(const thing in users.users){
|
||||||
const user:Specialuser = users.users[thing]
|
const user:Specialuser = users.users[thing];
|
||||||
if(user.serverurls.wellknown.includes(well)){
|
if(user.serverurls.wellknown.includes(well)){
|
||||||
joinable.push(user);
|
joinable.push(user);
|
||||||
}
|
}
|
||||||
console.log(users.users[thing]);
|
console.log(users.users[thing]);
|
||||||
}
|
}
|
||||||
let urls:{api:string,cdn:string};
|
let urls:{api:string,cdn:string};
|
||||||
if(!joinable.length){
|
if(!joinable.length&&well){
|
||||||
const out=await getapiurls(well);
|
const out=await getapiurls(well);
|
||||||
if(out){
|
if(out){
|
||||||
urls=out;
|
urls=out;
|
||||||
for(const thing in users.users){
|
for(const thing in users.users){
|
||||||
const user:Specialuser = users.users[thing]
|
const user:Specialuser = users.users[thing];
|
||||||
if(user.serverurls.api.includes(out.api)){
|
if(user.serverurls.api.includes(out.api)){
|
||||||
joinable.push(user);
|
joinable.push(user);
|
||||||
}
|
}
|
||||||
console.log(users.users[thing]);
|
console.log(users.users[thing]);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
throw Error("someone needs to handle the case where the servers don't exist")
|
throw new Error("someone needs to handle the case where the servers don't exist");
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
}else{
|
urls=joinable[0].serverurls;
|
||||||
urls=joinable[0].serverurls;
|
}
|
||||||
}
|
if(!joinable.length){
|
||||||
if(!joinable.length){
|
document.getElementById("AcceptInvite").textContent="Create an account to accept the invite";
|
||||||
document.getElementById("AcceptInvite").textContent="Create an account to accept the invite"
|
}
|
||||||
}
|
const code=window.location.pathname.split("/")[2];
|
||||||
const code=window.location.pathname.split("/")[2];
|
let guildinfo;
|
||||||
let guildinfo;
|
fetch(`${urls.api}/invites/${code}`,{
|
||||||
fetch(`${urls.api}/invites/${code}`,{
|
method: "GET"
|
||||||
method:"GET"
|
}).then(_=>_.json()).then(json=>{
|
||||||
}).then(_=>_.json()).then(json=>{
|
const guildjson=json.guild;
|
||||||
const guildjson=json.guild;
|
guildinfo=guildjson;
|
||||||
guildinfo=guildjson;
|
document.getElementById("invitename").textContent=guildjson.name;
|
||||||
document.getElementById("invitename").textContent=guildjson.name;
|
document.getElementById("invitedescription").textContent=
|
||||||
document.getElementById("invitedescription").textContent=
|
|
||||||
`${json.inviter.username} invited you to join ${guildjson.name}`;
|
`${json.inviter.username} invited you to join ${guildjson.name}`;
|
||||||
if(guildjson.icon){
|
if(guildjson.icon){
|
||||||
const img=document.createElement("img");
|
const img=document.createElement("img");
|
||||||
img.src=`${urls.cdn}/icons/${guildjson.id}/${guildjson.icon}.png`;
|
img.src=`${urls.cdn}/icons/${guildjson.id}/${guildjson.icon}.png`;
|
||||||
img.classList.add("inviteGuild");
|
img.classList.add("inviteGuild");
|
||||||
document.getElementById("inviteimg").append(img);
|
document.getElementById("inviteimg").append(img);
|
||||||
}else{
|
}else{
|
||||||
const txt=guildjson.name.replace(/'s /g, " ").replace(/\w+/g, word => word[0]).replace(/\s/g, "");
|
const txt=guildjson.name.replace(/'s /g, " ").replace(/\w+/g, word=>word[0]).replace(/\s/g, "");
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
div.textContent=txt;
|
div.textContent=txt;
|
||||||
div.classList.add("inviteGuild");
|
div.classList.add("inviteGuild");
|
||||||
document.getElementById("inviteimg").append(div);
|
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");
|
||||||
function showAccounts(){
|
userinfo.classList.add("flexltr","switchtable");
|
||||||
const table=document.createElement("dialog");
|
const pfp=document.createElement("img");
|
||||||
for(const thing of Object.values(joinable)){
|
userinfo.append(pfp);
|
||||||
const specialuser=thing as Specialuser;
|
|
||||||
console.log(specialuser.pfpsrc)
|
|
||||||
|
|
||||||
const userinfo=document.createElement("div");
|
const user=document.createElement("div");
|
||||||
userinfo.classList.add("flexltr","switchtable");
|
userinfo.append(user);
|
||||||
const pfp=document.createElement("img");
|
user.append(specialuser.username);
|
||||||
userinfo.append(pfp);
|
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");
|
||||||
|
|
||||||
const user=document.createElement("div");
|
pfp.src=specialuser.pfpsrc;
|
||||||
userinfo.append(user);
|
pfp.classList.add("pfp");
|
||||||
user.append(specialuser.username);
|
table.append(userinfo);
|
||||||
user.append(document.createElement("br"));
|
userinfo.addEventListener("click",_=>{
|
||||||
const span=document.createElement("span");
|
console.log(thing);
|
||||||
span.textContent=specialuser.serverurls.wellknown.replace("https://","").replace("http://","");
|
fetch(`${urls.api}/invites/${code}`,{
|
||||||
user.append(span);
|
method: "POST",
|
||||||
user.classList.add("userinfo")
|
headers: {
|
||||||
span.classList.add("serverURL")
|
Authorization: thing.token
|
||||||
|
}
|
||||||
pfp.src=specialuser.pfpsrc;
|
}).then(_=>{
|
||||||
pfp.classList.add("pfp");
|
users.currentuser=specialuser.uid;
|
||||||
table.append(userinfo);
|
localStorage.setItem("userinfos",JSON.stringify(users));
|
||||||
userinfo.addEventListener("click",_=>{
|
window.location.href="/channels/"+guildinfo.id;
|
||||||
console.log(thing);
|
});
|
||||||
fetch(`${urls.api}/invites/${code}`,{
|
});
|
||||||
method:"POST",
|
}
|
||||||
headers:{
|
{
|
||||||
Authorization:thing.token
|
const td=document.createElement("div");
|
||||||
}
|
td.classList.add("switchtable");
|
||||||
}).then(_=>{
|
td.append("Login or create an account ⇌");
|
||||||
users["currentuser"]=specialuser.uid;
|
td.addEventListener("click",_=>{
|
||||||
localStorage.setItem("userinfos",JSON.stringify(users));
|
const l=new URLSearchParams("?");
|
||||||
window.location.href="/channels/"+guildinfo.id;
|
l.set("goback",window.location.href);
|
||||||
})
|
l.set("instance",well);
|
||||||
})
|
window.location.href="/login?"+l.toString();
|
||||||
}
|
});
|
||||||
{
|
if(!joinable.length){
|
||||||
const td=document.createElement("div");
|
const l=new URLSearchParams("?");
|
||||||
td.classList.add("switchtable")
|
l.set("goback",window.location.href);
|
||||||
td.append("Login or create an account ⇌");
|
l.set("instance",well);
|
||||||
td.addEventListener("click",_=>{
|
window.location.href="/login?"+l.toString();
|
||||||
const l=new URLSearchParams("?")
|
}
|
||||||
l.set("goback",window.location.href);
|
table.append(td);
|
||||||
l.set("instance",well);
|
}
|
||||||
window.location.href="/login?"+l.toString();
|
table.classList.add("accountSwitcher");
|
||||||
})
|
console.log(table);
|
||||||
if(!joinable.length){
|
document.body.append(table);
|
||||||
const l=new URLSearchParams("?")
|
}
|
||||||
l.set("goback",window.location.href);
|
document.getElementById("AcceptInvite").addEventListener("click",showAccounts);
|
||||||
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,6 @@
|
||||||
type readyjson={
|
type readyjson={
|
||||||
op:number;
|
op:0;
|
||||||
t:string;
|
t:"READY";
|
||||||
s:number;
|
s:number;
|
||||||
d:{
|
d:{
|
||||||
v:number;
|
v:number;
|
||||||
|
@ -341,4 +341,59 @@ type presencejson={
|
||||||
afk: boolean,
|
afk: boolean,
|
||||||
user?:userjson,
|
user?:userjson,
|
||||||
}
|
}
|
||||||
export {readyjson,dirrectjson,channeljson,guildjson,rolesjson,userjson,memberjson,mainuserjson,messagejson,filejson,embedjson,emojijson,presencejson};
|
type messageCreateJson={
|
||||||
|
op:0,
|
||||||
|
d:{
|
||||||
|
guild_id?:string,
|
||||||
|
channel_id?:string,
|
||||||
|
}&messagejson,
|
||||||
|
s:number,
|
||||||
|
t:"MESSAGE_CREATE"
|
||||||
|
}
|
||||||
|
type wsjson={
|
||||||
|
op:0,
|
||||||
|
d:any,
|
||||||
|
s:number,
|
||||||
|
t:"TYPING_START"|"USER_UPDATE"|"CHANNEL_UPDATE"|"CHANNEL_CREATE"|"CHANNEL_DELETE"|"GUILD_DELETE"|"GUILD_CREATE"|"MESSAGE_REACTION_ADD"|"MESSAGE_REACTION_REMOVE"|"MESSAGE_REACTION_REMOVE_ALL"|"MESSAGE_REACTION_REMOVE_EMOJI"
|
||||||
|
}|{
|
||||||
|
op:0,
|
||||||
|
t:"GUILD_MEMBERS_CHUNK",
|
||||||
|
d:memberChunk
|
||||||
|
}|{
|
||||||
|
op:0,
|
||||||
|
d:{
|
||||||
|
id:string,
|
||||||
|
guild_id?:string,
|
||||||
|
channel_id:string
|
||||||
|
},
|
||||||
|
s:number,
|
||||||
|
t:"MESSAGE_DELETE"
|
||||||
|
}|{
|
||||||
|
op:0,
|
||||||
|
d:{
|
||||||
|
guild_id?:string,
|
||||||
|
channel_id:string
|
||||||
|
}&messagejson,
|
||||||
|
s:number,
|
||||||
|
t:"MESSAGE_UPDATE"
|
||||||
|
}|messageCreateJson|readyjson|{
|
||||||
|
op:11,
|
||||||
|
s:undefined,
|
||||||
|
d:{}
|
||||||
|
}|{
|
||||||
|
op:10,
|
||||||
|
s:undefined,
|
||||||
|
d:{
|
||||||
|
heartbeat_interval:number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
type memberChunk={
|
||||||
|
guild_id: string,
|
||||||
|
nonce: string,
|
||||||
|
members: memberjson[],
|
||||||
|
presences: presencejson[],
|
||||||
|
chunk_index: number,
|
||||||
|
chunk_count: number,
|
||||||
|
not_found: string[]
|
||||||
|
}
|
||||||
|
export{readyjson,dirrectjson,channeljson,guildjson,rolesjson,userjson,memberjson,mainuserjson,messagejson,filejson,embedjson,emojijson,presencejson,wsjson,messageCreateJson,memberChunk};
|
||||||
|
|
2873
webpage/localuser.ts
2873
webpage/localuser.ts
File diff suppressed because it is too large
Load diff
|
@ -1,36 +1,36 @@
|
||||||
<body class="Dark-theme">
|
<body class="Dark-theme">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Jank Client</title>
|
<title>Jank Client</title>
|
||||||
<meta content="Jank Client" property="og:title" />
|
<meta content="Jank Client" property="og:title">
|
||||||
<meta content="A spacebar client that has DMs, replying and more" property="og:description" />
|
<meta content="A spacebar client that has DMs, replying and more" property="og:description">
|
||||||
<meta content="/logo.webp" property="og:image" />
|
<meta content="/logo.webp" property="og:image">
|
||||||
<meta content="#4b458c" data-react-helmet="true" name="theme-color" />
|
<meta content="#4b458c" data-react-helmet="true" name="theme-color">
|
||||||
<link href="/style.css" rel="stylesheet" type="text/css" />
|
<link href="/style.css" rel="stylesheet">
|
||||||
<link href="/themes.css" rel="stylesheet" type="text/css" id="lightcss"/>
|
<link href="/themes.css" rel="stylesheet" id="lightcss">
|
||||||
</head>
|
</head>
|
||||||
<div id="logindiv">
|
<div id="logindiv">
|
||||||
<h1>Login</h1><br>
|
<h1>Login</h1><br>
|
||||||
<form id="form" submit="check(e)">
|
<form id="form" submit="check(e)">
|
||||||
<label for="instance"><b>Instance:</b></label><br>
|
<label for="instance"><b>Instance:</b></label><br>
|
||||||
<p id="verify"></p>
|
<p id="verify"></p>
|
||||||
<input type="search" list="instances" placeholder="Instance URL" name="instance" id="instancein" value="" id="instancein" required><br><br>
|
<input type="search" list="instances" placeholder="Instance URL" name="instance" id="instancein" value="" id="instancein" required><br><br>
|
||||||
|
|
||||||
<label for="uname"><b>Email:</b></label><br>
|
<label for="uname"><b>Email:</b></label><br>
|
||||||
<input type="text" placeholder="Enter email address" name="uname" id="uname" required><br><br>
|
<input type="text" placeholder="Enter email address" name="uname" id="uname" required><br><br>
|
||||||
|
|
||||||
<label for="psw"><b>Password:</b></label><br>
|
<label for="psw"><b>Password:</b></label><br>
|
||||||
<input type="password" placeholder="Enter Password" name="psw" id="psw" required><br><br><br><br>
|
<input type="password" placeholder="Enter Password" name="psw" id="psw" required><br><br><br><br>
|
||||||
<p class="wrongred" id="wrong"></p>
|
<p class="wrongred" id="wrong"></p>
|
||||||
|
|
||||||
<div id="h-captcha">
|
<div id="h-captcha">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<button type="submit">Login</button>
|
<button type="submit">Login</button>
|
||||||
</form>
|
</form>
|
||||||
<a href="/register.html" id="switch">Don't have an account?</a>
|
<a href="/register.html" id="switch">Don't have an account?</a>
|
||||||
</div>
|
</div>
|
||||||
<datalist id="instances"></datalist>
|
<datalist id="instances"></datalist>
|
||||||
<script src="/login.js" type="module" ></script>
|
<script src="/login.js" type="module"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
718
webpage/login.ts
718
webpage/login.ts
|
@ -1,366 +1,362 @@
|
||||||
import { Dialog } from "./dialog.js";
|
import{ Dialog }from"./dialog.js";
|
||||||
|
|
||||||
const mobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
const mobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
||||||
|
|
||||||
function setTheme(){
|
function setTheme(){
|
||||||
let name=localStorage.getItem("theme");
|
let name=localStorage.getItem("theme");
|
||||||
if(!name){
|
if(!name){
|
||||||
localStorage.setItem("theme","Dark");
|
localStorage.setItem("theme","Dark");
|
||||||
name="Dark";
|
name="Dark";
|
||||||
}
|
}
|
||||||
document.body.className=name+"-theme";
|
document.body.className=name+"-theme";
|
||||||
}
|
}
|
||||||
setTheme();
|
setTheme();
|
||||||
function getBulkUsers(){
|
function getBulkUsers(){
|
||||||
const json=getBulkInfo()
|
const json=getBulkInfo();
|
||||||
for(const thing in json.users){
|
for(const thing in json.users){
|
||||||
json.users[thing]=new Specialuser(json.users[thing]);
|
json.users[thing]=new Specialuser(json.users[thing]);
|
||||||
}
|
}
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
function trimswitcher(){
|
function trimswitcher(){
|
||||||
const json=getBulkInfo()
|
const json=getBulkInfo();
|
||||||
const map=new Map();
|
const map=new Map();
|
||||||
for(const thing in json.users){
|
for(const thing in json.users){
|
||||||
const user=json.users[thing];
|
const user=json.users[thing];
|
||||||
let wellknown=user.serverurls.wellknown;
|
let wellknown=user.serverurls.wellknown;
|
||||||
if(wellknown[wellknown.length-1]!=="/"){
|
if(wellknown.at(-1)!=="/"){
|
||||||
wellknown+="/";
|
wellknown+="/";
|
||||||
}
|
}
|
||||||
wellknown+=user.username;
|
wellknown+=user.username;
|
||||||
if(map.has(wellknown)){
|
if(map.has(wellknown)){
|
||||||
const otheruser=map.get(wellknown);
|
const otheruser=map.get(wellknown);
|
||||||
if(otheruser[1].serverurls.wellknown[otheruser[1].serverurls.wellknown.length-1]==="/"){
|
if(otheruser[1].serverurls.wellknown.at(-1)==="/"){
|
||||||
delete json.users[otheruser[0]];
|
delete json.users[otheruser[0]];
|
||||||
map.set(wellknown,[thing,user]);
|
map.set(wellknown,[thing,user]);
|
||||||
}else{
|
}else{
|
||||||
delete json.users[thing];
|
delete json.users[thing];
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
map.set(wellknown,[thing,user]);
|
map.set(wellknown,[thing,user]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(const thing in json.users){
|
for(const thing in json.users){
|
||||||
if(thing[thing.length-1]==="/"){
|
if(thing.at(-1)==="/"){
|
||||||
const user=json.users[thing];
|
const user=json.users[thing];
|
||||||
delete json.users[thing];
|
delete json.users[thing];
|
||||||
json.users[thing.slice(0, -1)]=user;
|
json.users[thing.slice(0, -1)]=user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
localStorage.setItem("userinfos",JSON.stringify(json));
|
localStorage.setItem("userinfos",JSON.stringify(json));
|
||||||
console.log(json);
|
console.log(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBulkInfo(){
|
function getBulkInfo(){
|
||||||
return JSON.parse(localStorage.getItem("userinfos"));
|
return JSON.parse(localStorage.getItem("userinfos"));
|
||||||
}
|
}
|
||||||
function setDefaults(){
|
function setDefaults(){
|
||||||
let userinfos=getBulkInfo();
|
let userinfos=getBulkInfo();
|
||||||
if(!userinfos){
|
if(!userinfos){
|
||||||
localStorage.setItem("userinfos",JSON.stringify({
|
localStorage.setItem("userinfos",JSON.stringify({
|
||||||
currentuser:null,
|
currentuser: null,
|
||||||
users:{},
|
users: {},
|
||||||
preferences:
|
preferences:
|
||||||
{
|
{
|
||||||
theme:"Dark",
|
theme: "Dark",
|
||||||
notifications:false,
|
notifications: false,
|
||||||
notisound:"three",
|
notisound: "three",
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
userinfos=getBulkInfo();
|
userinfos=getBulkInfo();
|
||||||
}
|
}
|
||||||
if(userinfos.users===undefined){
|
if(userinfos.users===undefined){
|
||||||
userinfos.users={};
|
userinfos.users={};
|
||||||
}
|
}
|
||||||
if(userinfos.accent_color===undefined){
|
if(userinfos.accent_color===undefined){
|
||||||
userinfos.accent_color="#242443";
|
userinfos.accent_color="#242443";
|
||||||
}
|
}
|
||||||
document.documentElement.style.setProperty('--accent-color', userinfos.accent_color);
|
document.documentElement.style.setProperty("--accent-color", userinfos.accent_color);
|
||||||
if(userinfos.preferences===undefined){
|
if(userinfos.preferences===undefined){
|
||||||
userinfos.preferences={
|
userinfos.preferences={
|
||||||
theme:"Dark",
|
theme: "Dark",
|
||||||
notifications:false,
|
notifications: false,
|
||||||
notisound:"three",
|
notisound: "three",
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
if(userinfos.preferences&&(userinfos.preferences.notisound===undefined)){
|
if(userinfos.preferences&&(userinfos.preferences.notisound===undefined)){
|
||||||
userinfos.preferences.notisound="three";
|
userinfos.preferences.notisound="three";
|
||||||
}
|
}
|
||||||
localStorage.setItem("userinfos",JSON.stringify(userinfos))
|
localStorage.setItem("userinfos",JSON.stringify(userinfos));
|
||||||
}
|
}
|
||||||
setDefaults();
|
setDefaults();
|
||||||
class Specialuser{
|
class Specialuser{
|
||||||
serverurls:{api:string,cdn:string,gateway:string,wellknown:string,login:string};
|
serverurls:{api:string,cdn:string,gateway:string,wellknown:string,login:string};
|
||||||
email:string;
|
email:string;
|
||||||
token:string;
|
token:string;
|
||||||
loggedin;
|
loggedin;
|
||||||
json;
|
json;
|
||||||
constructor(json){
|
constructor(json){
|
||||||
if(json instanceof Specialuser){
|
if(json instanceof Specialuser){
|
||||||
console.error("specialuser can't construct from another specialuser");
|
console.error("specialuser can't construct from another specialuser");
|
||||||
}
|
}
|
||||||
this.serverurls=json.serverurls;
|
this.serverurls=json.serverurls;
|
||||||
let apistring=new URL(json.serverurls.api).toString();
|
let apistring=new URL(json.serverurls.api).toString();
|
||||||
apistring=apistring.replace(/\/(v\d+\/?)?$/, "")+"/v9";
|
apistring=apistring.replace(/\/(v\d+\/?)?$/, "")+"/v9";
|
||||||
this.serverurls.api=apistring;
|
this.serverurls.api=apistring;
|
||||||
this.serverurls.cdn=new URL(json.serverurls.cdn).toString().replace(/\/$/,"");
|
this.serverurls.cdn=new URL(json.serverurls.cdn).toString().replace(/\/$/,"");
|
||||||
this.serverurls.gateway=new URL(json.serverurls.gateway).toString().replace(/\/$/,"");;
|
this.serverurls.gateway=new URL(json.serverurls.gateway).toString().replace(/\/$/,"");
|
||||||
this.serverurls.wellknown=new URL(json.serverurls.wellknown).toString().replace(/\/$/,"");;
|
this.serverurls.wellknown=new URL(json.serverurls.wellknown).toString().replace(/\/$/,"");
|
||||||
this.serverurls.login=new URL(json.serverurls.login).toString().replace(/\/$/,"");;
|
this.serverurls.login=new URL(json.serverurls.login).toString().replace(/\/$/,"");
|
||||||
this.email=json.email;
|
this.email=json.email;
|
||||||
this.token=json.token;
|
this.token=json.token;
|
||||||
this.loggedin=json.loggedin;
|
this.loggedin=json.loggedin;
|
||||||
this.json=json;
|
this.json=json;
|
||||||
if(!this.serverurls||!this.email||!this.token){
|
if(!this.serverurls||!this.email||!this.token){
|
||||||
console.error("There are fundamentally missing pieces of info missing from this user");
|
console.error("There are fundamentally missing pieces of info missing from this user");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set pfpsrc(e){
|
set pfpsrc(e){
|
||||||
console.log("this ran fr")
|
console.log("this ran fr");
|
||||||
this.json.pfpsrc=e;
|
this.json.pfpsrc=e;
|
||||||
this.updateLocal();
|
this.updateLocal();
|
||||||
}
|
}
|
||||||
get pfpsrc(){
|
get pfpsrc(){
|
||||||
return this.json.pfpsrc;
|
return this.json.pfpsrc;
|
||||||
}
|
}
|
||||||
set username(e){
|
set username(e){
|
||||||
this.json.username=e;
|
this.json.username=e;
|
||||||
this.updateLocal();
|
this.updateLocal();
|
||||||
}
|
}
|
||||||
get username(){
|
get username(){
|
||||||
return this.json.username;
|
return this.json.username;
|
||||||
}
|
}
|
||||||
get uid(){
|
get uid(){
|
||||||
return this.email+this.serverurls.wellknown;
|
return this.email+this.serverurls.wellknown;
|
||||||
}
|
}
|
||||||
toJSON(){
|
toJSON(){
|
||||||
return this.json;
|
return this.json;
|
||||||
}
|
}
|
||||||
updateLocal(){
|
updateLocal(){
|
||||||
const info=getBulkInfo();
|
const info=getBulkInfo();
|
||||||
info.users[this.uid]=this.toJSON();
|
info.users[this.uid]=this.toJSON();
|
||||||
localStorage.setItem("userinfos",JSON.stringify(info));
|
localStorage.setItem("userinfos",JSON.stringify(info));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function adduser(user){
|
function adduser(user){
|
||||||
user=new Specialuser(user);
|
user=new Specialuser(user);
|
||||||
const info=getBulkInfo();
|
const info=getBulkInfo();
|
||||||
info.users[user.uid]=user;
|
info.users[user.uid]=user;
|
||||||
info.currentuser=user.uid;
|
info.currentuser=user.uid;
|
||||||
localStorage.setItem("userinfos",JSON.stringify(info));
|
localStorage.setItem("userinfos",JSON.stringify(info));
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
const instancein=document.getElementById("instancein") as HTMLInputElement;
|
const instancein=document.getElementById("instancein") as HTMLInputElement;
|
||||||
let timeout;
|
let timeout;
|
||||||
let instanceinfo;
|
let instanceinfo;
|
||||||
const stringURLMap=new Map<string,string>();
|
const stringURLMap=new Map<string,string>();
|
||||||
|
|
||||||
const stringURLsMap=new Map<string,{wellknown:string,api:string,cdn:string,gateway:string,login?:string}>();
|
const stringURLsMap=new Map<string,{wellknown:string,api:string,cdn:string,gateway:string,login?:string}>();
|
||||||
async function getapiurls(str:string):Promise<{api:string,cdn:string,gateway:string,wellknown:string,login:string}|false>{
|
async function getapiurls(str:string):Promise<{api:string,cdn:string,gateway:string,wellknown:string,login:string}|false>{
|
||||||
if(!URL.canParse(str)){
|
if(!URL.canParse(str)){
|
||||||
const val=stringURLMap.get(str);
|
const val=stringURLMap.get(str);
|
||||||
if(val){
|
if(val){
|
||||||
str=val;
|
str=val;
|
||||||
}else{
|
}else{
|
||||||
const val=stringURLsMap.get(str)
|
const val=stringURLsMap.get(str);
|
||||||
if(val){
|
if(val){
|
||||||
const responce=await fetch(val.api+val.api.endsWith("/")?"":"/"+"ping");
|
const responce=await fetch(val.api+val.api.endsWith("/")?"":"/"+"ping");
|
||||||
if(responce.ok){
|
if(responce.ok){
|
||||||
if(val.login){
|
if(val.login){
|
||||||
return val as {wellknown:string,api:string,cdn:string,gateway:string,login:string};
|
return val as {wellknown:string,api:string,cdn:string,gateway:string,login:string};
|
||||||
}else{
|
}else{
|
||||||
val.login=val.api;
|
val.login=val.api;
|
||||||
return val as {wellknown:string,api:string,cdn:string,gateway:string,login:string};
|
return val as {wellknown:string,api:string,cdn:string,gateway:string,login:string};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if(str.at(-1)!=="/"){
|
||||||
if(str[str.length-1]!=="/"){
|
str+="/";
|
||||||
str+="/"
|
}
|
||||||
}
|
let api:string;
|
||||||
let api:string;
|
try{
|
||||||
try{
|
const info=await fetch(`${str}/.well-known/spacebar`).then(x=>x.json());
|
||||||
const info=await fetch(`${str}/.well-known/spacebar`).then((x) => x.json());
|
api=info.api;
|
||||||
api=info.api;
|
}catch{
|
||||||
}catch{
|
return false;
|
||||||
return false
|
}
|
||||||
}
|
const url = new URL(api);
|
||||||
const url = new URL(api);
|
try{
|
||||||
try{
|
const info=await fetch(`${api}${url.pathname.includes("api") ? "" : "api"}/policies/instance/domains`).then(x=>x.json());
|
||||||
|
return{
|
||||||
const info=await fetch(`${api}${url.pathname.includes("api") ? "" : "api"}/policies/instance/domains`).then((x) => x.json());
|
api: info.apiEndpoint,
|
||||||
return {
|
gateway: info.gateway,
|
||||||
api: info.apiEndpoint,
|
cdn: info.cdn,
|
||||||
gateway: info.gateway,
|
wellknown: str,
|
||||||
cdn: info.cdn,
|
login: url.toString()
|
||||||
wellknown: str,
|
};
|
||||||
login:url.toString()
|
}catch{
|
||||||
};
|
const val=stringURLsMap.get(str);
|
||||||
}catch{
|
if(val){
|
||||||
const val=stringURLsMap.get(str)
|
const responce=await fetch(val.api+val.api.endsWith("/")?"":"/"+"ping");
|
||||||
if(val){
|
if(responce.ok){
|
||||||
const responce=await fetch(val.api+val.api.endsWith("/")?"":"/"+"ping");
|
if(val.login){
|
||||||
if(responce.ok){
|
return val as {wellknown:string,api:string,cdn:string,gateway:string,login:string};
|
||||||
if(val.login){
|
}else{
|
||||||
return val as {wellknown:string,api:string,cdn:string,gateway:string,login:string};
|
val.login=val.api;
|
||||||
}else{
|
return val as {wellknown:string,api:string,cdn:string,gateway:string,login:string};
|
||||||
val.login=val.api;
|
}
|
||||||
return val as {wellknown:string,api:string,cdn:string,gateway:string,login:string};
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
async function checkInstance(e:string){
|
async function checkInstance(e:string){
|
||||||
const verify=document.getElementById("verify");
|
const verify=document.getElementById("verify");
|
||||||
try{
|
try{
|
||||||
verify.textContent="Checking Instance";
|
verify.textContent="Checking Instance";
|
||||||
const instanceinfo=await getapiurls((instancein as HTMLInputElement).value) as {wellknown:string,api:string,cdn:string,gateway:string,login:string, value:string};
|
const instanceinfo=await getapiurls((instancein as HTMLInputElement).value) as {wellknown:string,api:string,cdn:string,gateway:string,login:string, value:string};
|
||||||
if(instanceinfo){
|
if(instanceinfo){
|
||||||
instanceinfo.value=(instancein as HTMLInputElement).value;
|
instanceinfo.value=(instancein as HTMLInputElement).value;
|
||||||
localStorage.setItem("instanceinfo",JSON.stringify(instanceinfo));
|
localStorage.setItem("instanceinfo",JSON.stringify(instanceinfo));
|
||||||
verify.textContent="Instance is all good"
|
verify.textContent="Instance is all good";
|
||||||
if(checkInstance["alt"]){checkInstance["alt"]();}
|
if(checkInstance.alt){
|
||||||
setTimeout(_=>{
|
checkInstance.alt();
|
||||||
console.log(verify.textContent)
|
}
|
||||||
verify.textContent="";
|
setTimeout(_=>{
|
||||||
},3000);
|
console.log(verify.textContent);
|
||||||
}else{
|
verify.textContent="";
|
||||||
verify.textContent="Invalid Instance, try again"
|
},3000);
|
||||||
}
|
}else{
|
||||||
}catch(e){
|
verify.textContent="Invalid Instance, try again";
|
||||||
console.log("catch")
|
}
|
||||||
verify.textContent="Invalid Instance, try again"
|
}catch{
|
||||||
}
|
console.log("catch");
|
||||||
|
verify.textContent="Invalid Instance, try again";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(instancein){
|
if(instancein){
|
||||||
console.log(instancein)
|
console.log(instancein);
|
||||||
instancein.addEventListener("keydown",e=>{
|
instancein.addEventListener("keydown",e=>{
|
||||||
const verify=document.getElementById("verify");
|
const verify=document.getElementById("verify");
|
||||||
verify.textContent="Waiting to check Instance"
|
verify.textContent="Waiting to check Instance";
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout=setTimeout(checkInstance,1000);
|
timeout=setTimeout(checkInstance,1000);
|
||||||
});
|
});
|
||||||
if(localStorage.getItem("instanceinfo")){
|
if(localStorage.getItem("instanceinfo")){
|
||||||
const json=JSON.parse(localStorage.getItem("instanceinfo"));
|
const json=JSON.parse(localStorage.getItem("instanceinfo"));
|
||||||
if(json.value){
|
if(json.value){
|
||||||
(instancein as HTMLInputElement).value=json.value
|
(instancein as HTMLInputElement).value=json.value;
|
||||||
}else{
|
}else{
|
||||||
(instancein as HTMLInputElement).value=json.wellknown
|
(instancein as HTMLInputElement).value=json.wellknown;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
checkInstance("https://spacebar.chat/");
|
checkInstance("https://spacebar.chat/");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function login(username:string, password:string, captcha:string){
|
async function login(username:string, password:string, captcha:string){
|
||||||
if(captcha===""){
|
if(captcha===""){
|
||||||
captcha=undefined;
|
captcha=undefined;
|
||||||
}
|
}
|
||||||
const options={
|
const options={
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body:JSON.stringify({
|
body: JSON.stringify({
|
||||||
"login": username,
|
login: username,
|
||||||
"password": password,
|
password,
|
||||||
"undelete":false,
|
undelete: false,
|
||||||
"captcha_key":captcha
|
captcha_key: captcha
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-type": "application/json; charset=UTF-8",
|
"Content-type": "application/json; charset=UTF-8",
|
||||||
}}
|
}};
|
||||||
try{
|
try{
|
||||||
const info=JSON.parse(localStorage.getItem("instanceinfo"));
|
const info=JSON.parse(localStorage.getItem("instanceinfo"));
|
||||||
const api=info.login+(info.login.startsWith("/")?"/":"");
|
const api=info.login+(info.login.startsWith("/")?"/":"");
|
||||||
return await fetch(api+'/auth/login',options).then(response=>response.json())
|
return await fetch(api+"/auth/login",options).then(response=>response.json())
|
||||||
.then((response) => {
|
.then(response=>{
|
||||||
console.log(response,response.message)
|
console.log(response,response.message);
|
||||||
if("Invalid Form Body"===response.message){
|
if(response.message==="Invalid Form Body"){
|
||||||
return response.errors.login._errors[0].message;
|
return response.errors.login._errors[0].message;
|
||||||
console.log("test")
|
console.log("test");
|
||||||
}
|
}
|
||||||
//this.serverurls||!this.email||!this.token
|
//this.serverurls||!this.email||!this.token
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
|
||||||
if(response.captcha_sitekey){
|
if(response.captcha_sitekey){
|
||||||
|
const capt=document.getElementById("h-captcha");
|
||||||
|
if(!capt.children.length){
|
||||||
|
const capty=document.createElement("div");
|
||||||
|
capty.classList.add("h-captcha");
|
||||||
|
|
||||||
const capt=document.getElementById("h-captcha");
|
capty.setAttribute("data-sitekey", response.captcha_sitekey);
|
||||||
if(!capt.children.length){
|
const script=document.createElement("script");
|
||||||
const capty=document.createElement("div");
|
script.src="https://js.hcaptcha.com/1/api.js";
|
||||||
capty.classList.add("h-captcha");
|
capt.append(script);
|
||||||
|
capt.append(capty);
|
||||||
capty.setAttribute("data-sitekey", response.captcha_sitekey);
|
}else{
|
||||||
const script=document.createElement("script");
|
eval("hcaptcha.reset()");
|
||||||
script.src="https://js.hcaptcha.com/1/api.js";
|
}
|
||||||
capt.append(script);
|
}else{
|
||||||
capt.append(capty);
|
console.log(response);
|
||||||
}else{
|
if(response.ticket){
|
||||||
eval("hcaptcha.reset()");
|
let onetimecode="";
|
||||||
}
|
new Dialog(["vdiv",["title","2FA code:"],["textbox","","",function(this:HTMLInputElement){
|
||||||
return;
|
onetimecode=this.value;
|
||||||
}else{
|
}],["button","","Submit",function(){
|
||||||
console.log(response);
|
fetch(api+"/auth/mfa/totp",{
|
||||||
if(response.ticket){
|
method: "POST",
|
||||||
let onetimecode="";
|
headers: {
|
||||||
new Dialog(["vdiv",["title","2FA code:"],["textbox","","",function(this:HTMLInputElement){onetimecode=this.value}],["button","","Submit",function(){
|
"Content-Type": "application/json"
|
||||||
fetch(api+"/auth/mfa/totp",{
|
},
|
||||||
method:"POST",
|
body: JSON.stringify({
|
||||||
headers:{
|
code: onetimecode,
|
||||||
"Content-Type": "application/json"
|
ticket: response.ticket,
|
||||||
},
|
})
|
||||||
body:JSON.stringify({
|
}).then(r=>r.json()).then(response=>{
|
||||||
code:onetimecode,
|
if(response.message){
|
||||||
ticket:response.ticket,
|
alert(response.message);
|
||||||
})
|
}else{
|
||||||
}).then(r=>r.json()).then(response=>{
|
console.warn(response);
|
||||||
if(response.message){
|
if(!response.token)return;
|
||||||
alert(response.message)
|
adduser({serverurls: JSON.parse(localStorage.getItem("instanceinfo")),email: username,token: response.token}).username=username;
|
||||||
}else{
|
const redir=new URLSearchParams(window.location.search).get("goback");
|
||||||
console.warn(response);
|
if(redir){
|
||||||
if(!response.token) return;
|
window.location.href = redir;
|
||||||
adduser({serverurls:JSON.parse(localStorage.getItem("instanceinfo")),email:username,token:response.token}).username=username;
|
}else{
|
||||||
const redir=new URLSearchParams(window.location.search).get("goback");
|
window.location.href = "/channels/@me";
|
||||||
if(redir){
|
}
|
||||||
window.location.href = redir;
|
}
|
||||||
}else{
|
});
|
||||||
window.location.href = '/channels/@me';
|
}]]).show();
|
||||||
}
|
}else{
|
||||||
}
|
console.warn(response);
|
||||||
})
|
if(!response.token)return;
|
||||||
}]]).show();
|
adduser({serverurls: JSON.parse(localStorage.getItem("instanceinfo")),email: username,token: response.token}).username=username;
|
||||||
}else{
|
const redir=new URLSearchParams(window.location.search).get("goback");
|
||||||
console.warn(response);
|
if(redir){
|
||||||
if(!response.token) return;
|
window.location.href = redir;
|
||||||
adduser({serverurls:JSON.parse(localStorage.getItem("instanceinfo")),email:username,token:response.token}).username=username;
|
}else{
|
||||||
const redir=new URLSearchParams(window.location.search).get("goback");
|
window.location.href = "/channels/@me";
|
||||||
if(redir){
|
}
|
||||||
window.location.href = redir;
|
return"";
|
||||||
}else{
|
}
|
||||||
window.location.href = '/channels/@me';
|
}
|
||||||
}
|
});
|
||||||
return "";
|
}catch(error){
|
||||||
}
|
console.error("Error:", error);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}catch(error){
|
|
||||||
console.error('Error:', error);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function check(e){
|
async function check(e){
|
||||||
|
e.preventDefault();
|
||||||
e.preventDefault();
|
const h=await login(e.srcElement[1].value,e.srcElement[2].value,e.srcElement[3].value);
|
||||||
let h=await login(e.srcElement[1].value,e.srcElement[2].value,e.srcElement[3].value);
|
document.getElementById("wrong").textContent=h;
|
||||||
document.getElementById("wrong").textContent=h;
|
console.log(h);
|
||||||
console.log(h);
|
|
||||||
}
|
}
|
||||||
if(document.getElementById("form")){
|
if(document.getElementById("form")){
|
||||||
document.getElementById("form").addEventListener("submit", check);
|
document.getElementById("form").addEventListener("submit", check);
|
||||||
}
|
}
|
||||||
//this currently does not work, and need to be implemented better at some time.
|
//this currently does not work, and need to be implemented better at some time.
|
||||||
/*
|
/*
|
||||||
|
@ -390,50 +386,50 @@ if ("serviceWorker" in navigator){
|
||||||
*/
|
*/
|
||||||
const switchurl=document.getElementById("switch") as HTMLAreaElement;
|
const switchurl=document.getElementById("switch") as HTMLAreaElement;
|
||||||
if(switchurl){
|
if(switchurl){
|
||||||
switchurl.href+=window.location.search;
|
switchurl.href+=window.location.search;
|
||||||
const instance=new URLSearchParams(window.location.search).get("instance");
|
const instance=new URLSearchParams(window.location.search).get("instance");
|
||||||
console.log(instance);
|
console.log(instance);
|
||||||
if(instance){
|
if(instance){
|
||||||
instancein.value=instance;
|
instancein.value=instance;
|
||||||
checkInstance("");
|
checkInstance("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export {checkInstance};
|
export{checkInstance};
|
||||||
trimswitcher();
|
trimswitcher();
|
||||||
export {mobile, getBulkUsers,getBulkInfo,setTheme,Specialuser,getapiurls,adduser}
|
export{mobile, getBulkUsers,getBulkInfo,setTheme,Specialuser,getapiurls,adduser};
|
||||||
|
|
||||||
const datalist=document.getElementById("instances");
|
const datalist=document.getElementById("instances");
|
||||||
console.warn(datalist);
|
console.warn(datalist);
|
||||||
if(datalist){
|
if(datalist){
|
||||||
fetch("/instances.json").then(_=>_.json()).then((json:{name:string,online:boolean,description?:string,src?:string,url?:string,display?:boolean,urls:{wellknown:string,api:string,cdn:string,gateway:string,login?:string}}[])=>{
|
fetch("/instances.json").then(_=>_.json()).then((json:{name:string,online:boolean,description?:string,src?:string,url?:string,display?:boolean,urls:{wellknown:string,api:string,cdn:string,gateway:string,login?:string}}[])=>{
|
||||||
console.warn(json);
|
console.warn(json);
|
||||||
if(instancein&&instancein.value===""){
|
if(instancein&&instancein.value===""){
|
||||||
instancein.value=json[0].name;
|
instancein.value=json[0].name;
|
||||||
}
|
}
|
||||||
for(const instance of json){
|
for(const instance of json){
|
||||||
if(instance.display===false){
|
if(instance.display===false){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const option=document.createElement("option");
|
const option=document.createElement("option");
|
||||||
option.disabled=!instance.online;
|
option.disabled=!instance.online;
|
||||||
option.value=instance.name;
|
option.value=instance.name;
|
||||||
if(instance.url){
|
if(instance.url){
|
||||||
stringURLMap.set(option.value,instance.url);
|
stringURLMap.set(option.value,instance.url);
|
||||||
if(instance.urls){
|
if(instance.urls){
|
||||||
stringURLsMap.set(instance.url,instance.urls);
|
stringURLsMap.set(instance.url,instance.urls);
|
||||||
}
|
}
|
||||||
}else if(instance.urls){
|
}else if(instance.urls){
|
||||||
stringURLsMap.set(option.value,instance.urls);
|
stringURLsMap.set(option.value,instance.urls);
|
||||||
}else{
|
}else{
|
||||||
option.disabled=true;
|
option.disabled=true;
|
||||||
}
|
}
|
||||||
if(instance.description){
|
if(instance.description){
|
||||||
option.label=instance.description;
|
option.label=instance.description;
|
||||||
}else{
|
}else{
|
||||||
option.label=instance.name;
|
option.label=instance.name;
|
||||||
}
|
}
|
||||||
datalist.append(option);
|
datalist.append(option);
|
||||||
}
|
}
|
||||||
checkInstance("");
|
checkInstance("");
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
1099
webpage/markdown.ts
1099
webpage/markdown.ts
File diff suppressed because it is too large
Load diff
|
@ -1,218 +1,219 @@
|
||||||
import {User} from "./user.js";
|
import{User}from"./user.js";
|
||||||
import {Role} from "./role.js";
|
import{Role}from"./role.js";
|
||||||
import {Guild} from "./guild.js";
|
import{Guild}from"./guild.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import{ SnowFlake }from"./snowflake.js";
|
||||||
import { memberjson, presencejson, userjson } from "./jsontypes.js";
|
import{ memberjson, presencejson, userjson }from"./jsontypes.js";
|
||||||
import { Dialog } from "./dialog.js";
|
import{ Dialog }from"./dialog.js";
|
||||||
|
|
||||||
class Member{
|
class Member{
|
||||||
static already={};
|
static already={};
|
||||||
owner:Guild;
|
owner:Guild;
|
||||||
user:User;
|
user:User;
|
||||||
roles:Role[]=[];
|
roles:Role[]=[];
|
||||||
id:string;
|
id:string;
|
||||||
nick:string;
|
nick:string;
|
||||||
private constructor(memberjson:memberjson,owner:Guild){
|
private constructor(memberjson:memberjson,owner:Guild){
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
if(this.localuser.userMap.has(memberjson.id)){
|
if(this.localuser.userMap.has(memberjson.id)){
|
||||||
this.user=this.localuser.userMap.get(memberjson.id) as User;
|
this.user=this.localuser.userMap.get(memberjson.id) as User;
|
||||||
}else if(memberjson.user){
|
}else if(memberjson.user){
|
||||||
this.user=new User(memberjson.user,owner.localuser);
|
this.user=new User(memberjson.user,owner.localuser);
|
||||||
}else{
|
}else{
|
||||||
throw new Error("Missing user object of this member");
|
throw new Error("Missing user object of this member");
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const thing of Object.keys(memberjson)){
|
for(const thing of Object.keys(memberjson)){
|
||||||
if(thing==="guild"){continue}
|
if(thing==="guild"){
|
||||||
if(thing==="owner"){continue}
|
continue;
|
||||||
if(thing==="roles"){
|
}
|
||||||
for(const strrole of memberjson["roles"]){
|
if(thing==="owner"){
|
||||||
|
continue;
|
||||||
const role=SnowFlake.getSnowFlakeFromID(strrole,Role).getObject();
|
}
|
||||||
this.roles.push(role);
|
if(thing==="roles"){
|
||||||
}
|
for(const strrole of memberjson.roles){
|
||||||
continue;
|
const role=SnowFlake.getSnowFlakeFromID(strrole,Role).getObject();
|
||||||
}
|
this.roles.push(role);
|
||||||
this[thing]=memberjson[thing];
|
}
|
||||||
}
|
continue;
|
||||||
if(this.localuser.userMap.has(this?.id)){
|
}
|
||||||
this.user=this.localuser.userMap.get(this?.id) as User;
|
this[thing]=memberjson[thing];
|
||||||
return;
|
}
|
||||||
}
|
if(this.localuser.userMap.has(this?.id)){
|
||||||
|
this.user=this.localuser.userMap.get(this?.id) as User;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
get guild(){
|
get guild(){
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
get localuser(){
|
get localuser(){
|
||||||
return this.guild.localuser;
|
return this.guild.localuser;
|
||||||
}
|
}
|
||||||
get info(){
|
get info(){
|
||||||
return this.owner.info;
|
return this.owner.info;
|
||||||
}
|
}
|
||||||
static async new(memberjson:memberjson,owner:Guild):Promise<Member|undefined>{
|
static async new(memberjson:memberjson,owner:Guild):Promise<Member|undefined>{
|
||||||
let user:User;
|
let user:User;
|
||||||
if(owner.localuser.userMap.has(memberjson.id)){
|
if(owner.localuser.userMap.has(memberjson.id)){
|
||||||
user=owner.localuser.userMap.get(memberjson.id);
|
user=owner.localuser.userMap.get(memberjson.id) as User;
|
||||||
}else if(memberjson.user){
|
}else if(memberjson.user){
|
||||||
user=new User(memberjson.user,owner.localuser);
|
user=new User(memberjson.user,owner.localuser);
|
||||||
}else{
|
}else{
|
||||||
throw new Error("missing user object of this member");
|
throw new Error("missing user object of this member");
|
||||||
}
|
}
|
||||||
if(user.members.has(owner)){
|
if(user.members.has(owner)){
|
||||||
let memb=user.members.get(owner)
|
let memb=user.members.get(owner);
|
||||||
if(memb===undefined){
|
if(memb===undefined){
|
||||||
memb=new Member(memberjson,owner);
|
memb=new Member(memberjson,owner);
|
||||||
user.members.set(owner,memb);
|
user.members.set(owner,memb);
|
||||||
return memb
|
return memb;
|
||||||
}else if(memb instanceof Promise){
|
}else if(memb instanceof Promise){
|
||||||
return await memb;//I should do something else, though for now this is "good enough"
|
return await memb;//I should do something else, though for now this is "good enough"
|
||||||
}else{
|
}else{
|
||||||
return memb;
|
return memb;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
const memb=new Member(memberjson,owner);
|
const memb=new Member(memberjson,owner);
|
||||||
user.members.set(owner,memb);
|
user.members.set(owner,memb);
|
||||||
return memb;
|
return memb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static async resolveMember(user:User,guild:Guild):Promise<Member|undefined>{
|
static async resolveMember(user:User,guild:Guild):Promise<Member|undefined>{
|
||||||
const maybe=user.members.get(guild);
|
const maybe=user.members.get(guild);
|
||||||
if(!user.members.has(guild)){
|
if(!user.members.has(guild)){
|
||||||
const membpromise=guild.localuser.resolvemember(user.id,guild.id);
|
const membpromise=guild.localuser.resolvemember(user.id,guild.id);
|
||||||
const promise=new Promise<Member|undefined>( async res=>{
|
const promise=new Promise<Member|undefined>(async res=>{
|
||||||
const membjson=await membpromise;
|
const membjson=await membpromise;
|
||||||
if(membjson===undefined){
|
if(membjson===undefined){
|
||||||
res(undefined);
|
res(undefined);
|
||||||
return undefined;
|
}else{
|
||||||
}else{
|
const member=new Member(membjson,guild);
|
||||||
const member=new Member(membjson,guild);
|
const map=guild.localuser.presences;
|
||||||
const map=guild.localuser.presences;
|
member.getPresence(map.get(member.id));
|
||||||
member.getPresence(map.get(member.id));
|
map.delete(member.id);
|
||||||
map.delete(member.id);
|
res(member);
|
||||||
res(member);
|
return member;
|
||||||
return member;
|
}
|
||||||
}
|
});
|
||||||
})
|
user.members.set(guild,promise);
|
||||||
user.members.set(guild,promise);
|
}
|
||||||
}
|
if(maybe instanceof Promise){
|
||||||
if(maybe instanceof Promise){
|
return await maybe;
|
||||||
return await maybe;
|
}else{
|
||||||
}else{
|
return maybe;
|
||||||
return maybe
|
}
|
||||||
}
|
}
|
||||||
}
|
public getPresence(presence:presencejson|undefined){
|
||||||
public getPresence(presence:presencejson|undefined){
|
this.user.getPresence(presence);
|
||||||
this.user.getPresence(presence);
|
}
|
||||||
}
|
/**
|
||||||
/**
|
|
||||||
* @todo
|
* @todo
|
||||||
*/
|
*/
|
||||||
highInfo(){
|
highInfo(){
|
||||||
fetch(this.info.api+"/users/"+this.id+"/profile?with_mutual_guilds=true&with_mutual_friends_count=true&guild_id="+this.guild.id,{headers:this.guild.headers})
|
fetch(this.info.api+"/users/"+this.id+"/profile?with_mutual_guilds=true&with_mutual_friends_count=true&guild_id="+this.guild.id,{headers: this.guild.headers});
|
||||||
}
|
}
|
||||||
hasRole(ID:string){
|
hasRole(ID:string){
|
||||||
console.log(this.roles,ID);
|
console.log(this.roles,ID);
|
||||||
for(const thing of this.roles){
|
for(const thing of this.roles){
|
||||||
if(thing.id===ID){
|
if(thing.id===ID){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
getColor(){
|
getColor(){
|
||||||
for(const thing of this.roles){
|
for(const thing of this.roles){
|
||||||
const color=thing.getColor();
|
const color=thing.getColor();
|
||||||
if(color){
|
if(color){
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return"";
|
||||||
}
|
}
|
||||||
isAdmin(){
|
isAdmin(){
|
||||||
for(const role of this.roles){
|
for(const role of this.roles){
|
||||||
if(role.permissions.getPermission("ADMINISTRATOR")){
|
if(role.permissions.getPermission("ADMINISTRATOR")){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.guild.properties.owner_id===this.user.id;
|
return this.guild.properties.owner_id===this.user.id;
|
||||||
}
|
}
|
||||||
bind(html:HTMLElement){
|
bind(html:HTMLElement){
|
||||||
if(html.tagName==="SPAN"){
|
if(html.tagName==="SPAN"){
|
||||||
if(!this) {return};
|
if(!this){
|
||||||
/*
|
return;
|
||||||
|
}
|
||||||
|
/*
|
||||||
if(this.error){
|
if(this.error){
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
html.style.color=this.getColor();
|
html.style.color=this.getColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
//this.profileclick(html);
|
//this.profileclick(html);
|
||||||
}
|
}
|
||||||
profileclick(html:HTMLElement){
|
profileclick(html:HTMLElement){
|
||||||
//to be implemented
|
//to be implemented
|
||||||
}
|
}
|
||||||
get name(){
|
get name(){
|
||||||
return this.nick||this.user.username;
|
return this.nick||this.user.username;
|
||||||
}
|
}
|
||||||
kick(){
|
kick(){
|
||||||
let reason=""
|
let reason="";
|
||||||
const menu=new Dialog(["vdiv",
|
const menu=new Dialog(["vdiv",
|
||||||
["title","Kick "+this.name+" from "+this.guild.properties.name],
|
["title","Kick "+this.name+" from "+this.guild.properties.name],
|
||||||
["textbox","Reason:","",function(e:Event){
|
["textbox","Reason:","",function(e:Event){
|
||||||
reason=(e.target as HTMLInputElement).value;
|
reason=(e.target as HTMLInputElement).value;
|
||||||
}],
|
}],
|
||||||
["button","","submit",()=>{
|
["button","","submit",()=>{
|
||||||
this.kickAPI(reason);
|
this.kickAPI(reason);
|
||||||
menu.hide();
|
menu.hide();
|
||||||
}]
|
}]
|
||||||
]);
|
]);
|
||||||
menu.show();
|
menu.show();
|
||||||
}
|
}
|
||||||
kickAPI(reason:string){
|
kickAPI(reason:string){
|
||||||
const headers=structuredClone(this.guild.headers);
|
const headers=structuredClone(this.guild.headers);
|
||||||
headers["x-audit-log-reason"]=reason
|
headers["x-audit-log-reason"]=reason;
|
||||||
fetch(`${this.info.api}/guilds/${this.guild.id}/members/${this.id}`,{
|
fetch(`${this.info.api}/guilds/${this.guild.id}/members/${this.id}`,{
|
||||||
method:"DELETE",
|
method: "DELETE",
|
||||||
headers,
|
headers,
|
||||||
|
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
ban(){
|
ban(){
|
||||||
let reason=""
|
let reason="";
|
||||||
const menu=new Dialog(["vdiv",
|
const menu=new Dialog(["vdiv",
|
||||||
["title","Ban "+this.name+" from "+this.guild.properties.name],
|
["title","Ban "+this.name+" from "+this.guild.properties.name],
|
||||||
["textbox","Reason:","",function(e:Event){
|
["textbox","Reason:","",function(e:Event){
|
||||||
reason=(e.target as HTMLInputElement).value;
|
reason=(e.target as HTMLInputElement).value;
|
||||||
}],
|
}],
|
||||||
["button","","submit",()=>{
|
["button","","submit",()=>{
|
||||||
this.banAPI(reason);
|
this.banAPI(reason);
|
||||||
menu.hide();
|
menu.hide();
|
||||||
}]
|
}]
|
||||||
]);
|
]);
|
||||||
menu.show();
|
menu.show();
|
||||||
}
|
}
|
||||||
banAPI(reason:string){
|
banAPI(reason:string){
|
||||||
const headers=structuredClone(this.guild.headers);
|
const headers=structuredClone(this.guild.headers);
|
||||||
headers["x-audit-log-reason"]=reason
|
headers["x-audit-log-reason"]=reason;
|
||||||
fetch(`${this.info.api}/guilds/${this.guild.id}/bans/${this.id}`,{
|
fetch(`${this.info.api}/guilds/${this.guild.id}/bans/${this.id}`,{
|
||||||
method:"PUT",
|
method: "PUT",
|
||||||
headers
|
headers
|
||||||
|
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
hasPermission(name:string):boolean{
|
hasPermission(name:string):boolean{
|
||||||
if(this.isAdmin()){
|
if(this.isAdmin()){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for(const thing of this.roles){
|
for(const thing of this.roles){
|
||||||
if(thing.permissions.getPermission(name)){
|
if(thing.permissions.getPermission(name)){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export {Member};
|
export{Member};
|
||||||
|
|
1149
webpage/message.ts
1149
webpage/message.ts
File diff suppressed because it is too large
Load diff
|
@ -1,323 +1,323 @@
|
||||||
class Permissions{
|
class Permissions{
|
||||||
allow:bigint;
|
allow:bigint;
|
||||||
deny:bigint;
|
deny:bigint;
|
||||||
readonly hasDeny:boolean;
|
readonly hasDeny:boolean;
|
||||||
constructor(allow:string,deny:string=""){
|
constructor(allow:string,deny:string=""){
|
||||||
this.hasDeny=!!deny;
|
this.hasDeny=Boolean(deny);
|
||||||
try{
|
try{
|
||||||
this.allow = BigInt(allow);
|
this.allow = BigInt(allow);
|
||||||
this.deny = BigInt(deny);
|
this.deny = BigInt(deny);
|
||||||
}catch(e){
|
}catch{
|
||||||
this.allow = 0n;
|
this.allow = 0n;
|
||||||
this.deny = 0n;
|
this.deny = 0n;
|
||||||
console.error(`Something really stupid happened with a permission with allow being ${allow} and deny being, ${deny}, execution will still happen, but something really stupid happened, please report if you know what caused this.`)
|
console.error(`Something really stupid happened with a permission with allow being ${allow} and deny being, ${deny}, execution will still happen, but something really stupid happened, please report if you know what caused this.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getPermissionbit(b:number,big:bigint) : boolean{
|
getPermissionbit(b:number,big:bigint) : boolean{
|
||||||
return Boolean((big>>BigInt(b))&1n);
|
return Boolean((big>>BigInt(b))&1n);
|
||||||
}
|
}
|
||||||
setPermissionbit(b:number,state:boolean,big:bigint) : bigint{
|
setPermissionbit(b:number,state:boolean,big:bigint) : bigint{
|
||||||
const bit=1n<<BigInt(b);
|
const bit=1n<<BigInt(b);
|
||||||
return (big & ~bit) | (BigInt(state) << BigInt(b));//thanks to geotale for this code :3
|
return(big & ~bit) | (BigInt(state) << BigInt(b));//thanks to geotale for this code :3
|
||||||
}
|
}
|
||||||
static map:{
|
static map:{
|
||||||
[key:number|string]:{"name":string,"readableName":string,"description":string}|number,
|
[key:number|string]:{"name":string,"readableName":string,"description":string}|number,
|
||||||
}
|
};
|
||||||
static info:{"name":string,"readableName":string,"description":string}[];
|
static info:{"name":string,"readableName":string,"description":string}[];
|
||||||
static makeMap(){
|
static makeMap(){
|
||||||
Permissions.info=[//for people in the future, do not reorder these, the creation of the map realize on the order
|
Permissions.info=[//for people in the future, do not reorder these, the creation of the map realize on the order
|
||||||
{
|
{
|
||||||
name:"CREATE_INSTANT_INVITE",
|
name: "CREATE_INSTANT_INVITE",
|
||||||
readableName:"Create invite",
|
readableName: "Create invite",
|
||||||
description:"Allows the user to create invites for the guild"
|
description: "Allows the user to create invites for the guild"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"KICK_MEMBERS",
|
name: "KICK_MEMBERS",
|
||||||
readableName:"Kick members",
|
readableName: "Kick members",
|
||||||
description:"Allows the user to kick members from the guild"
|
description: "Allows the user to kick members from the guild"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"BAN_MEMBERS",
|
name: "BAN_MEMBERS",
|
||||||
readableName:"Ban members",
|
readableName: "Ban members",
|
||||||
description:"Allows the user to ban members from the guild"
|
description: "Allows the user to ban members from the guild"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"ADMINISTRATOR",
|
name: "ADMINISTRATOR",
|
||||||
readableName:"Administrator",
|
readableName: "Administrator",
|
||||||
description:"Allows all permissions and bypasses channel permission overwrites. This is a dangerous permission!"
|
description: "Allows all permissions and bypasses channel permission overwrites. This is a dangerous permission!"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MANAGE_CHANNELS",
|
name: "MANAGE_CHANNELS",
|
||||||
readableName:"Manage channels",
|
readableName: "Manage channels",
|
||||||
description:"Allows the user to manage and edit channels"
|
description: "Allows the user to manage and edit channels"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MANAGE_GUILD",
|
name: "MANAGE_GUILD",
|
||||||
readableName:"Manage guild",
|
readableName: "Manage guild",
|
||||||
description:"Allows management and editing of the guild"
|
description: "Allows management and editing of the guild"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"ADD_REACTIONS",
|
name: "ADD_REACTIONS",
|
||||||
readableName:"Add reactions",
|
readableName: "Add reactions",
|
||||||
description:"Allows user to add reactions to messages"
|
description: "Allows user to add reactions to messages"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"VIEW_AUDIT_LOG",
|
name: "VIEW_AUDIT_LOG",
|
||||||
readableName:"View audit log",
|
readableName: "View audit log",
|
||||||
description:"Allows the user to view the audit log"
|
description: "Allows the user to view the audit log"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"PRIORITY_SPEAKER",
|
name: "PRIORITY_SPEAKER",
|
||||||
readableName:"Priority speaker",
|
readableName: "Priority speaker",
|
||||||
description:"Allows for using priority speaker in a voice channel"
|
description: "Allows for using priority speaker in a voice channel"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"STREAM",
|
name: "STREAM",
|
||||||
readableName:"Video",
|
readableName: "Video",
|
||||||
description:"Allows the user to stream"
|
description: "Allows the user to stream"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"VIEW_CHANNEL",
|
name: "VIEW_CHANNEL",
|
||||||
readableName:"View channels",
|
readableName: "View channels",
|
||||||
description:"Allows the user to view the channel"
|
description: "Allows the user to view the channel"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"SEND_MESSAGES",
|
name: "SEND_MESSAGES",
|
||||||
readableName:"Send messages",
|
readableName: "Send messages",
|
||||||
description:"Allows user to send messages"
|
description: "Allows user to send messages"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"SEND_TTS_MESSAGES",
|
name: "SEND_TTS_MESSAGES",
|
||||||
readableName:"Send text-to-speech messages",
|
readableName: "Send text-to-speech messages",
|
||||||
description:"Allows the user to send text-to-speech messages"
|
description: "Allows the user to send text-to-speech messages"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MANAGE_MESSAGES",
|
name: "MANAGE_MESSAGES",
|
||||||
readableName:"Manage messages",
|
readableName: "Manage messages",
|
||||||
description:"Allows the user to delete messages that aren't their own"
|
description: "Allows the user to delete messages that aren't their own"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"EMBED_LINKS",
|
name: "EMBED_LINKS",
|
||||||
readableName:"Embed links",
|
readableName: "Embed links",
|
||||||
description:"Allow links sent by this user to auto-embed"
|
description: "Allow links sent by this user to auto-embed"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"ATTACH_FILES",
|
name: "ATTACH_FILES",
|
||||||
readableName:"Attach files",
|
readableName: "Attach files",
|
||||||
description:"Allows the user to attach files"
|
description: "Allows the user to attach files"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"READ_MESSAGE_HISTORY",
|
name: "READ_MESSAGE_HISTORY",
|
||||||
readableName:"Read message history",
|
readableName: "Read message history",
|
||||||
description:"Allows user to read the message history"
|
description: "Allows user to read the message history"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MENTION_EVERYONE",
|
name: "MENTION_EVERYONE",
|
||||||
readableName:"Mention @everyone, @here and all roles",
|
readableName: "Mention @everyone, @here and all roles",
|
||||||
description:"Allows the user to mention everyone"
|
description: "Allows the user to mention everyone"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"USE_EXTERNAL_EMOJIS",
|
name: "USE_EXTERNAL_EMOJIS",
|
||||||
readableName:"Use external emojis",
|
readableName: "Use external emojis",
|
||||||
description:"Allows the user to use external emojis"
|
description: "Allows the user to use external emojis"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"VIEW_GUILD_INSIGHTS",
|
name: "VIEW_GUILD_INSIGHTS",
|
||||||
readableName:"View guild insights",
|
readableName: "View guild insights",
|
||||||
description:"Allows the user to see guild insights"
|
description: "Allows the user to see guild insights"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"CONNECT",
|
name: "CONNECT",
|
||||||
readableName:"Connect",
|
readableName: "Connect",
|
||||||
description:"Allows the user to connect to a voice channel"
|
description: "Allows the user to connect to a voice channel"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"SPEAK",
|
name: "SPEAK",
|
||||||
readableName:"Speak",
|
readableName: "Speak",
|
||||||
description:"Allows the user to speak in a voice channel"
|
description: "Allows the user to speak in a voice channel"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MUTE_MEMBERS",
|
name: "MUTE_MEMBERS",
|
||||||
readableName:"Mute members",
|
readableName: "Mute members",
|
||||||
description:"Allows user to mute other members"
|
description: "Allows user to mute other members"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"DEAFEN_MEMBERS",
|
name: "DEAFEN_MEMBERS",
|
||||||
readableName:"Deafen members",
|
readableName: "Deafen members",
|
||||||
description:"Allows user to deafen other members"
|
description: "Allows user to deafen other members"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MOVE_MEMBERS",
|
name: "MOVE_MEMBERS",
|
||||||
readableName:"Move members",
|
readableName: "Move members",
|
||||||
description:"Allows the user to move members between voice channels"
|
description: "Allows the user to move members between voice channels"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"USE_VAD",
|
name: "USE_VAD",
|
||||||
readableName:"Use voice activity detection",
|
readableName: "Use voice activity detection",
|
||||||
description:"Allows users to speak in a voice channel by simply talking"
|
description: "Allows users to speak in a voice channel by simply talking"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"CHANGE_NICKNAME",
|
name: "CHANGE_NICKNAME",
|
||||||
readableName:"Change nickname",
|
readableName: "Change nickname",
|
||||||
description:"Allows the user to change their own nickname"
|
description: "Allows the user to change their own nickname"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MANAGE_NICKNAMES",
|
name: "MANAGE_NICKNAMES",
|
||||||
readableName:"Manage nicknames",
|
readableName: "Manage nicknames",
|
||||||
description:"Allows user to change nicknames of other members"
|
description: "Allows user to change nicknames of other members"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MANAGE_ROLES",
|
name: "MANAGE_ROLES",
|
||||||
readableName:"Manage roles",
|
readableName: "Manage roles",
|
||||||
description:"Allows user to edit and manage roles"
|
description: "Allows user to edit and manage roles"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MANAGE_WEBHOOKS",
|
name: "MANAGE_WEBHOOKS",
|
||||||
readableName:"Manage webhooks",
|
readableName: "Manage webhooks",
|
||||||
description:"Allows management and editing of webhooks"
|
description: "Allows management and editing of webhooks"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MANAGE_GUILD_EXPRESSIONS",
|
name: "MANAGE_GUILD_EXPRESSIONS",
|
||||||
readableName:"Manage expressions",
|
readableName: "Manage expressions",
|
||||||
description:"Allows for managing emoji, stickers, and soundboards"
|
description: "Allows for managing emoji, stickers, and soundboards"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"USE_APPLICATION_COMMANDS",
|
name: "USE_APPLICATION_COMMANDS",
|
||||||
readableName:"Use application commands",
|
readableName: "Use application commands",
|
||||||
description:"Allows the user to use application commands"
|
description: "Allows the user to use application commands"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"REQUEST_TO_SPEAK",
|
name: "REQUEST_TO_SPEAK",
|
||||||
readableName:"Request to speak",
|
readableName: "Request to speak",
|
||||||
description:"Allows user to request to speak in stage channel"
|
description: "Allows user to request to speak in stage channel"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MANAGE_EVENTS",
|
name: "MANAGE_EVENTS",
|
||||||
readableName:"Manage events",
|
readableName: "Manage events",
|
||||||
description:"Allows user to edit and manage events"
|
description: "Allows user to edit and manage events"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MANAGE_THREADS",
|
name: "MANAGE_THREADS",
|
||||||
readableName:"Manage threads",
|
readableName: "Manage threads",
|
||||||
description:"Allows the user to delete and archive threads and view all private threads"
|
description: "Allows the user to delete and archive threads and view all private threads"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"CREATE_PUBLIC_THREADS",
|
name: "CREATE_PUBLIC_THREADS",
|
||||||
readableName:"Create public threads",
|
readableName: "Create public threads",
|
||||||
description:"Allows the user to create public threads"
|
description: "Allows the user to create public threads"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"CREATE_PRIVATE_THREADS",
|
name: "CREATE_PRIVATE_THREADS",
|
||||||
readableName:"Create private threads",
|
readableName: "Create private threads",
|
||||||
description:"Allows the user to create private threads"
|
description: "Allows the user to create private threads"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"USE_EXTERNAL_STICKERS",
|
name: "USE_EXTERNAL_STICKERS",
|
||||||
readableName:"Use external stickers",
|
readableName: "Use external stickers",
|
||||||
description:"Allows user to use external stickers"
|
description: "Allows user to use external stickers"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"SEND_MESSAGES_IN_THREADS",
|
name: "SEND_MESSAGES_IN_THREADS",
|
||||||
readableName:"Send messages in threads",
|
readableName: "Send messages in threads",
|
||||||
description:"Allows the user to send messages in threads"
|
description: "Allows the user to send messages in threads"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"USE_EMBEDDED_ACTIVITIES",
|
name: "USE_EMBEDDED_ACTIVITIES",
|
||||||
readableName:"Use activities",
|
readableName: "Use activities",
|
||||||
description:"Allows the user to use embedded activities"
|
description: "Allows the user to use embedded activities"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"MODERATE_MEMBERS",
|
name: "MODERATE_MEMBERS",
|
||||||
readableName:"Timeout members",
|
readableName: "Timeout members",
|
||||||
description:"Allows the user to time out other users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels"
|
description: "Allows the user to time out other users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"VIEW_CREATOR_MONETIZATION_ANALYTICS",
|
name: "VIEW_CREATOR_MONETIZATION_ANALYTICS",
|
||||||
readableName:"View creator monetization analytics",
|
readableName: "View creator monetization analytics",
|
||||||
description:"Allows for viewing role subscription insights"
|
description: "Allows for viewing role subscription insights"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"USE_SOUNDBOARD",
|
name: "USE_SOUNDBOARD",
|
||||||
readableName:"Use soundboard",
|
readableName: "Use soundboard",
|
||||||
description:"Allows for using soundboard in a voice channel"
|
description: "Allows for using soundboard in a voice channel"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"CREATE_GUILD_EXPRESSIONS",
|
name: "CREATE_GUILD_EXPRESSIONS",
|
||||||
readableName:"Create expressions",
|
readableName: "Create expressions",
|
||||||
description:"Allows for creating emojis, stickers, and soundboard sounds, and editing and deleting those created by the current user."
|
description: "Allows for creating emojis, stickers, and soundboard sounds, and editing and deleting those created by the current user."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"CREATE_EVENTS",
|
name: "CREATE_EVENTS",
|
||||||
readableName:"Create events",
|
readableName: "Create events",
|
||||||
description:"Allows for creating scheduled events, and editing and deleting those created by the current user."
|
description: "Allows for creating scheduled events, and editing and deleting those created by the current user."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"USE_EXTERNAL_SOUNDS",
|
name: "USE_EXTERNAL_SOUNDS",
|
||||||
readableName:"Use external sounds",
|
readableName: "Use external sounds",
|
||||||
description:"Allows the usage of custom soundboard sounds from other servers"
|
description: "Allows the usage of custom soundboard sounds from other servers"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"SEND_VOICE_MESSAGES",
|
name: "SEND_VOICE_MESSAGES",
|
||||||
readableName:"Send voice messages",
|
readableName: "Send voice messages",
|
||||||
description:"Allows sending voice messages"
|
description: "Allows sending voice messages"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"SEND_POLLS",
|
name: "SEND_POLLS",
|
||||||
readableName:"Create polls",
|
readableName: "Create polls",
|
||||||
description:"Allows sending polls"
|
description: "Allows sending polls"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name:"USE_EXTERNAL_APPS",
|
name: "USE_EXTERNAL_APPS",
|
||||||
readableName:"Use external apps",
|
readableName: "Use external apps",
|
||||||
description:"Allows user-installed apps to send public responses. " +
|
description: "Allows user-installed apps to send public responses. " +
|
||||||
"When disabled, users will still be allowed to use their apps but the responses will be ephemeral. " +
|
"When disabled, users will still be allowed to use their apps but the responses will be ephemeral. " +
|
||||||
"This only applies to apps not also installed to the server."
|
"This only applies to apps not also installed to the server."
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
Permissions.map={};
|
Permissions.map={};
|
||||||
let i=0;
|
let i=0;
|
||||||
for(const thing of Permissions.info){
|
for(const thing of Permissions.info){
|
||||||
Permissions.map[i]=thing;
|
Permissions.map[i]=thing;
|
||||||
Permissions.map[thing.name]=i;
|
Permissions.map[thing.name]=i;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getPermission(name:string):number{
|
getPermission(name:string):number{
|
||||||
if(this.getPermissionbit(Permissions.map[name] as number,this.allow)){
|
if(this.getPermissionbit(Permissions.map[name] as number,this.allow)){
|
||||||
return 1;
|
return 1;
|
||||||
}else if(this.getPermissionbit(Permissions.map[name] as number,this.deny)){
|
}else if(this.getPermissionbit(Permissions.map[name] as number,this.deny)){
|
||||||
return -1;
|
return-1;
|
||||||
}else{
|
}else{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasPermission(name:string):boolean{
|
hasPermission(name:string):boolean{
|
||||||
if(this.deny){console.warn("This function may of been used in error, think about using getPermision instead")}
|
if(this.deny){
|
||||||
if (this.getPermissionbit(Permissions.map[name] as number,this.allow)) return true;
|
console.warn("This function may of been used in error, think about using getPermision instead");
|
||||||
if (name != "ADMINISTRATOR") return this.hasPermission("ADMINISTRATOR");
|
}
|
||||||
return false;
|
if(this.getPermissionbit(Permissions.map[name] as number,this.allow))return true;
|
||||||
}
|
if(name != "ADMINISTRATOR")return this.hasPermission("ADMINISTRATOR");
|
||||||
setPermission(name:string,setto:number):void{
|
return false;
|
||||||
const bit=Permissions.map[name] as number;
|
}
|
||||||
if (!bit) {
|
setPermission(name:string,setto:number):void{
|
||||||
return console.error("Tried to set permission to " + setto + " for " + name + " but it doesn't exist");
|
const bit=Permissions.map[name] as number;
|
||||||
}
|
if(!bit){
|
||||||
|
return console.error("Tried to set permission to " + setto + " for " + name + " but it doesn't exist");
|
||||||
|
}
|
||||||
|
|
||||||
if(setto===0){
|
if(setto===0){
|
||||||
this.deny=this.setPermissionbit(bit,false,this.deny);
|
this.deny=this.setPermissionbit(bit,false,this.deny);
|
||||||
this.allow=this.setPermissionbit(bit,false,this.allow);
|
this.allow=this.setPermissionbit(bit,false,this.allow);
|
||||||
}else if(setto===1){
|
}else if(setto===1){
|
||||||
|
this.deny=this.setPermissionbit(bit,false,this.deny);
|
||||||
this.deny=this.setPermissionbit(bit,false,this.deny);
|
this.allow=this.setPermissionbit(bit,true,this.allow);
|
||||||
this.allow=this.setPermissionbit(bit,true,this.allow);
|
}else if(setto===-1){
|
||||||
}else if(setto===-1){
|
this.deny=this.setPermissionbit(bit,true,this.deny);
|
||||||
|
this.allow=this.setPermissionbit(bit,false,this.allow);
|
||||||
this.deny=this.setPermissionbit(bit,true,this.deny);
|
}else{
|
||||||
this.allow=this.setPermissionbit(bit,false,this.allow);
|
console.error("invalid number entered:"+setto);
|
||||||
}else{
|
}
|
||||||
console.error("invalid number entered:"+setto);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Permissions.makeMap();
|
Permissions.makeMap();
|
||||||
export {Permissions};
|
export{Permissions};
|
||||||
|
|
|
@ -1,60 +1,60 @@
|
||||||
<body class="Dark-theme">
|
<body class="Dark-theme">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Jank Client</title>
|
<title>Jank Client</title>
|
||||||
<meta content="Jank Client" property="og:title" />
|
<meta content="Jank Client" property="og:title">
|
||||||
<meta content="A spacebar client that has DMs, replying and more" property="og:description" />
|
<meta content="A spacebar client that has DMs, replying and more" property="og:description">
|
||||||
<meta content="/logo.webp" property="og:image" />
|
<meta content="/logo.webp" property="og:image">
|
||||||
<meta content="#4b458c" data-react-helmet="true" name="theme-color" />
|
<meta content="#4b458c" data-react-helmet="true" name="theme-color">
|
||||||
<link href="/style.css" rel="stylesheet" type="text/css" />
|
<link href="/style.css" rel="stylesheet">
|
||||||
<link href="/themes.css" rel="stylesheet" type="text/css" id="lightcss"/>
|
<link href="/themes.css" rel="stylesheet" id="lightcss">
|
||||||
</head>
|
</head>
|
||||||
<div id="logindiv">
|
<div id="logindiv">
|
||||||
<h1>Create an account</h1><br>
|
<h1>Create an account</h1><br>
|
||||||
<form id="register" submit="registertry(e)">
|
<form id="register" submit="registertry(e)">
|
||||||
<div>
|
<div>
|
||||||
<label for="instance"><b>Instance:</b></label><br>
|
<label for="instance"><b>Instance:</b></label><br>
|
||||||
<p id="verify"></p>
|
<p id="verify"></p>
|
||||||
<input type="search" list="instances" placeholder="Instance URL" id="instancein" name="instance" value="" id="instancein" required>
|
<input type="search" list="instances" placeholder="Instance URL" id="instancein" name="instance" value="" id="instancein" required>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="uname"><b>Email:</b></label><br>
|
<label for="uname"><b>Email:</b></label><br>
|
||||||
<input type="text" placeholder="Enter Email" name="uname" id="uname" required>
|
<input type="text" placeholder="Enter Email" name="uname" id="uname" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="uname"><b>Username:</b></label><br>
|
<label for="uname"><b>Username:</b></label><br>
|
||||||
<input type="text" placeholder="Enter Username" name="username" id="username" required>
|
<input type="text" placeholder="Enter Username" name="username" id="username" required>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="psw"><b>Password:</b></label><br>
|
<label for="psw"><b>Password:</b></label><br>
|
||||||
<input type="password" placeholder="Enter Password" name="psw" id="psw" required>
|
<input type="password" placeholder="Enter Password" name="psw" id="psw" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="psw2"><b>Enter password again:</b></label><br>
|
<label for="psw2"><b>Enter password again:</b></label><br>
|
||||||
<input type="password" placeholder="Enter Password Again" name="psw2" id="psw2" required>
|
<input type="password" placeholder="Enter Password Again" name="psw2" id="psw2" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="date"><b>Date of birth:</b></label><br>
|
<label for="date"><b>Date of birth:</b></label><br>
|
||||||
<input type="date" id="date" name="date"/>
|
<input type="date" id="date" name="date">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<b id="TOSbox">I agree to the <a href="" id="TOSa">Terms of Service</a>:</b>
|
<b id="TOSbox">I agree to the <a href="" id="TOSa">Terms of Service</a>:</b>
|
||||||
<input type="checkbox" id="TOS" name="TOS"/>
|
<input type="checkbox" id="TOS" name="TOS">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p class="wrongred" id="wrong"></p>
|
<p class="wrongred" id="wrong"></p>
|
||||||
<div id="h-captcha">
|
<div id="h-captcha">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="dontgrow">Create account</button>
|
<button type="submit" class="dontgrow">Create account</button>
|
||||||
</form>
|
</form>
|
||||||
<a href="/login.html" id="switch">Already have an account?</a>
|
<a href="/login.html" id="switch">Already have an account?</a>
|
||||||
</div>
|
</div>
|
||||||
<datalist id="instances"></datalist>
|
<datalist id="instances"></datalist>
|
||||||
<script src="/register.js" type="module"></script>
|
<script src="/register.js" type="module"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,109 +1,110 @@
|
||||||
import {checkInstance, adduser} from "./login.js";
|
import{checkInstance, adduser}from"./login.js";
|
||||||
if(document.getElementById("register")){
|
if(document.getElementById("register")){
|
||||||
document.getElementById("register").addEventListener("submit", registertry);
|
document.getElementById("register").addEventListener("submit", registertry);
|
||||||
}
|
}
|
||||||
async function registertry(e){
|
async function registertry(e){
|
||||||
|
e.preventDefault();
|
||||||
|
const elements=e.srcElement;
|
||||||
|
const email=elements[1].value;
|
||||||
|
const username=elements[2].value;
|
||||||
|
if(elements[3].value!==elements[4].value){
|
||||||
|
document.getElementById("wrong").textContent="Passwords don't match";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const password=elements[3].value;
|
||||||
|
const dateofbirth=elements[5].value;
|
||||||
|
const apiurl=new URL(JSON.parse(localStorage.getItem("instanceinfo")).api);
|
||||||
|
|
||||||
e.preventDefault();
|
await fetch(apiurl+"/auth/register",{
|
||||||
const elements=e.srcElement;
|
body: JSON.stringify({
|
||||||
const email=elements[1].value;
|
date_of_birth: dateofbirth,
|
||||||
const username=elements[2].value;
|
email,
|
||||||
if(elements[3].value!==elements[4].value){
|
username,
|
||||||
document.getElementById("wrong").textContent="Passwords don't match";
|
password,
|
||||||
return;
|
consent: elements[6].checked,
|
||||||
}
|
captcha_key: elements[7]?.value
|
||||||
const password=elements[3].value;
|
}),
|
||||||
const dateofbirth=elements[5].value;
|
headers: {
|
||||||
const apiurl=new URL(JSON.parse(localStorage.getItem("instanceinfo")).api)
|
"content-type": "application/json"
|
||||||
|
},
|
||||||
|
method: "POST"
|
||||||
|
}).then(e=>{
|
||||||
|
e.json().then(e=>{
|
||||||
|
if(e.captcha_sitekey){
|
||||||
|
const capt=document.getElementById("h-captcha");
|
||||||
|
if(!capt.children.length){
|
||||||
|
const capty=document.createElement("div");
|
||||||
|
capty.classList.add("h-captcha");
|
||||||
|
|
||||||
await fetch(apiurl+"/auth/register",{
|
capty.setAttribute("data-sitekey", e.captcha_sitekey);
|
||||||
body:JSON.stringify({
|
const script=document.createElement("script");
|
||||||
date_of_birth:dateofbirth,
|
script.src="https://js.hcaptcha.com/1/api.js";
|
||||||
email:email,
|
capt.append(script);
|
||||||
username:username,
|
capt.append(capty);
|
||||||
password:password,
|
}else{
|
||||||
consent:elements[6].checked,
|
eval("hcaptcha.reset()");
|
||||||
captcha_key:elements[7]?.value
|
}
|
||||||
}),
|
return;
|
||||||
headers:{
|
}
|
||||||
"content-type": "application/json"
|
if(!e.token){
|
||||||
},
|
console.log(e);
|
||||||
method:"POST"
|
if(e.errors.consent){
|
||||||
}).then(e=>{
|
error(elements[6],e.errors.consent._errors[0].message);
|
||||||
e.json().then(e=>{
|
}else if(e.errors.password){
|
||||||
if(e.captcha_sitekey){
|
error(elements[3],"Password: "+e.errors.password._errors[0].message);
|
||||||
const capt=document.getElementById("h-captcha");
|
}else if(e.errors.username){
|
||||||
if(!capt.children.length){
|
error(elements[2],"Username: "+e.errors.username._errors[0].message);
|
||||||
const capty=document.createElement("div");
|
}else if(e.errors.email){
|
||||||
capty.classList.add("h-captcha");
|
error(elements[1],"Email: "+e.errors.email._errors[0].message);
|
||||||
|
}else if(e.errors.date_of_birth){
|
||||||
capty.setAttribute("data-sitekey", e.captcha_sitekey);
|
error(elements[5],"Date of Birth: "+e.errors.date_of_birth._errors[0].message);
|
||||||
const script=document.createElement("script");
|
}else{
|
||||||
script.src="https://js.hcaptcha.com/1/api.js";
|
document.getElementById("wrong").textContent=e.errors[Object.keys(e.errors)[0]]._errors[0].message;
|
||||||
capt.append(script);
|
}
|
||||||
capt.append(capty);
|
}else{
|
||||||
}else{
|
adduser({serverurls: JSON.parse(localStorage.getItem("instanceinfo")),email,token: e.token}).username=username;
|
||||||
eval("hcaptcha.reset()");
|
localStorage.setItem("token",e.token);
|
||||||
}
|
const redir=new URLSearchParams(window.location.search).get("goback");
|
||||||
return;
|
if(redir){
|
||||||
}
|
window.location.href = redir;
|
||||||
if(!e.token){
|
}else{
|
||||||
console.log(e);
|
window.location.href = "/channels/@me";
|
||||||
if(e.errors.consent){
|
}
|
||||||
error(elements[6],e.errors.consent._errors[0].message);
|
}
|
||||||
}else if(e.errors.password){
|
});
|
||||||
error(elements[3],"Password: "+e.errors.password._errors[0].message);
|
});
|
||||||
}else if(e.errors.username){
|
//document.getElementById("wrong").textContent=h;
|
||||||
error(elements[2],"Username: "+e.errors.username._errors[0].message);
|
// console.log(h);
|
||||||
}else if(e.errors.email){
|
|
||||||
error(elements[1],"Email: "+e.errors.email._errors[0].message);
|
|
||||||
}else if(e.errors.date_of_birth){
|
|
||||||
error(elements[5],"Date of Birth: "+e.errors.date_of_birth._errors[0].message);
|
|
||||||
}else{
|
|
||||||
document.getElementById("wrong").textContent=e.errors[Object.keys(e.errors)[0]]._errors[0].message;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
adduser({serverurls:JSON.parse(localStorage.getItem("instanceinfo")),email:email,token:e.token}).username=username;
|
|
||||||
localStorage.setItem("token",e.token);
|
|
||||||
const redir=new URLSearchParams(window.location.search).get("goback");
|
|
||||||
if(redir){
|
|
||||||
window.location.href = redir;
|
|
||||||
}else{
|
|
||||||
window.location.href = '/channels/@me';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
//document.getElementById("wrong").textContent=h;
|
|
||||||
// console.log(h);
|
|
||||||
}
|
}
|
||||||
function error(e:HTMLFormElement,message:string){
|
function error(e:HTMLFormElement,message:string){
|
||||||
const p=e.parentElement;
|
const p=e.parentElement;
|
||||||
let element=p.getElementsByClassName("suberror")[0] as HTMLElement;
|
let element=p.getElementsByClassName("suberror")[0] as HTMLElement;
|
||||||
if(!element){
|
if(!element){
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
div.classList.add("suberror","suberrora");
|
div.classList.add("suberror","suberrora");
|
||||||
p.append(div);
|
p.append(div);
|
||||||
element=div;
|
element=div;
|
||||||
}else{
|
}else{
|
||||||
element.classList.remove("suberror");
|
element.classList.remove("suberror");
|
||||||
setTimeout(_=>{element.classList.add("suberror")},100);
|
setTimeout(_=>{
|
||||||
}
|
element.classList.add("suberror");
|
||||||
element.textContent=message;
|
},100);
|
||||||
|
}
|
||||||
|
element.textContent=message;
|
||||||
}
|
}
|
||||||
let TOSa=document.getElementById("TOSa");
|
let TOSa=document.getElementById("TOSa");
|
||||||
async function tosLogic(){
|
async function tosLogic(){
|
||||||
const apiurl=new URL(JSON.parse(localStorage.getItem("instanceinfo")).api)
|
const apiurl=new URL(JSON.parse(localStorage.getItem("instanceinfo")).api);
|
||||||
const tosPage=(await (await fetch(apiurl.toString()+"/ping")).json()).instance.tosPage;
|
const tosPage=(await (await fetch(apiurl.toString()+"/ping")).json()).instance.tosPage;
|
||||||
if(tosPage){
|
if(tosPage){
|
||||||
document.getElementById("TOSbox").innerHTML="I agree to the <a href=\"\" id=\"TOSa\">Terms of Service</a>:";
|
document.getElementById("TOSbox").innerHTML="I agree to the <a href=\"\" id=\"TOSa\">Terms of Service</a>:";
|
||||||
TOSa=document.getElementById("TOSa");
|
TOSa=document.getElementById("TOSa");
|
||||||
(TOSa as HTMLAnchorElement).href=tosPage;
|
(TOSa as HTMLAnchorElement).href=tosPage;
|
||||||
}else{
|
}else{
|
||||||
document.getElementById("TOSbox").textContent="This instance has no Terms of Service, accept ToS anyways:";
|
document.getElementById("TOSbox").textContent="This instance has no Terms of Service, accept ToS anyways:";
|
||||||
TOSa=null;
|
TOSa=null;
|
||||||
}
|
}
|
||||||
console.log(tosPage);
|
console.log(tosPage);
|
||||||
}
|
}
|
||||||
tosLogic();
|
tosLogic();
|
||||||
|
|
||||||
|
|
308
webpage/role.ts
308
webpage/role.ts
|
@ -1,162 +1,170 @@
|
||||||
|
|
||||||
import {Permissions} from "./permissions.js";
|
import{Permissions}from"./permissions.js";
|
||||||
import {Localuser} from "./localuser.js";
|
import{Localuser}from"./localuser.js";
|
||||||
import {Guild} from "./guild.js";
|
import{Guild}from"./guild.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import{ SnowFlake }from"./snowflake.js";
|
||||||
import { rolesjson } from "./jsontypes.js";
|
import{ rolesjson }from"./jsontypes.js";
|
||||||
class Role{
|
class Role{
|
||||||
permissions:Permissions;
|
permissions:Permissions;
|
||||||
owner:Guild;
|
owner:Guild;
|
||||||
color:number;
|
color:number;
|
||||||
readonly snowflake:SnowFlake<Role>;
|
readonly snowflake:SnowFlake<Role>;
|
||||||
name:string;
|
name:string;
|
||||||
info:Guild["info"];
|
info:Guild["info"];
|
||||||
hoist:boolean;
|
hoist:boolean;
|
||||||
icon:string;
|
icon:string;
|
||||||
mentionable:boolean;
|
mentionable:boolean;
|
||||||
unicode_emoji:string;
|
unicode_emoji:string;
|
||||||
headers:Guild["headers"];
|
headers:Guild["headers"];
|
||||||
get id(){
|
get id(){
|
||||||
return this.snowflake.id;
|
return this.snowflake.id;
|
||||||
}
|
}
|
||||||
constructor(json:rolesjson, owner:Guild){
|
constructor(json:rolesjson, owner:Guild){
|
||||||
this.headers=owner.headers;
|
this.headers=owner.headers;
|
||||||
this.info=owner.info;
|
this.info=owner.info;
|
||||||
for(const thing of Object.keys(json)){
|
for(const thing of Object.keys(json)){
|
||||||
if(thing==="id"){
|
if(thing==="id"){
|
||||||
this.snowflake=new SnowFlake(json.id,this);
|
this.snowflake=new SnowFlake(json.id,this);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing]=json[thing];
|
this[thing]=json[thing];
|
||||||
}
|
}
|
||||||
this.permissions=new Permissions(json.permissions);
|
this.permissions=new Permissions(json.permissions);
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
}
|
}
|
||||||
get guild():Guild{
|
get guild():Guild{
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
get localuser():Localuser{
|
get localuser():Localuser{
|
||||||
return this.guild.localuser;
|
return this.guild.localuser;
|
||||||
}
|
}
|
||||||
getColor():string|null{
|
getColor():string|null{
|
||||||
if(this.color===0){return null};
|
if(this.color===0){
|
||||||
return `#${this.color.toString(16)}`;
|
return null;
|
||||||
}
|
}
|
||||||
|
return`#${this.color.toString(16)}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export {Role};
|
export{Role};
|
||||||
import {Options} from "./settings.js";
|
import{Options}from"./settings.js";
|
||||||
class PermissionToggle implements OptionsElement<number>{
|
class PermissionToggle implements OptionsElement<number>{
|
||||||
readonly rolejson:{name:string,readableName:string,description:string};
|
readonly rolejson:{name:string,readableName:string,description:string};
|
||||||
permissions:Permissions;
|
permissions:Permissions;
|
||||||
owner:Options;
|
owner:Options;
|
||||||
value:number;
|
value:number;
|
||||||
constructor(roleJSON:PermissionToggle["rolejson"],permissions:Permissions,owner:Options){
|
constructor(roleJSON:PermissionToggle["rolejson"],permissions:Permissions,owner:Options){
|
||||||
this.rolejson=roleJSON;
|
this.rolejson=roleJSON;
|
||||||
this.permissions=permissions;
|
this.permissions=permissions;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
}
|
}
|
||||||
watchForChange(){};
|
watchForChange(){}
|
||||||
generateHTML():HTMLElement{
|
generateHTML():HTMLElement{
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
div.classList.add("setting");
|
div.classList.add("setting");
|
||||||
const name=document.createElement("span");
|
const name=document.createElement("span");
|
||||||
name.textContent=this.rolejson.readableName;
|
name.textContent=this.rolejson.readableName;
|
||||||
name.classList.add("settingsname");
|
name.classList.add("settingsname");
|
||||||
div.append(name);
|
div.append(name);
|
||||||
|
|
||||||
|
|
||||||
div.append(this.generateCheckbox());
|
div.append(this.generateCheckbox());
|
||||||
const p=document.createElement("p");
|
const p=document.createElement("p");
|
||||||
p.textContent=this.rolejson.description;
|
p.textContent=this.rolejson.description;
|
||||||
div.appendChild(p);
|
div.appendChild(p);
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
generateCheckbox():HTMLElement{
|
generateCheckbox():HTMLElement{
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
div.classList.add("tritoggle");
|
div.classList.add("tritoggle");
|
||||||
const state=this.permissions.getPermission(this.rolejson.name);
|
const state=this.permissions.getPermission(this.rolejson.name);
|
||||||
|
|
||||||
const on=document.createElement("input");
|
const on=document.createElement("input");
|
||||||
on.type="radio";
|
on.type="radio";
|
||||||
on.name=this.rolejson.name;
|
on.name=this.rolejson.name;
|
||||||
div.append(on);
|
div.append(on);
|
||||||
if(state===1){on.checked=true;};
|
if(state===1){
|
||||||
on.onclick=_=>{
|
on.checked=true;
|
||||||
this.permissions.setPermission(this.rolejson.name,1);
|
}
|
||||||
this.owner.changed();
|
on.onclick=_=>{
|
||||||
}
|
this.permissions.setPermission(this.rolejson.name,1);
|
||||||
|
this.owner.changed();
|
||||||
|
};
|
||||||
|
|
||||||
const no=document.createElement("input");
|
const no=document.createElement("input");
|
||||||
no.type="radio";
|
no.type="radio";
|
||||||
no.name=this.rolejson.name;
|
no.name=this.rolejson.name;
|
||||||
div.append(no);
|
div.append(no);
|
||||||
if(state===0){no.checked=true;};
|
if(state===0){
|
||||||
no.onclick=_=>{
|
no.checked=true;
|
||||||
this.permissions.setPermission(this.rolejson.name,0);
|
}
|
||||||
this.owner.changed();
|
no.onclick=_=>{
|
||||||
}
|
this.permissions.setPermission(this.rolejson.name,0);
|
||||||
if(this.permissions.hasDeny){
|
this.owner.changed();
|
||||||
const off=document.createElement("input");
|
};
|
||||||
off.type="radio";
|
if(this.permissions.hasDeny){
|
||||||
off.name=this.rolejson.name;
|
const off=document.createElement("input");
|
||||||
div.append(off);
|
off.type="radio";
|
||||||
if(state===-1){off.checked=true;};
|
off.name=this.rolejson.name;
|
||||||
off.onclick=_=>{
|
div.append(off);
|
||||||
this.permissions.setPermission(this.rolejson.name,-1);
|
if(state===-1){
|
||||||
this.owner.changed();
|
off.checked=true;
|
||||||
}
|
}
|
||||||
}
|
off.onclick=_=>{
|
||||||
return div;
|
this.permissions.setPermission(this.rolejson.name,-1);
|
||||||
}
|
this.owner.changed();
|
||||||
submit(){
|
};
|
||||||
|
}
|
||||||
|
return div;
|
||||||
|
}
|
||||||
|
submit(){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
import { OptionsElement,Buttons } from "./settings.js";
|
import{ OptionsElement,Buttons }from"./settings.js";
|
||||||
class RoleList extends Buttons{
|
class RoleList extends Buttons{
|
||||||
readonly permissions:[SnowFlake<Role>,Permissions][];
|
readonly permissions:[SnowFlake<Role>,Permissions][];
|
||||||
permission:Permissions;
|
permission:Permissions;
|
||||||
readonly guild:Guild;
|
readonly guild:Guild;
|
||||||
readonly channel:boolean;
|
readonly channel:boolean;
|
||||||
readonly declare buttons:[string,string][];
|
readonly declare buttons:[string,string][];
|
||||||
readonly options:Options;
|
readonly options:Options;
|
||||||
onchange:Function;
|
onchange:Function;
|
||||||
curid:string;
|
curid:string;
|
||||||
constructor(permissions:[SnowFlake<Role>,Permissions][],guild:Guild,onchange:Function,channel=false){
|
constructor(permissions:[SnowFlake<Role>,Permissions][],guild:Guild,onchange:Function,channel=false){
|
||||||
super("Roles");
|
super("Roles");
|
||||||
this.guild=guild;
|
this.guild=guild;
|
||||||
this.permissions=permissions;
|
this.permissions=permissions;
|
||||||
this.channel=channel;
|
this.channel=channel;
|
||||||
this.onchange=onchange;
|
this.onchange=onchange;
|
||||||
const options=new Options("",this);
|
const options=new Options("",this);
|
||||||
if(channel){
|
if(channel){
|
||||||
this.permission=new Permissions("0","0");
|
this.permission=new Permissions("0","0");
|
||||||
}else{
|
}else{
|
||||||
this.permission=new Permissions("0");
|
this.permission=new Permissions("0");
|
||||||
}
|
}
|
||||||
for(const thing of Permissions.info){
|
for(const thing of Permissions.info){
|
||||||
options.options.push(new PermissionToggle(thing,this.permission,options));
|
options.options.push(new PermissionToggle(thing,this.permission,options));
|
||||||
}
|
}
|
||||||
for(const i of permissions){
|
for(const i of permissions){
|
||||||
console.log(i);
|
console.log(i);
|
||||||
this.buttons.push([i[0].getObject().name,i[0].id])//
|
this.buttons.push([i[0].getObject().name,i[0].id]);//
|
||||||
}
|
}
|
||||||
this.options=options;
|
this.options=options;
|
||||||
}
|
}
|
||||||
handleString(str:string):HTMLElement{
|
handleString(str:string):HTMLElement{
|
||||||
this.curid=str;
|
this.curid=str;
|
||||||
const arr=this.permissions.find(_=>_[0].id===str);
|
const arr=this.permissions.find(_=>_[0].id===str);
|
||||||
if(arr){
|
if(arr){
|
||||||
const perm=arr[1];
|
const perm=arr[1];
|
||||||
this.permission.deny=perm.deny;
|
this.permission.deny=perm.deny;
|
||||||
this.permission.allow=perm.allow;
|
this.permission.allow=perm.allow;
|
||||||
this.options.name=SnowFlake.getSnowFlakeFromID(str,Role).getObject().name;
|
this.options.name=SnowFlake.getSnowFlakeFromID(str,Role).getObject().name;
|
||||||
this.options.haschanged=false;
|
this.options.haschanged=false;
|
||||||
}
|
}
|
||||||
return this.options.generateHTML();
|
return this.options.generateHTML();
|
||||||
}
|
}
|
||||||
save(){
|
save(){
|
||||||
this.onchange(this.curid,this.permission);
|
this.onchange(this.curid,this.permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export {RoleList}
|
export{RoleList};
|
||||||
|
|
|
@ -1,87 +1,93 @@
|
||||||
function deleteoldcache(){
|
function deleteoldcache(){
|
||||||
caches.delete("cache");
|
caches.delete("cache");
|
||||||
console.log("this ran :P")
|
console.log("this ran :P");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function putInCache(request, response){
|
async function putInCache(request, response){
|
||||||
console.log(request,response);
|
console.log(request,response);
|
||||||
const cache = await caches.open('cache');
|
const cache = await caches.open("cache");
|
||||||
console.log("Grabbed")
|
console.log("Grabbed");
|
||||||
try{
|
try{
|
||||||
console.log(await cache.put(request, response));
|
console.log(await cache.put(request, response));
|
||||||
}catch(error){
|
}catch(error){
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
console.log("test");
|
console.log("test");
|
||||||
|
|
||||||
let lastcache
|
let lastcache;
|
||||||
self.addEventListener("activate", async (event) => {
|
self.addEventListener("activate", async event=>{
|
||||||
console.log("test2");
|
console.log("test2");
|
||||||
checkCache();
|
checkCache();
|
||||||
})
|
});
|
||||||
async function checkCache(){
|
async function checkCache(){
|
||||||
if(checkedrecently){
|
if(checkedrecently){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const promise=await caches.match("/getupdates");
|
const promise=await caches.match("/getupdates");
|
||||||
if(promise){
|
if(promise){
|
||||||
lastcache= await promise.text();
|
lastcache= await promise.text();
|
||||||
}
|
}
|
||||||
console.log(lastcache);
|
console.log(lastcache);
|
||||||
fetch("/getupdates").then(async data=>{
|
fetch("/getupdates").then(async data=>{
|
||||||
const text=await data.clone().text();
|
const text=await data.clone().text();
|
||||||
console.log(text,lastcache)
|
console.log(text,lastcache);
|
||||||
if(lastcache!==text){
|
if(lastcache!==text){
|
||||||
deleteoldcache();
|
deleteoldcache();
|
||||||
putInCache("/getupdates",data.clone());
|
putInCache("/getupdates",data.clone());
|
||||||
}
|
}
|
||||||
checkedrecently=true;
|
checkedrecently=true;
|
||||||
setTimeout(_=>{checkedrecently=false},1000*60*30);
|
setTimeout(_=>{
|
||||||
})
|
checkedrecently=false;
|
||||||
|
},1000*60*30);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
var checkedrecently=false;
|
var checkedrecently=false;
|
||||||
function samedomain(url){
|
function samedomain(url){
|
||||||
return new URL(url).origin===self.origin;
|
return new URL(url).origin===self.origin;
|
||||||
}
|
}
|
||||||
function isindexhtml(url){
|
function isindexhtml(url){
|
||||||
console.log(url);
|
console.log(url);
|
||||||
if(new URL(url).pathname.startsWith("/channels")){
|
if(new URL(url).pathname.startsWith("/channels")){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
async function getfile(event){
|
async function getfile(event){
|
||||||
checkCache();
|
checkCache();
|
||||||
if(!samedomain(event.request.url)){
|
if(!samedomain(event.request.url)){
|
||||||
return await fetch(event.request.clone());
|
return await fetch(event.request.clone());
|
||||||
}
|
}
|
||||||
const responseFromCache = await caches.match(event.request.url);
|
const responseFromCache = await caches.match(event.request.url);
|
||||||
console.log(responseFromCache,caches);
|
console.log(responseFromCache,caches);
|
||||||
if (responseFromCache) {
|
if(responseFromCache){
|
||||||
console.log("cache hit")
|
console.log("cache hit");
|
||||||
return responseFromCache;
|
return responseFromCache;
|
||||||
}
|
}
|
||||||
if(isindexhtml(event.request.url)){
|
if(isindexhtml(event.request.url)){
|
||||||
console.log("is index.html")
|
console.log("is index.html");
|
||||||
const responseFromCache = await caches.match("/index.html");
|
const responseFromCache = await caches.match("/index.html");
|
||||||
if (responseFromCache) {
|
if(responseFromCache){
|
||||||
console.log("cache hit")
|
console.log("cache hit");
|
||||||
return responseFromCache;
|
return responseFromCache;
|
||||||
}
|
}
|
||||||
const responseFromNetwork = await fetch("/index.html");
|
const responseFromNetwork = await fetch("/index.html");
|
||||||
await putInCache("/index.html",responseFromNetwork.clone());
|
await putInCache("/index.html",responseFromNetwork.clone());
|
||||||
return responseFromNetwork;
|
return responseFromNetwork;
|
||||||
}
|
}
|
||||||
const responseFromNetwork = await fetch(event.request.clone());
|
const responseFromNetwork = await fetch(event.request.clone());
|
||||||
console.log(event.request.clone());
|
console.log(event.request.clone());
|
||||||
await putInCache(event.request.clone(),responseFromNetwork.clone());
|
await putInCache(event.request.clone(),responseFromNetwork.clone());
|
||||||
try{
|
try{
|
||||||
return responseFromNetwork;
|
return responseFromNetwork;
|
||||||
}catch(e){console.error(e)}
|
}catch(e){
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.addEventListener('fetch', (event:any) => {
|
self.addEventListener("fetch", (event:any)=>{
|
||||||
try{
|
try{
|
||||||
event.respondWith(getfile(event));
|
event.respondWith(getfile(event));
|
||||||
}catch(e){console.error(e)}
|
}catch(e){
|
||||||
})
|
console.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
1697
webpage/settings.ts
1697
webpage/settings.ts
File diff suppressed because it is too large
Load diff
|
@ -1,95 +1,95 @@
|
||||||
class SnowFlake<x extends WeakKey>{
|
class SnowFlake<x extends WeakKey>{
|
||||||
public readonly id:string;
|
public readonly id:string;
|
||||||
private static SnowFlakes:Map<any,Map<string,WeakRef<SnowFlake<any>>>>=new Map();
|
private static SnowFlakes:Map<any,Map<string,WeakRef<SnowFlake<any>>>>=new Map();
|
||||||
private static readonly FinalizationRegistry=new FinalizationRegistry((a:[string,WeakKey])=>{
|
private static readonly FinalizationRegistry=new FinalizationRegistry((a:[string,WeakKey])=>{
|
||||||
SnowFlake.SnowFlakes.get(a[1]).delete(a[0]);
|
SnowFlake.SnowFlakes.get(a[1]).delete(a[0]);
|
||||||
});
|
});
|
||||||
private obj:x;
|
private obj:x;
|
||||||
constructor(id:string,obj:x){
|
constructor(id:string,obj:x){
|
||||||
if(!obj){
|
if(!obj){
|
||||||
this.id=id;
|
this.id=id;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!SnowFlake.SnowFlakes.get(obj.constructor)){
|
if(!SnowFlake.SnowFlakes.get(obj.constructor)){
|
||||||
SnowFlake.SnowFlakes.set(obj.constructor,new Map());
|
SnowFlake.SnowFlakes.set(obj.constructor,new Map());
|
||||||
}
|
}
|
||||||
if(SnowFlake.SnowFlakes.get(obj.constructor).get(id)){
|
if(SnowFlake.SnowFlakes.get(obj.constructor).get(id)){
|
||||||
const snowflake=SnowFlake.SnowFlakes.get(obj.constructor).get(id).deref();
|
const snowflake=SnowFlake.SnowFlakes.get(obj.constructor).get(id).deref();
|
||||||
if(snowflake){
|
if(snowflake){
|
||||||
snowflake.obj=obj;
|
snowflake.obj=obj;
|
||||||
return snowflake;
|
return snowflake;
|
||||||
}else{
|
}else{
|
||||||
SnowFlake.SnowFlakes.get(obj.constructor).delete(id);
|
SnowFlake.SnowFlakes.get(obj.constructor).delete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.id=id;
|
this.id=id;
|
||||||
SnowFlake.SnowFlakes.get(obj.constructor).set(id,new WeakRef(this));
|
SnowFlake.SnowFlakes.get(obj.constructor).set(id,new WeakRef(this));
|
||||||
SnowFlake.FinalizationRegistry.register(this,[id,obj.constructor]);
|
SnowFlake.FinalizationRegistry.register(this,[id,obj.constructor]);
|
||||||
this.obj=obj;
|
this.obj=obj;
|
||||||
}
|
}
|
||||||
static clear(){//this is kinda a temp solution, it should be fixed, though its not that easy to do so
|
static clear(){//this is kinda a temp solution, it should be fixed, though its not that easy to do so
|
||||||
this.SnowFlakes=new Map();
|
this.SnowFlakes=new Map();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Just to clarify bc TS, it returns a SnowFlake\<type> which is what you entered with the type parameter
|
* Just to clarify bc TS, it returns a SnowFlake\<type> which is what you entered with the type parameter
|
||||||
* @deprecated
|
* @deprecated
|
||||||
**/
|
**/
|
||||||
static getSnowFlakeFromID<T extends {}>(id:string,type: abstract new(...args: never) => T): SnowFlake<T>{
|
static getSnowFlakeFromID<T extends {}>(id:string,type: abstract new(...args: never) => T): SnowFlake<T>{
|
||||||
if(!SnowFlake.SnowFlakes.get(type)){
|
if(!SnowFlake.SnowFlakes.get(type)){
|
||||||
SnowFlake.SnowFlakes.set(type,new Map());
|
SnowFlake.SnowFlakes.set(type,new Map());
|
||||||
}
|
}
|
||||||
const snowflake=SnowFlake.SnowFlakes.get(type).get(id);
|
const snowflake=SnowFlake.SnowFlakes.get(type).get(id);
|
||||||
if(snowflake){
|
if(snowflake){
|
||||||
const obj=snowflake.deref();
|
const obj=snowflake.deref();
|
||||||
if(obj){
|
if(obj){
|
||||||
return obj;
|
return obj;
|
||||||
}else{
|
}else{
|
||||||
SnowFlake.SnowFlakes.get(type).delete(id);
|
SnowFlake.SnowFlakes.get(type).delete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const snowflake=new SnowFlake(id,undefined);
|
const snowflake=new SnowFlake(id,undefined);
|
||||||
|
|
||||||
SnowFlake.SnowFlakes.get(type).set(id,new WeakRef(snowflake));
|
SnowFlake.SnowFlakes.get(type).set(id,new WeakRef(snowflake));
|
||||||
SnowFlake.FinalizationRegistry.register(this,[id,type]);
|
SnowFlake.FinalizationRegistry.register(this,[id,type]);
|
||||||
|
|
||||||
return snowflake;
|
return snowflake;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static hasSnowFlakeFromID(id:string,type:any){
|
static hasSnowFlakeFromID(id:string,type:any){
|
||||||
if(!SnowFlake.SnowFlakes.get(type)){
|
if(!SnowFlake.SnowFlakes.get(type)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const flake=SnowFlake.SnowFlakes.get(type).get(id);
|
const flake=SnowFlake.SnowFlakes.get(type).get(id);
|
||||||
if(flake){
|
if(flake){
|
||||||
const flake2=flake.deref()?.getObject();
|
const flake2=flake.deref()?.getObject();
|
||||||
if(flake2){
|
if(flake2){
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getUnixTime():number{
|
getUnixTime():number{
|
||||||
try{
|
try{
|
||||||
return Number((BigInt(this.id)>>22n)+1420070400000n);
|
return Number((BigInt(this.id)>>22n)+1420070400000n);
|
||||||
}catch{
|
}catch{
|
||||||
console.error(`The ID is corrupted, it's ${this.id} when it should be some number.`)
|
console.error(`The ID is corrupted, it's ${this.id} when it should be some number.`);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toString(){
|
toString(){
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
getObject():x{
|
getObject():x{
|
||||||
return this.obj;
|
return this.obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export {SnowFlake};
|
export{SnowFlake};
|
||||||
|
|
835
webpage/user.ts
835
webpage/user.ts
|
@ -1,431 +1,432 @@
|
||||||
//const usercache={};
|
//const usercache={};
|
||||||
import {Member} from "./member.js";
|
import{Member}from"./member.js";
|
||||||
import {MarkDown} from "./markdown.js";
|
import{MarkDown}from"./markdown.js";
|
||||||
import {Contextmenu} from "./contextmenu.js";
|
import{Contextmenu}from"./contextmenu.js";
|
||||||
import {Localuser} from "./localuser.js";
|
import{Localuser}from"./localuser.js";
|
||||||
import {Guild} from "./guild.js";
|
import{Guild}from"./guild.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import{ SnowFlake }from"./snowflake.js";
|
||||||
import { presencejson, userjson } from "./jsontypes.js";
|
import{ presencejson, userjson }from"./jsontypes.js";
|
||||||
|
|
||||||
class User{
|
class User{
|
||||||
owner:Localuser;
|
owner:Localuser;
|
||||||
hypotheticalpfp:boolean;
|
hypotheticalpfp:boolean;
|
||||||
snowflake:SnowFlake<User>;
|
snowflake:SnowFlake<User>;
|
||||||
avatar:string|null;
|
avatar:string|null;
|
||||||
username:string;
|
username:string;
|
||||||
nickname:string|null=null;
|
nickname:string|null=null;
|
||||||
relationshipType:0|1|2|3|4=0;
|
relationshipType:0|1|2|3|4=0;
|
||||||
bio:MarkDown;
|
bio:MarkDown;
|
||||||
discriminator:string;
|
discriminator:string;
|
||||||
pronouns:string;
|
pronouns:string;
|
||||||
bot:boolean;
|
bot:boolean;
|
||||||
public_flags: number;
|
public_flags: number;
|
||||||
accent_color: number;
|
accent_color: number;
|
||||||
banner: string|undefined;
|
banner: string|undefined;
|
||||||
hypotheticalbanner:boolean;
|
hypotheticalbanner:boolean;
|
||||||
premium_since: string;
|
premium_since: string;
|
||||||
premium_type: number;
|
premium_type: number;
|
||||||
theme_colors: string;
|
theme_colors: string;
|
||||||
badge_ids: string[];
|
badge_ids: string[];
|
||||||
members: WeakMap<Guild, Member|undefined|Promise<Member|undefined>>=new WeakMap();
|
members: WeakMap<Guild, Member|undefined|Promise<Member|undefined>>=new WeakMap();
|
||||||
private status:string;
|
private status:string;
|
||||||
clone(){
|
clone(){
|
||||||
return new User({
|
return new User({
|
||||||
username:this.username,
|
username: this.username,
|
||||||
id:this.id+"#clone",
|
id: this.id+"#clone",
|
||||||
public_flags:this.public_flags,
|
public_flags: this.public_flags,
|
||||||
discriminator:this.discriminator,
|
discriminator: this.discriminator,
|
||||||
avatar:this.avatar,
|
avatar: this.avatar,
|
||||||
accent_color:this.accent_color,
|
accent_color: this.accent_color,
|
||||||
banner:this.banner,
|
banner: this.banner,
|
||||||
bio:this.bio.rawString,
|
bio: this.bio.rawString,
|
||||||
premium_since:this.premium_since,
|
premium_since: this.premium_since,
|
||||||
premium_type:this.premium_type,
|
premium_type: this.premium_type,
|
||||||
bot:this.bot,
|
bot: this.bot,
|
||||||
theme_colors:this.theme_colors,
|
theme_colors: this.theme_colors,
|
||||||
pronouns:this.pronouns,
|
pronouns: this.pronouns,
|
||||||
badge_ids:this.badge_ids
|
badge_ids: this.badge_ids
|
||||||
},this.owner)
|
},this.owner);
|
||||||
}
|
}
|
||||||
public getPresence(presence:presencejson|undefined){
|
public getPresence(presence:presencejson|undefined){
|
||||||
if(presence){
|
if(presence){
|
||||||
this.setstatus(presence.status);
|
this.setstatus(presence.status);
|
||||||
}else{
|
}else{
|
||||||
this.setstatus("offline");
|
this.setstatus("offline");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setstatus(status:string){
|
setstatus(status:string){
|
||||||
this.status=status;
|
this.status=status;
|
||||||
}
|
}
|
||||||
async getStatus(){
|
async getStatus(){
|
||||||
if(this.status){
|
if(this.status){
|
||||||
return this.status;
|
return this.status;
|
||||||
}else{
|
}else{
|
||||||
return "offline";
|
return"offline";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get id(){
|
get id(){
|
||||||
return this.snowflake.id;
|
return this.snowflake.id;
|
||||||
}
|
}
|
||||||
static contextmenu=new Contextmenu<User,Member|undefined>("User Menu");
|
static contextmenu=new Contextmenu<User,Member|undefined>("User Menu");
|
||||||
static setUpContextMenu(){
|
static setUpContextMenu(){
|
||||||
this.contextmenu.addbutton("Copy user id",function(this:User){
|
this.contextmenu.addbutton("Copy user id",function(this:User){
|
||||||
navigator.clipboard.writeText(this.id);
|
navigator.clipboard.writeText(this.id);
|
||||||
});
|
});
|
||||||
this.contextmenu.addbutton("Message user",function(this:User){
|
this.contextmenu.addbutton("Message user",function(this:User){
|
||||||
fetch(this.info.api+"/users/@me/channels",
|
fetch(this.info.api+"/users/@me/channels",
|
||||||
{method:"POST",
|
{method: "POST",
|
||||||
body:JSON.stringify({"recipients":[this.id]}),
|
body: JSON.stringify({recipients: [this.id]}),
|
||||||
headers: this.localuser.headers
|
headers: this.localuser.headers
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.contextmenu.addbutton("Block user",function(this:User){
|
this.contextmenu.addbutton("Block user",function(this:User){
|
||||||
this.block();
|
this.block();
|
||||||
},null,function(){
|
},null,function(){
|
||||||
return this.relationshipType!==2
|
return this.relationshipType!==2;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.contextmenu.addbutton("Unblock user",function(this:User){
|
this.contextmenu.addbutton("Unblock user",function(this:User){
|
||||||
this.unblock();
|
this.unblock();
|
||||||
},null,function(){
|
},null,function(){
|
||||||
return this.relationshipType===2
|
return this.relationshipType===2;
|
||||||
});
|
});
|
||||||
this.contextmenu.addbutton("Friend request",function(this:User){
|
this.contextmenu.addbutton("Friend request",function(this:User){
|
||||||
fetch(`${this.info.api}/users/@me/relationships/${this.id}`,{
|
fetch(`${this.info.api}/users/@me/relationships/${this.id}`,{
|
||||||
method:"PUT",
|
method: "PUT",
|
||||||
headers:this.owner.headers,
|
headers: this.owner.headers,
|
||||||
body:JSON.stringify({
|
body: JSON.stringify({
|
||||||
type:1
|
type: 1
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
this.contextmenu.addbutton("Kick member",function(this:User,member:Member){
|
this.contextmenu.addbutton("Kick member",function(this:User,member:Member){
|
||||||
member.kick();
|
member.kick();
|
||||||
},null,function(member){
|
},null,member=>{
|
||||||
if(!member) return false;
|
if(!member)return false;
|
||||||
const us=member.guild.member;
|
const us=member.guild.member;
|
||||||
if(member.id===us.id){
|
if(member.id===us.id){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(member.id===member.guild.properties.owner_id){
|
if(member.id===member.guild.properties.owner_id){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (us.hasPermission("KICK_MEMBERS"))||false;
|
return(us.hasPermission("KICK_MEMBERS"))||false;
|
||||||
});
|
});
|
||||||
this.contextmenu.addbutton("Ban member",function(this:User,member:Member){
|
this.contextmenu.addbutton("Ban member",function(this:User,member:Member){
|
||||||
member.ban();
|
member.ban();
|
||||||
},null,function(member){
|
},null,member=>{
|
||||||
if(!member) return false;
|
if(!member)return false;
|
||||||
const us=member.guild.member;
|
const us=member.guild.member;
|
||||||
if(member.id===us.id){
|
if(member.id===us.id){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(member.id===member.guild.properties.owner_id){
|
if(member.id===member.guild.properties.owner_id){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (us.hasPermission("BAN_MEMBERS"))||false;
|
return(us.hasPermission("BAN_MEMBERS"))||false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
static checkuser(user:User|userjson,owner:Localuser):User{
|
static checkuser(user:User|userjson,owner:Localuser):User{
|
||||||
if(owner.userMap.has(user.id)){
|
if(owner.userMap.has(user.id)){
|
||||||
return owner.userMap.get(user.id) as User;
|
return owner.userMap.get(user.id) as User;
|
||||||
}else{
|
}else{
|
||||||
const tempuser=new User(user as userjson,owner,true)
|
const tempuser=new User(user as userjson,owner,true);
|
||||||
owner.userMap.set(user.id,tempuser);
|
owner.userMap.set(user.id,tempuser);
|
||||||
return tempuser;
|
return tempuser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get info(){
|
get info(){
|
||||||
return this.owner.info;
|
return this.owner.info;
|
||||||
}
|
}
|
||||||
get localuser(){
|
get localuser(){
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
constructor(userjson:userjson,owner:Localuser,dontclone=false){
|
constructor(userjson:userjson,owner:Localuser,dontclone=false){
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
if(!owner){console.error("missing localuser")}
|
if(!owner){
|
||||||
if(dontclone){
|
console.error("missing localuser");
|
||||||
for(const thing of Object.keys(userjson)){
|
}
|
||||||
if(thing==="bio"){
|
if(dontclone){
|
||||||
this.bio=new MarkDown(userjson[thing],this.localuser);
|
for(const thing of Object.keys(userjson)){
|
||||||
continue;
|
if(thing==="bio"){
|
||||||
}
|
this.bio=new MarkDown(userjson[thing],this.localuser);
|
||||||
if(thing === "id"){
|
continue;
|
||||||
this.snowflake=new SnowFlake(userjson[thing],this);
|
}
|
||||||
continue;
|
if(thing === "id"){
|
||||||
}
|
this.snowflake=new SnowFlake(userjson[thing],this);
|
||||||
this[thing]=userjson[thing];
|
continue;
|
||||||
}
|
}
|
||||||
this.hypotheticalpfp=false;
|
this[thing]=userjson[thing];
|
||||||
}else{
|
}
|
||||||
return User.checkuser(userjson,owner);
|
this.hypotheticalpfp=false;
|
||||||
}
|
}else{
|
||||||
}
|
return User.checkuser(userjson,owner);
|
||||||
async resolvemember(guild:Guild){
|
}
|
||||||
return await Member.resolveMember(this,guild);
|
}
|
||||||
}
|
async resolvemember(guild:Guild){
|
||||||
|
return await Member.resolveMember(this,guild);
|
||||||
|
}
|
||||||
|
|
||||||
async getUserProfile(){
|
async getUserProfile(){
|
||||||
return (await fetch(`${this.info.api}/users/${this.id.replace("#clone","")}/profile?with_mutual_guilds=true&with_mutual_friends=true`,{
|
return(await fetch(`${this.info.api}/users/${this.id.replace("#clone","")}/profile?with_mutual_guilds=true&with_mutual_friends=true`,{
|
||||||
headers:this.localuser.headers
|
headers: this.localuser.headers
|
||||||
})).json()
|
})).json();
|
||||||
}
|
}
|
||||||
resolving:false|Promise<any>=false;
|
resolving:false|Promise<any>=false;
|
||||||
async getBadge(id:string){
|
async getBadge(id:string){
|
||||||
if(this.localuser.badges.has(id)){
|
if(this.localuser.badges.has(id)){
|
||||||
return this.localuser.badges.get(id);
|
return this.localuser.badges.get(id);
|
||||||
}else{
|
}else{
|
||||||
if(this.resolving)
|
if(this.resolving){
|
||||||
{
|
await this.resolving;
|
||||||
await this.resolving;
|
return this.localuser.badges.get(id);
|
||||||
return this.localuser.badges.get(id);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const prom=await this.getUserProfile();
|
const prom=await this.getUserProfile();
|
||||||
this.resolving=prom;
|
this.resolving=prom;
|
||||||
const badges=prom.badges;
|
const badges=prom.badges;
|
||||||
this.resolving=false;
|
this.resolving=false;
|
||||||
for(const thing of badges){
|
for(const thing of badges){
|
||||||
this.localuser.badges.set(thing.id,thing);
|
this.localuser.badges.set(thing.id,thing);
|
||||||
}
|
}
|
||||||
return this.localuser.badges.get(id);
|
return this.localuser.badges.get(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildpfp(){
|
buildpfp(){
|
||||||
const pfp=document.createElement('img');
|
const pfp=document.createElement("img");
|
||||||
pfp.loading="lazy";
|
pfp.loading="lazy";
|
||||||
pfp.src=this.getpfpsrc();
|
pfp.src=this.getpfpsrc();
|
||||||
pfp.classList.add("pfp");
|
pfp.classList.add("pfp");
|
||||||
pfp.classList.add("userid:"+this.id);
|
pfp.classList.add("userid:"+this.id);
|
||||||
return pfp;
|
return pfp;
|
||||||
}
|
}
|
||||||
async buildstatuspfp(){
|
async buildstatuspfp(){
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
div.style.position="relative";
|
div.style.position="relative";
|
||||||
const pfp=this.buildpfp();
|
const pfp=this.buildpfp();
|
||||||
div.append(pfp);
|
div.append(pfp);
|
||||||
{
|
{
|
||||||
const status=document.createElement("div");
|
const status=document.createElement("div");
|
||||||
status.classList.add("statusDiv");
|
status.classList.add("statusDiv");
|
||||||
switch(await this.getStatus()){
|
switch(await this.getStatus()){
|
||||||
case "offline":
|
case"offline":
|
||||||
status.classList.add("offlinestatus");
|
status.classList.add("offlinestatus");
|
||||||
break;
|
break;
|
||||||
case "online":
|
case"online":
|
||||||
default:
|
default:
|
||||||
status.classList.add("onlinestatus");
|
status.classList.add("onlinestatus");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
div.append(status);
|
div.append(status);
|
||||||
}
|
}
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
userupdate(json:userjson){
|
userupdate(json:userjson){
|
||||||
if(json.avatar!==this.avatar){
|
if(json.avatar!==this.avatar){
|
||||||
console.log
|
console.log;
|
||||||
this.changepfp(json.avatar);
|
this.changepfp(json.avatar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bind(html:HTMLElement,guild:Guild|null=null,error=true){
|
bind(html:HTMLElement,guild:Guild|null=null,error=true){
|
||||||
if(guild&&guild.id!=="@me"){
|
if(guild&&guild.id!=="@me"){
|
||||||
Member.resolveMember(this,guild).then(_=>{
|
Member.resolveMember(this,guild).then(_=>{
|
||||||
User.contextmenu.bindContextmenu(html,this,_);
|
User.contextmenu.bindContextmenu(html,this,_);
|
||||||
if(_===undefined&&error){
|
if(_===undefined&&error){
|
||||||
const error=document.createElement("span");
|
const error=document.createElement("span");
|
||||||
error.textContent="!";
|
error.textContent="!";
|
||||||
error.classList.add("membererror");
|
error.classList.add("membererror");
|
||||||
html.after(error);
|
html.after(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(_){
|
if(_){
|
||||||
_.bind(html);
|
_.bind(html);
|
||||||
}
|
}
|
||||||
}).catch(_=>{
|
}).catch(_=>{
|
||||||
console.log(_)
|
console.log(_);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(guild){
|
if(guild){
|
||||||
this.profileclick(html,guild);
|
this.profileclick(html,guild);
|
||||||
}else{
|
}else{
|
||||||
this.profileclick(html);
|
this.profileclick(html);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static async resolve(id:string,localuser:Localuser){
|
static async resolve(id:string,localuser:Localuser){
|
||||||
const json=await fetch(localuser.info.api.toString()+"/users/"+id+"/profile",
|
const json=await fetch(localuser.info.api.toString()+"/users/"+id+"/profile",
|
||||||
{headers:localuser.headers}
|
{headers: localuser.headers}
|
||||||
).then(_=>_.json());
|
).then(_=>_.json());
|
||||||
return new User(json,localuser);
|
return new User(json,localuser);
|
||||||
}
|
}
|
||||||
changepfp(update:string|null){
|
changepfp(update:string|null){
|
||||||
this.avatar=update;
|
this.avatar=update;
|
||||||
this.hypotheticalpfp=false;
|
this.hypotheticalpfp=false;
|
||||||
const src=this.getpfpsrc();
|
const src=this.getpfpsrc();
|
||||||
console.log(src)
|
console.log(src);
|
||||||
for(const thing of document.getElementsByClassName("userid:"+this.id)){
|
for(const thing of document.getElementsByClassName("userid:"+this.id)){
|
||||||
(thing as HTMLImageElement).src=src;
|
(thing as HTMLImageElement).src=src;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
block(){
|
block(){
|
||||||
fetch(`${this.info.api}/users/@me/relationships/${this.id}`,{
|
fetch(`${this.info.api}/users/@me/relationships/${this.id}`,{
|
||||||
method:"PUT",
|
method: "PUT",
|
||||||
headers:this.owner.headers,
|
headers: this.owner.headers,
|
||||||
body:JSON.stringify({
|
body: JSON.stringify({
|
||||||
type:2
|
type: 2
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
this.relationshipType=2;
|
this.relationshipType=2;
|
||||||
const channel=this.localuser.channelfocus;
|
const channel=this.localuser.channelfocus;
|
||||||
if(channel){
|
if(channel){
|
||||||
for(const thing of channel.messages){
|
for(const thing of channel.messages){
|
||||||
thing[1].generateMessage();
|
thing[1].generateMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unblock(){
|
unblock(){
|
||||||
fetch(`${this.info.api}/users/@me/relationships/${this.id}`,{
|
fetch(`${this.info.api}/users/@me/relationships/${this.id}`,{
|
||||||
method:"DELETE",
|
method: "DELETE",
|
||||||
headers:this.owner.headers,
|
headers: this.owner.headers,
|
||||||
})
|
});
|
||||||
this.relationshipType=0;
|
this.relationshipType=0;
|
||||||
const channel=this.localuser.channelfocus;
|
const channel=this.localuser.channelfocus;
|
||||||
if(channel){
|
if(channel){
|
||||||
for(const thing of channel.messages){
|
for(const thing of channel.messages){
|
||||||
thing[1].generateMessage();
|
thing[1].generateMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getpfpsrc(){
|
getpfpsrc(){
|
||||||
if(this.hypotheticalpfp&&this.avatar){
|
if(this.hypotheticalpfp&&this.avatar){
|
||||||
return this.avatar;
|
return this.avatar;
|
||||||
}
|
}
|
||||||
if(this.avatar!=null){
|
if(this.avatar!=null){
|
||||||
return this.info.cdn+"/avatars/"+this.id.replace("#clone","")+"/"+this.avatar+".png";
|
return this.info.cdn+"/avatars/"+this.id.replace("#clone","")+"/"+this.avatar+".png";
|
||||||
}else{
|
}else{
|
||||||
const int=new Number((BigInt(this.id.replace("#clone","")) >> 22n) % 6n);
|
const int=new Number((BigInt(this.id.replace("#clone","")) >> 22n) % 6n);
|
||||||
return this.info.cdn+`/embed/avatars/${int}.png`;
|
return this.info.cdn+`/embed/avatars/${int}.png`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createjankpromises(){
|
createjankpromises(){
|
||||||
new Promise(_=>{})
|
new Promise(_=>{});
|
||||||
}
|
}
|
||||||
async buildprofile(x:number,y:number,guild:Guild|null=null){
|
async buildprofile(x:number,y:number,guild:Guild|null=null){
|
||||||
if(Contextmenu.currentmenu!=""){
|
if(Contextmenu.currentmenu!=""){
|
||||||
Contextmenu.currentmenu.remove();
|
Contextmenu.currentmenu.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
|
|
||||||
if(this.accent_color){
|
if(this.accent_color){
|
||||||
div.style.setProperty("--accent_color","#"+this.accent_color.toString(16).padStart(6,"0"));
|
div.style.setProperty("--accent_color","#"+this.accent_color.toString(16).padStart(6,"0"));
|
||||||
}else{
|
}else{
|
||||||
div.style.setProperty("--accent_color","transparent");
|
div.style.setProperty("--accent_color","transparent");
|
||||||
}
|
}
|
||||||
if(this.banner){
|
if(this.banner){
|
||||||
const banner=document.createElement("img")
|
const banner=document.createElement("img");
|
||||||
let src:string;
|
let src:string;
|
||||||
if(!this.hypotheticalbanner){
|
if(!this.hypotheticalbanner){
|
||||||
src=this.info.cdn+"/avatars/"+this.id.replace("#clone","")+"/"+this.banner+".png";
|
src=this.info.cdn+"/avatars/"+this.id.replace("#clone","")+"/"+this.banner+".png";
|
||||||
}else{
|
}else{
|
||||||
src=this.banner;
|
src=this.banner;
|
||||||
}
|
}
|
||||||
console.log(src,this.banner);
|
console.log(src,this.banner);
|
||||||
banner.src=src;
|
banner.src=src;
|
||||||
banner.classList.add("banner");
|
banner.classList.add("banner");
|
||||||
div.append(banner);
|
div.append(banner);
|
||||||
}
|
}
|
||||||
if(x!==-1){
|
if(x!==-1){
|
||||||
div.style.left=x+"px";
|
div.style.left=x+"px";
|
||||||
div.style.top=y+"px";
|
div.style.top=y+"px";
|
||||||
div.classList.add("profile","flexttb");
|
div.classList.add("profile","flexttb");
|
||||||
}else{
|
}else{
|
||||||
this.setstatus("online");
|
this.setstatus("online");
|
||||||
div.classList.add("hypoprofile","flexttb");
|
div.classList.add("hypoprofile","flexttb");
|
||||||
}
|
}
|
||||||
const badgediv=document.createElement("div");
|
const badgediv=document.createElement("div");
|
||||||
badgediv.classList.add("badges");
|
badgediv.classList.add("badges");
|
||||||
(async ()=>{
|
(async ()=>{
|
||||||
if(!this.badge_ids) return;
|
if(!this.badge_ids)return;
|
||||||
for(const id of this.badge_ids){
|
for(const id of this.badge_ids){
|
||||||
const badgejson=await this.getBadge(id);
|
const badgejson=await this.getBadge(id);
|
||||||
if(badgejson){
|
if(badgejson){
|
||||||
const badge=document.createElement(badgejson.link?"a":"div");
|
const badge=document.createElement(badgejson.link?"a":"div");
|
||||||
badge.classList.add("badge")
|
badge.classList.add("badge");
|
||||||
const img=document.createElement("img");
|
const img=document.createElement("img");
|
||||||
img.src=badgejson.icon;
|
img.src=badgejson.icon;
|
||||||
badge.append(img);
|
badge.append(img);
|
||||||
const span=document.createElement("span");
|
const span=document.createElement("span");
|
||||||
span.textContent=badgejson.description;
|
span.textContent=badgejson.description;
|
||||||
badge.append(span);
|
badge.append(span);
|
||||||
if(badge instanceof HTMLAnchorElement){
|
if(badge instanceof HTMLAnchorElement){
|
||||||
badge.href=badgejson.link;
|
badge.href=badgejson.link;
|
||||||
}
|
}
|
||||||
badgediv.append(badge);
|
badgediv.append(badge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})()
|
})();
|
||||||
{
|
{
|
||||||
const pfp=await this.buildstatuspfp();
|
const pfp=await this.buildstatuspfp();
|
||||||
div.appendChild(pfp);
|
div.appendChild(pfp);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const userbody=document.createElement("div");
|
const userbody=document.createElement("div");
|
||||||
userbody.classList.add("infosection");
|
userbody.classList.add("infosection");
|
||||||
div.appendChild(userbody);
|
div.appendChild(userbody);
|
||||||
const usernamehtml=document.createElement("h2");
|
const usernamehtml=document.createElement("h2");
|
||||||
usernamehtml.textContent=this.username;
|
usernamehtml.textContent=this.username;
|
||||||
userbody.appendChild(usernamehtml);
|
userbody.appendChild(usernamehtml);
|
||||||
userbody.appendChild(badgediv);
|
userbody.appendChild(badgediv);
|
||||||
const discrimatorhtml=document.createElement("h3");
|
const discrimatorhtml=document.createElement("h3");
|
||||||
discrimatorhtml.classList.add("tag");
|
discrimatorhtml.classList.add("tag");
|
||||||
discrimatorhtml.textContent=this.username+"#"+this.discriminator;
|
discrimatorhtml.textContent=this.username+"#"+this.discriminator;
|
||||||
userbody.appendChild(discrimatorhtml)
|
userbody.appendChild(discrimatorhtml);
|
||||||
|
|
||||||
const pronounshtml=document.createElement("p");
|
const pronounshtml=document.createElement("p");
|
||||||
pronounshtml.textContent=this.pronouns;
|
pronounshtml.textContent=this.pronouns;
|
||||||
pronounshtml.classList.add("pronouns");
|
pronounshtml.classList.add("pronouns");
|
||||||
userbody.appendChild(pronounshtml)
|
userbody.appendChild(pronounshtml);
|
||||||
|
|
||||||
const rule=document.createElement("hr");
|
const rule=document.createElement("hr");
|
||||||
userbody.appendChild(rule);
|
userbody.appendChild(rule);
|
||||||
const biohtml=this.bio.makeHTML();
|
const biohtml=this.bio.makeHTML();
|
||||||
userbody.appendChild(biohtml);
|
userbody.appendChild(biohtml);
|
||||||
if(guild){
|
if(guild){
|
||||||
Member.resolveMember(this,guild).then(member=>{
|
Member.resolveMember(this,guild).then(member=>{
|
||||||
if(!member) return;
|
if(!member)return;
|
||||||
const roles=document.createElement("div");
|
const roles=document.createElement("div");
|
||||||
roles.classList.add("rolesbox");
|
roles.classList.add("rolesbox");
|
||||||
for(const role of member.roles){
|
for(const role of member.roles){
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
div.classList.add("rolediv");
|
div.classList.add("rolediv");
|
||||||
const color=document.createElement("div");
|
const color=document.createElement("div");
|
||||||
div.append(color);
|
div.append(color);
|
||||||
color.style.setProperty("--role-color","#"+role.color.toString(16).padStart(6,"0"))
|
color.style.setProperty("--role-color","#"+role.color.toString(16).padStart(6,"0"));
|
||||||
color.classList.add("colorrolediv");
|
color.classList.add("colorrolediv");
|
||||||
const span=document.createElement("span");
|
const span=document.createElement("span");
|
||||||
div.append(span);
|
div.append(span);
|
||||||
span.textContent=role.name;
|
span.textContent=role.name;
|
||||||
roles.append(div);
|
roles.append(div);
|
||||||
}
|
}
|
||||||
userbody.append(roles);
|
userbody.append(roles);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(div);
|
console.log(div);
|
||||||
|
|
||||||
if(x!==-1){
|
if(x!==-1){
|
||||||
Contextmenu.currentmenu=div;
|
Contextmenu.currentmenu=div;
|
||||||
document.body.appendChild(div)
|
document.body.appendChild(div);
|
||||||
Contextmenu.keepOnScreen(div);
|
Contextmenu.keepOnScreen(div);
|
||||||
}
|
}
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
profileclick(obj:HTMLElement,guild:Guild|undefined=undefined){
|
profileclick(obj:HTMLElement,guild?:Guild|undefined){
|
||||||
obj.onclick=e=>{
|
obj.onclick=e=>{
|
||||||
this.buildprofile(e.clientX,e.clientY,guild);
|
this.buildprofile(e.clientX,e.clientY,guild);
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
User.setUpContextMenu();
|
User.setUpContextMenu();
|
||||||
export {User};
|
export{User};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue