apply and fix ESlint

This commit is contained in:
MathMan05 2024-09-02 15:59:56 -05:00
parent f8b80b65fe
commit 19f08a6408
57 changed files with 8070 additions and 7943 deletions

View file

@ -9,7 +9,7 @@ class Voice {
source;
constructor(wave, freq, volume = 1) {
this.audioCtx = new (window.AudioContext)();
this.info = { wave: wave, freq: freq };
this.info = { wave, freq };
this.playing = false;
this.myArrayBuffer = this.audioCtx.createBuffer(1, this.audioCtx.sampleRate, this.audioCtx.sampleRate);
this.gainNode = this.audioCtx.createGain();
@ -43,7 +43,7 @@ class Voice {
}
}
waveFunction() {
if (typeof this.wave === 'function') {
if (typeof this.wave === "function") {
return this.wave;
}
switch (this.wave) {
@ -92,9 +92,15 @@ class Voice {
case "three": {
const voicy = new Voice("sin", 800);
voicy.play();
setTimeout(_ => { voicy.freq = 1000; }, 50);
setTimeout(_ => { voicy.freq = 1300; }, 100);
setTimeout(_ => { voicy.stop(); }, 150);
setTimeout(_ => {
voicy.freq = 1000;
}, 50);
setTimeout(_ => {
voicy.freq = 1300;
}, 100);
setTimeout(_ => {
voicy.stop();
}, 150);
break;
}
case "zip": {
@ -102,23 +108,37 @@ class Voice {
return Math.sin(((t + 2) ** (Math.cos(t * 4))) * Math.PI * 2 * freq);
}, 700);
voicy.play();
setTimeout(_ => { voicy.stop(); }, 150);
setTimeout(_ => {
voicy.stop();
}, 150);
break;
}
case "square": {
const voicy = new Voice("square", 600, .4);
const voicy = new Voice("square", 600, 0.4);
voicy.play();
setTimeout(_ => { voicy.freq = 800; }, 50);
setTimeout(_ => { voicy.freq = 1000; }, 100);
setTimeout(_ => { voicy.stop(); }, 150);
setTimeout(_ => {
voicy.freq = 800;
}, 50);
setTimeout(_ => {
voicy.freq = 1000;
}, 100);
setTimeout(_ => {
voicy.stop();
}, 150);
break;
}
case "beep": {
const voicy = new Voice("sin", 800);
voicy.play();
setTimeout(_ => { voicy.stop(); }, 50);
setTimeout(_ => { voicy.play(); }, 100);
setTimeout(_ => { voicy.stop(); }, 150);
setTimeout(_ => {
voicy.stop();
}, 50);
setTimeout(_ => {
voicy.play();
}, 100);
setTimeout(_ => {
voicy.stop();
}, 150);
break;
}
}
@ -127,13 +147,13 @@ class Voice {
return ["three", "zip", "square", "beep"];
}
static setNotificationSound(sound) {
let userinfos = getBulkInfo();
const userinfos = getBulkInfo();
userinfos.preferences.notisound = sound;
localStorage.setItem("userinfos", JSON.stringify(userinfos));
}
static getNotificationSound() {
let userinfos = getBulkInfo();
const userinfos = getBulkInfo();
return userinfos.preferences.notisound;
}
}
export { Voice as Voice };
export { Voice };

View file

@ -58,10 +58,14 @@ class Channel {
this.contextmenu.addbutton("Delete channel", function () {
console.log(this);
this.deleteChannel();
}, null, function () { return this.isAdmin(); });
}, null, function () {
return this.isAdmin();
});
this.contextmenu.addbutton("Edit channel", function () {
this.editChannel();
}, null, function () { return this.isAdmin(); });
}, null, function () {
return this.isAdmin();
});
this.contextmenu.addbutton("Make invite", function () {
this.createInvite();
}, null, function () {
@ -148,12 +152,11 @@ class Channel {
}
sortPerms() {
this.permission_overwritesar.sort((a, b) => {
const order = this.guild.roles.findIndex(_ => _.snowflake === a[0]) - this.guild.roles.findIndex(_ => _.snowflake === b[0]);
return order;
return this.guild.roles.findIndex(_ => _.snowflake === a[0]) - this.guild.roles.findIndex(_ => _.snowflake === b[0]);
});
}
setUpInfiniteScroller() {
this.infinite = new InfiniteScroller(async function (id, offset) {
this.infinite = new InfiniteScroller((async (id, offset) => {
const snowflake = id;
if (offset === 1) {
if (this.idToPrev.has(snowflake)) {
@ -176,13 +179,12 @@ class Channel {
console.log("at bottom");
}
}
}.bind(this), async function (id) {
}), (async (id) => {
//await new Promise(_=>{setTimeout(_,Math.random()*10)})
const messgage = this.messages.get(id);
try {
if (messgage) {
const html = messgage.buildhtml();
return html;
return messgage.buildhtml();
}
else {
console.error(id + " not found");
@ -191,18 +193,21 @@ class Channel {
catch (e) {
console.error(e);
}
}.bind(this), async function (id) {
return document.createElement("div");
}), (async (id) => {
const message = this.messages.get(id);
try {
if (message) {
message.deleteDiv();
return true;
}
}
catch (e) {
console.error(e);
}
finally { }
}.bind(this), this.readbottom.bind(this));
return false;
}), this.readbottom.bind(this));
}
constructor(json, owner) {
if (json === -1) {
@ -227,7 +232,6 @@ class Channel {
if (thing.id === "1182819038095799904" || thing.id === "1182820803700625444") {
continue;
}
;
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
const permission = this.permission_overwrites.get(thing.id);
if (permission) {
@ -268,7 +272,7 @@ class Channel {
if (!this.hasPermission("VIEW_CHANNEL")) {
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) {
if (member.isAdmin()) {
@ -277,7 +281,7 @@ class Channel {
for (const thing of member.roles) {
const premission = this.permission_overwrites.get(thing.id);
if (premission) {
let perm = premission.getPermission(name);
const perm = premission.getPermission(name);
if (perm) {
return perm === 1;
}
@ -289,7 +293,7 @@ class Channel {
return false;
}
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");
if (role) {
this.addRoleToPerms(role);
@ -298,7 +302,9 @@ class Channel {
return this.hasPermission("SEND_MESSAGES");
}
sortchildren() {
this.children.sort((a, b) => { return a.position - b.position; });
this.children.sort((a, b) => {
return a.position - b.position;
});
}
resolveparent(guild) {
const parentid = this.parent_id?.id;
@ -313,7 +319,7 @@ class Channel {
}
calculateReorder() {
let position = -1;
let build = [];
const build = [];
for (const thing of this.children) {
const thisthing = { id: thing.snowflake, position: undefined, parent_id: undefined };
if (thing.position < position) {
@ -348,8 +354,13 @@ class Channel {
}
div["all"] = this;
div.draggable = admin;
div.addEventListener("dragstart", (e) => { Channel.dragged = [this, div]; e.stopImmediatePropagation(); });
div.addEventListener("dragend", () => { Channel.dragged = []; });
div.addEventListener("dragstart", e => {
Channel.dragged = [this, div];
e.stopImmediatePropagation();
});
div.addEventListener("dragend", () => {
Channel.dragged = [];
});
if (this.type === 4) {
this.sortchildren();
const caps = document.createElement("div");
@ -383,17 +394,19 @@ class Channel {
childrendiv.appendChild(channel.createguildHTML(admin));
}
childrendiv.classList.add("channels");
setTimeout(_ => { childrendiv.style.height = childrendiv.scrollHeight + 'px'; }, 100);
setTimeout(_ => {
childrendiv.style.height = childrendiv.scrollHeight + "px";
}, 100);
decdiv.onclick = function () {
if (childrendiv.style.height !== '0px') {
if (childrendiv.style.height !== "0px") {
decoration.classList.add("hiddencat");
//childrendiv.classList.add("colapsediv");
childrendiv.style.height = '0px';
childrendiv.style.height = "0px";
}
else {
decoration.classList.remove("hiddencat");
//childrendiv.classList.remove("colapsediv")
childrendiv.style.height = childrendiv.scrollHeight + 'px';
childrendiv.style.height = childrendiv.scrollHeight + "px";
}
};
div.appendChild(childrendiv);
@ -479,14 +492,14 @@ class Channel {
}
}
coatDropDiv(div, container = false) {
div.addEventListener("dragenter", (event) => {
div.addEventListener("dragenter", event => {
console.log("enter");
event.preventDefault();
});
div.addEventListener("dragover", (event) => {
div.addEventListener("dragover", event => {
event.preventDefault();
});
div.addEventListener("drop", (event) => {
div.addEventListener("drop", event => {
const that = Channel.dragged[0];
if (!that)
return;
@ -543,8 +556,8 @@ class Channel {
method: "POST",
headers: this.headers,
body: JSON.stringify({
name: name,
type: type,
name,
type,
parent_id: this.snowflake,
permission_overwrites: [],
})
@ -558,22 +571,28 @@ class Channel {
const thistype = this.type;
const full = new Dialog(["hdiv",
["vdiv",
["textbox", "Channel name:", this.name, function () { name = this.value; }],
["mdbox", "Channel topic:", this.topic, function () { topic = this.value; }],
["checkbox", "NSFW Channel", this.nsfw, function () { nsfw = this.checked; }],
["textbox", "Channel name:", this.name, function () {
name = this.value;
}],
["mdbox", "Channel topic:", this.topic, function () {
topic = this.value;
}],
["checkbox", "NSFW Channel", this.nsfw, function () {
nsfw = this.checked;
}],
["button", "", "submit", () => {
fetch(this.info.api + "/channels/" + thisid, {
method: "PATCH",
headers: this.headers,
body: JSON.stringify({
"name": name,
"type": thistype,
"topic": topic,
"bitrate": 64000,
"user_limit": 0,
"nsfw": nsfw,
"flags": 0,
"rate_limit_per_user": 0
name,
type: thistype,
topic,
bitrate: 64000,
user_limit: 0,
nsfw,
flags: 0,
rate_limit_per_user: 0
})
});
console.log(full);
@ -683,7 +702,7 @@ class Channel {
for (let i = 0; i < 15; i++) {
const div = document.createElement("div");
div.classList.add("loadingmessage");
if (Math.random() < .5) {
if (Math.random() < 0.5) {
const pfp = document.createElement("div");
pfp.classList.add("loadingpfp");
const username = document.createElement("div");
@ -704,7 +723,6 @@ class Channel {
if (this.allthewayup) {
return;
}
;
if (this.lastreadmessageid && this.messages.has(this.lastreadmessageid)) {
return;
}
@ -715,7 +733,7 @@ class Channel {
if (response.length !== 100) {
this.allthewayup = true;
}
let prev = undefined;
let prev;
for (const thing of response) {
const message = new Message(thing, this);
if (prev) {
@ -747,7 +765,9 @@ class Channel {
}
await fetch(this.info.api + "/channels/" + this.id + "/messages?limit=100&after=" + id, {
headers: this.headers
}).then((j) => { return j.json(); }).then(response => {
}).then(j => {
return j.json();
}).then(response => {
let previd = id;
for (const i in response) {
let messager;
@ -769,7 +789,6 @@ class Channel {
}
//out.buildmessages();
});
return;
}
topid;
async grabBefore(id) {
@ -778,7 +797,9 @@ class Channel {
}
await fetch(this.info.api + "/channels/" + this.id + "/messages?before=" + id + "&limit=100", {
headers: this.headers
}).then((j) => { return j.json(); }).then((response) => {
}).then(j => {
return j.json();
}).then((response) => {
if (response.length < 100) {
this.allthewayup = true;
if (response.length === 0) {
@ -801,7 +822,7 @@ class Channel {
this.idToPrev.set(previd, messager.id);
previd = messager.id;
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;
}
if (willbreak) {
@ -809,7 +830,6 @@ class Channel {
}
}
});
return;
}
/**
* Please dont use this, its not implemented.
@ -900,7 +920,7 @@ class Channel {
while (flake && time < flaketime) {
flake = this.idToPrev.get(flake);
if (!flake) {
return undefined;
return;
}
flaketime = Number((BigInt(flake) >> 22n) + 1420070400000n);
}
@ -919,7 +939,6 @@ class Channel {
if (thing.id === "1182819038095799904" || thing.id === "1182820803700625444") {
continue;
}
;
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
const permisions = this.permission_overwrites.get(thing.id);
if (permisions) {
@ -930,10 +949,10 @@ class Channel {
this.nsfw = json.nsfw;
}
typingstart() {
if (this.typing > new Date().getTime()) {
if (this.typing > Date.now()) {
return;
}
this.typing = new Date().getTime() + 6000;
this.typing = Date.now() + 6000;
fetch(this.info.api + "/channels/" + this.snowflake + "/typing", {
method: "POST",
headers: this.headers
@ -941,11 +960,11 @@ class Channel {
}
get notification() {
let notinumber = this.message_notifications;
if (+notinumber === 3) {
if (Number(notinumber) === 3) {
notinumber = null;
}
notinumber ??= this.guild.message_notifications;
switch (+notinumber) {
switch (Number(notinumber)) {
case 0:
return "all";
case 1:
@ -961,15 +980,14 @@ class Channel {
if (replyingto) {
replyjson =
{
"guild_id": replyingto.guild.id,
"channel_id": replyingto.channel.id,
"message_id": replyingto.id,
guild_id: replyingto.guild.id,
channel_id: replyingto.channel.id,
message_id: replyingto.id,
};
}
;
if (attachments.length === 0) {
const body = {
content: content,
content,
nonce: Math.floor(Math.random() * 1000000000),
message_reference: undefined
};
@ -985,21 +1003,21 @@ class Channel {
else {
const formData = new FormData();
const body = {
content: content,
content,
nonce: Math.floor(Math.random() * 1000000000),
message_reference: undefined
};
if (replyjson) {
body.message_reference = replyjson;
}
formData.append('payload_json', JSON.stringify(body));
formData.append("payload_json", JSON.stringify(body));
for (const i in attachments) {
formData.append("files[" + i + "]", attachments[i]);
}
return await fetch(this.info.api + "/channels/" + this.snowflake + "/messages", {
method: 'POST',
method: "POST",
body: formData,
headers: { "Authorization": this.headers.Authorization }
headers: { Authorization: this.headers.Authorization }
});
}
}
@ -1084,7 +1102,6 @@ class Channel {
if (deep === 3) {
return;
}
;
this.notify(message, deep + 1);
});
}
@ -1115,7 +1132,7 @@ class Channel {
body: JSON.stringify({
allow: permission.allow.toString(),
deny: permission.deny.toString(),
id: id,
id,
type: 0
})
});

View file

@ -5,7 +5,7 @@ class Contextmenu {
div;
static setup() {
Contextmenu.currentmenu = "";
document.addEventListener('click', function (event) {
document.addEventListener("click", event => {
if (Contextmenu.currentmenu == "") {
return;
}
@ -50,8 +50,8 @@ class Contextmenu {
if (Contextmenu.currentmenu != "") {
Contextmenu.currentmenu.remove();
}
div.style.top = y + 'px';
div.style.left = x + 'px';
div.style.top = y + "px";
div.style.left = x + "px";
document.body.appendChild(div);
Contextmenu.keepOnScreen(div);
console.log(div);
@ -59,7 +59,7 @@ class Contextmenu {
return this.div;
}
bindContextmenu(obj, addinfo, other) {
const func = (event) => {
const func = event => {
event.preventDefault();
event.stopImmediatePropagation();
this.makemenu(event.clientX, event.clientY, addinfo, other);
@ -75,12 +75,12 @@ class Contextmenu {
console.log(box, docheight, docwidth);
if (box.right > docwidth) {
console.log("test");
obj.style.left = docwidth - box.width + 'px';
obj.style.left = docwidth - box.width + "px";
}
if (box.bottom > docheight) {
obj.style.top = docheight - box.height + 'px';
obj.style.top = docheight - box.height + "px";
}
}
}
Contextmenu.setup();
export { Contextmenu as Contextmenu };
export { Contextmenu };

View file

@ -58,7 +58,7 @@ class Dialog {
case "checkbox":
{
const div = document.createElement("div");
const checkbox = document.createElement('input');
const checkbox = document.createElement("input");
div.appendChild(checkbox);
const label = document.createElement("span");
checkbox.checked = array[2];
@ -71,7 +71,7 @@ class Dialog {
case "button":
{
const div = document.createElement("div");
const input = document.createElement('button');
const input = document.createElement("button");
const label = document.createElement("span");
input.textContent = array[2];
label.textContent = array[1];
@ -134,7 +134,7 @@ class Dialog {
case "radio": {
const div = document.createElement("div");
const fieldset = document.createElement("fieldset");
fieldset.addEventListener("change", function () {
fieldset.addEventListener("change", () => {
let i = -1;
for (const thing of fieldset.children) {
i++;
@ -173,9 +173,8 @@ class Dialog {
div.appendChild(fieldset);
return div;
}
case "html": {
case "html":
return array[1];
}
case "select": {
const div = document.createElement("div");
const label = document.createElement("label");
@ -227,7 +226,6 @@ class Dialog {
}
default:
console.error("can't find element:" + array[0], " full element:" + array);
return;
}
}
show() {
@ -237,7 +235,9 @@ class Dialog {
this.background.classList.add("background");
document.body.appendChild(this.background);
document.body.appendChild(this.html);
this.background.onclick = _ => { this.hide(); };
this.background.onclick = _ => {
this.hide();
};
}
hide() {
document.body.removeChild(this.background);

View file

@ -96,7 +96,6 @@ class Group extends Channel {
this.messageids = new Map();
this.permission_overwrites = new Map();
this.lastmessageid = json.last_message_id;
this.lastmessageid ??= null;
this.mentions = 0;
this.setUpInfiniteScroller();
if (this.lastmessageid) {
@ -140,8 +139,8 @@ class Group extends Channel {
const messagez = new Message(messagep.d, this);
if (this.lastmessageid) {
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.messageids.set(messagez.snowflake, messagez);
if (messagez.author === this.localuser.user) {

View file

@ -119,7 +119,6 @@ class Embed {
if (this.json?.timestamp) {
const span = document.createElement("span");
span.textContent = new Date(this.json.timestamp).toLocaleString();
;
footer.append(span);
}
embed.append(footer);

View file

@ -62,10 +62,8 @@ class Emoji {
for (let i = 0; i < length; i++) {
array[i] = read8();
}
const decoded = new TextDecoder("utf-8").decode(array.buffer);
;
//console.log(array);
return decoded;
return new TextDecoder("utf-8").decode(array.buffer);
}
const build = [];
let cats = read16();
@ -78,7 +76,7 @@ class Emoji {
const name = readString8();
const len = read8();
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({
name,
skin_tone_support,
@ -102,7 +100,9 @@ class Emoji {
}
static async emojiPicker(x, y, localuser) {
let res;
const promise = new Promise((r) => { res = r; });
const promise = new Promise(r => {
res = r;
});
const menu = document.createElement("div");
menu.classList.add("flextttb", "emojiPicker");
menu.style.top = y + "px";

View file

@ -31,7 +31,7 @@ class File {
this.width /= scale;
this.height /= scale;
}
if (this.content_type.startsWith('image/')) {
if (this.content_type.startsWith("image/")) {
const div = document.createElement("div");
const img = document.createElement("img");
img.classList.add("messageimg");
@ -50,7 +50,7 @@ class File {
console.log(this.width, this.height);
return div;
}
else if (this.content_type.startsWith('video/')) {
else if (this.content_type.startsWith("video/")) {
const video = document.createElement("video");
const source = document.createElement("source");
source.src = src;
@ -63,7 +63,7 @@ class File {
}
return video;
}
else if (this.content_type.startsWith('audio/')) {
else if (this.content_type.startsWith("audio/")) {
const audio = document.createElement("audio");
const source = document.createElement("source");
source.src = src;
@ -138,8 +138,8 @@ class File {
return div;
}
static filesizehuman(fsize) {
var 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];
const i = fsize == 0 ? 0 : Math.floor(Math.log(fsize) / Math.log(1024));
return Number((fsize / Math.pow(1024, i)).toFixed(2)) * 1 + " " + ["Bytes", "Kilobytes", "Megabytes", "Gigabytes", "Terabytes"][i];
}
}
export { File };

View file

@ -149,7 +149,7 @@ class Guild {
method: "PATCH",
headers: this.headers,
body: JSON.stringify({
"message_notifications": noti
message_notifications: noti
})
});
this.message_notifications = noti;
@ -202,7 +202,7 @@ class Guild {
}
calculateReorder() {
let position = -1;
let build = [];
const build = [];
for (const thing of this.headchannels) {
const thisthing = { id: thing.snowflake, position: undefined, parent_id: undefined };
if (thing.position <= position) {
@ -256,7 +256,9 @@ class Guild {
return this.owner.info;
}
sortchannels() {
this.headchannels.sort((a, b) => { return a.position - b.position; });
this.headchannels.sort((a, b) => {
return a.position - b.position;
});
}
generateGuildIcon() {
const divy = document.createElement("div");
@ -279,7 +281,7 @@ class Guild {
}
else {
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.classList.add("blankserver", "servericon");
divy.appendChild(div);
@ -336,7 +338,7 @@ class Guild {
headers: this.headers,
});
}
unreads(html = undefined) {
unreads(html) {
if (html) {
this.html = html;
}
@ -399,7 +401,7 @@ class Guild {
}
return this.member.hasRole(r);
}
loadChannel(ID = undefined) {
loadChannel(ID) {
if (ID && this.channelids[ID]) {
this.channelids[ID].getHTML();
return;
@ -451,7 +453,7 @@ class Guild {
["voice", "text", "announcement"],
function (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
],
@ -463,12 +465,12 @@ class Guild {
console.log(name, category);
func(name, category);
channelselect.hide();
}.bind(this)]]);
}]]);
channelselect.show();
}
createcategory() {
let name = "";
let category = 4;
const category = 4;
const channelselect = new Dialog(["vdiv",
["textbox", "Name of category", "", function () {
console.log(this);
@ -510,7 +512,7 @@ class Guild {
fetch(this.info.api + "/guilds/" + this.snowflake + "/channels", {
method: "POST",
headers: this.headers,
body: JSON.stringify({ name: name, type: type })
body: JSON.stringify({ name, type })
});
}
async createRole(name) {
@ -518,7 +520,7 @@ class Guild {
method: "POST",
headers: this.headers,
body: JSON.stringify({
name: name,
name,
color: 0,
permissions: "0"
})

View file

@ -33,7 +33,7 @@ fetch("/instances.json").then(_ => _.json()).then((json) => {
if (instance.descriptionLong) {
p.innerText = instance.descriptionLong;
}
else {
else if (instance.description) {
p.innerText = instance.description;
}
textbox.append(p);

View file

@ -6,8 +6,10 @@ import { File } from "./file.js";
(async () => {
async function waitforload() {
let res;
new Promise(r => { res = r; });
document.addEventListener("DOMContentLoaded", function () {
new Promise(r => {
res = r;
});
document.addEventListener("DOMContentLoaded", () => {
res();
});
await res;
@ -15,7 +17,7 @@ import { File } from "./file.js";
await waitforload();
const users = getBulkUsers();
if (!users.currentuser) {
window.location.href = '/login.html';
window.location.href = "/login.html";
}
function showAccountSwitcher() {
const table = document.createElement("div");
@ -45,7 +47,7 @@ import { File } from "./file.js";
loading.classList.remove("doneloading");
loading.classList.add("loading");
thisuser = new Localuser(specialuser);
users["currentuser"] = specialuser.uid;
users.currentuser = specialuser.uid;
localStorage.setItem("userinfos", JSON.stringify(users));
thisuser.initwebsocket().then(_ => {
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
menu.addbutton("Create channel", function () {
menu.addbutton("Create channel", () => {
if (thisuser.lookingguild) {
thisuser.lookingguild.createchannels();
}
}, null, _ => { return thisuser.isAdmin(); });
menu.addbutton("Create category", function () {
}, null, _ => {
return thisuser.isAdmin();
});
menu.addbutton("Create category", () => {
if (thisuser.lookingguild) {
thisuser.lookingguild.createcategory();
}
}, null, _ => { return thisuser.isAdmin(); });
}, null, _ => {
return thisuser.isAdmin();
});
menu.bindContextmenu(document.getElementById("channels"), 0, 0);
}
const pasteimage = document.getElementById("pasteimage");
@ -134,7 +140,7 @@ import { File } from "./file.js";
}
else {
replyingto = thisuser.channelfocus.replyingto;
let replying = replyingto;
const replying = replyingto;
if (replyingto?.div) {
replyingto.div.classList.remove("replying");
}
@ -151,7 +157,6 @@ import { File } from "./file.js";
pasteimage.removeChild(imageshtml.pop());
}
typebox.innerHTML = "";
return;
}
}
const typebox = document.getElementById("typebox");
@ -174,7 +179,7 @@ import { File } from "./file.js";
*/
const images = [];
const imageshtml = [];
document.addEventListener('paste', async (e) => {
document.addEventListener("paste", async (e) => {
if (!e.clipboardData)
return;
Array.from(e.clipboardData.files).forEach(async (f) => {

View file

@ -32,7 +32,7 @@ class InfiniteScroller {
this.watchForChange();
});
this.scroll.addEventListener("scroll", _ => {
if (null === this.timeout) {
if (this.timeout === null) {
this.timeout = setTimeout(this.updatestuff.bind(this), 300);
}
this.watchForChange();
@ -71,10 +71,8 @@ class InfiniteScroller {
this.averageheight = 60;
}
this.scrollTop = this.scroll.scrollTop;
if (!this.scrollBottom) {
if (!await this.watchForChange()) {
this.reachesBottom();
}
if (!this.scrollBottom && !await this.watchForChange()) {
this.reachesBottom();
}
if (!this.scrollTop) {
await this.watchForChange();
@ -129,7 +127,6 @@ class InfiniteScroller {
this.HTMLElements.unshift([html, nextid]);
this.scrollTop += this.averageheight;
}
;
}
if (this.scrollTop > this.maxDist) {
const html = this.HTMLElements.shift();
@ -176,7 +173,6 @@ class InfiniteScroller {
this.HTMLElements.push([html, nextid]);
this.scrollBottom += this.averageheight;
}
;
}
if (scrollBottom > this.maxDist) {
const html = this.HTMLElements.pop();
@ -225,14 +221,14 @@ class InfiniteScroller {
}
const out = await Promise.allSettled([this.watchForTop(), this.watchForBottom()]);
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);
}
if (!this.currrunning) {
console.error("something really bad happened");
}
res(!!changed);
return !!changed;
res(Boolean(changed));
return Boolean(changed);
}
catch (e) {
console.error(e);

View file

@ -11,7 +11,7 @@ import { getBulkUsers, getapiurls } from "./login.js";
console.log(users.users[thing]);
}
let urls;
if (!joinable.length) {
if (!joinable.length && well) {
const out = await getapiurls(well);
if (out) {
urls = out;
@ -24,7 +24,7 @@ import { getBulkUsers, getapiurls } from "./login.js";
}
}
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 {
@ -86,7 +86,7 @@ import { getBulkUsers, getapiurls } from "./login.js";
Authorization: thing.token
}
}).then(_ => {
users["currentuser"] = specialuser.uid;
users.currentuser = specialuser.uid;
localStorage.setItem("userinfos", JSON.stringify(users));
window.location.href = "/channels/" + guildinfo.id;
});

View file

@ -22,13 +22,13 @@ function trimswitcher() {
for (const thing in json.users) {
const user = json.users[thing];
let wellknown = user.serverurls.wellknown;
if (wellknown[wellknown.length - 1] !== "/") {
if (wellknown.at(-1) !== "/") {
wellknown += "/";
}
wellknown += user.username;
if (map.has(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]];
map.set(wellknown, [thing, user]);
}
@ -41,7 +41,7 @@ function trimswitcher() {
}
}
for (const thing in json.users) {
if (thing[thing.length - 1] === "/") {
if (thing.at(-1) === "/") {
const user = json.users[thing];
delete json.users[thing];
json.users[thing.slice(0, -1)] = user;
@ -73,7 +73,7 @@ function setDefaults() {
if (userinfos.accent_color === undefined) {
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) {
userinfos.preferences = {
theme: "Dark",
@ -103,11 +103,8 @@ class Specialuser {
this.serverurls.api = apistring;
this.serverurls.cdn = new URL(json.serverurls.cdn).toString().replace(/\/$/, "");
this.serverurls.gateway = new URL(json.serverurls.gateway).toString().replace(/\/$/, "");
;
this.serverurls.wellknown = new URL(json.serverurls.wellknown).toString().replace(/\/$/, "");
;
this.serverurls.login = new URL(json.serverurls.login).toString().replace(/\/$/, "");
;
this.email = json.email;
this.token = json.token;
this.loggedin = json.loggedin;
@ -178,12 +175,12 @@ async function getapiurls(str) {
}
}
}
if (str[str.length - 1] !== "/") {
if (str.at(-1) !== "/") {
str += "/";
}
let api;
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;
}
catch {
@ -191,7 +188,7 @@ async function getapiurls(str) {
}
const url = new URL(api);
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 {
api: info.apiEndpoint,
gateway: info.gateway,
@ -226,8 +223,8 @@ async function checkInstance(e) {
instanceinfo.value = instancein.value;
localStorage.setItem("instanceinfo", JSON.stringify(instanceinfo));
verify.textContent = "Instance is all good";
if (checkInstance["alt"]) {
checkInstance["alt"]();
if (checkInstance.alt) {
checkInstance.alt();
}
setTimeout(_ => {
console.log(verify.textContent);
@ -238,7 +235,7 @@ async function checkInstance(e) {
verify.textContent = "Invalid Instance, try again";
}
}
catch (e) {
catch {
console.log("catch");
verify.textContent = "Invalid Instance, try again";
}
@ -271,10 +268,10 @@ async function login(username, password, captcha) {
const options = {
method: "POST",
body: JSON.stringify({
"login": username,
"password": password,
"undelete": false,
"captcha_key": captcha
login: username,
password,
undelete: false,
captcha_key: captcha
}),
headers: {
"Content-type": "application/json; charset=UTF-8",
@ -283,10 +280,10 @@ async function login(username, password, captcha) {
try {
const info = JSON.parse(localStorage.getItem("instanceinfo"));
const api = info.login + (info.login.startsWith("/") ? "/" : "");
return await fetch(api + '/auth/login', options).then(response => response.json())
.then((response) => {
return await fetch(api + "/auth/login", options).then(response => response.json())
.then(response => {
console.log(response, response.message);
if ("Invalid Form Body" === response.message) {
if (response.message === "Invalid Form Body") {
return response.errors.login._errors[0].message;
console.log("test");
}
@ -306,13 +303,14 @@ async function login(username, password, captcha) {
else {
eval("hcaptcha.reset()");
}
return;
}
else {
console.log(response);
if (response.ticket) {
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", {
method: "POST",
headers: {
@ -336,7 +334,7 @@ async function login(username, password, captcha) {
window.location.href = redir;
}
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;
}
else {
window.location.href = '/channels/@me';
window.location.href = "/channels/@me";
}
return "";
}
@ -360,13 +358,12 @@ async function login(username, password, captcha) {
});
}
catch (error) {
console.error('Error:', error);
console.error("Error:", error);
}
;
}
async function check(e) {
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;
console.log(h);
}

View file

@ -28,7 +28,7 @@ class MarkDown {
return this.makeHTML().textContent;
}
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 } = {}) {
let txt;
@ -105,7 +105,7 @@ class MarkDown {
if (keep) {
element.append(keepys);
}
element.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
element.appendChild(this.markdown(build, { keep, stdsize }));
span.append(element);
}
finally {
@ -179,7 +179,7 @@ class MarkDown {
}
else {
const pre = document.createElement("pre");
if (build[build.length - 1] === "\n") {
if (build.at(-1) === "\n") {
build = build.substring(0, build.length - 1);
}
if (txt[i] === "\n") {
@ -224,7 +224,7 @@ class MarkDown {
if (keep) {
i.append(stars);
}
i.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
i.appendChild(this.markdown(build, { keep, stdsize }));
if (keep) {
i.append(stars);
}
@ -235,7 +235,7 @@ class MarkDown {
if (keep) {
b.append(stars);
}
b.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
b.appendChild(this.markdown(build, { keep, stdsize }));
if (keep) {
b.append(stars);
}
@ -247,7 +247,7 @@ class MarkDown {
if (keep) {
b.append(stars);
}
b.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
b.appendChild(this.markdown(build, { keep, stdsize }));
if (keep) {
b.append(stars);
}
@ -290,7 +290,7 @@ class MarkDown {
if (keep) {
i.append(underscores);
}
i.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
i.appendChild(this.markdown(build, { keep, stdsize }));
if (keep) {
i.append(underscores);
}
@ -301,7 +301,7 @@ class MarkDown {
if (keep) {
u.append(underscores);
}
u.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
u.appendChild(this.markdown(build, { keep, stdsize }));
if (keep) {
u.append(underscores);
}
@ -313,7 +313,7 @@ class MarkDown {
if (keep) {
i.append(underscores);
}
i.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
i.appendChild(this.markdown(build, { keep, stdsize }));
if (keep) {
i.append(underscores);
}
@ -325,7 +325,7 @@ class MarkDown {
}
}
if (txt[i] === "~" && txt[i + 1] === "~") {
let count = 2;
const count = 2;
let build = [];
let find = 0;
let j = i + 2;
@ -350,7 +350,7 @@ class MarkDown {
if (keep) {
s.append(tildes);
}
s.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
s.appendChild(this.markdown(build, { keep, stdsize }));
if (keep) {
s.append(tildes);
}
@ -360,7 +360,7 @@ class MarkDown {
}
}
if (txt[i] === "|" && txt[i + 1] === "|") {
let count = 2;
const count = 2;
let build = [];
let find = 0;
let j = i + 2;
@ -385,7 +385,7 @@ class MarkDown {
if (keep) {
j.append(pipes);
}
j.appendChild(this.markdown(build, { keep: keep, stdsize: stdsize }));
j.appendChild(this.markdown(build, { keep, stdsize }));
j.classList.add("spoiler");
j.onclick = MarkDown.unspoil;
if (keep) {
@ -459,7 +459,7 @@ class MarkDown {
i = j;
const isEmojiOnly = txt.join("").trim() === buildjoin.trim();
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));
continue;
}
@ -479,7 +479,6 @@ class MarkDown {
else {
break;
}
;
}
else if (partsFound === 1 && txt[j] === ")") {
partsFound++;
@ -529,7 +528,7 @@ class MarkDown {
return;
console.log(_.clipboardData.types);
const data = _.clipboardData.getData("text");
document.execCommand('insertHTML', false, data);
document.execCommand("insertHTML", false, data);
_.preventDefault();
if (!box.onkeyup)
return;
@ -568,25 +567,25 @@ class MarkDown {
}
//solution from https://stackoverflow.com/questions/4576694/saving-and-restoring-caret-position-for-contenteditable-div
function saveCaretPosition(context) {
var selection = window.getSelection();
const selection = window.getSelection();
if (!selection)
return;
var range = selection.getRangeAt(0);
const range = selection.getRangeAt(0);
range.setStart(context, 0);
var len = range.toString().length;
const len = range.toString().length;
return function restore() {
if (!selection)
return;
var pos = getTextNodeAtPosition(context, len);
const pos = getTextNodeAtPosition(context, len);
selection.removeAllRanges();
var range = new Range();
const range = new Range();
range.setStart(pos.node, pos.position);
selection.addRange(range);
};
}
function getTextNodeAtPosition(root, index) {
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)
return 0;
if (index > elem.textContent.length) {
@ -595,7 +594,7 @@ function getTextNodeAtPosition(root, index) {
}
return NodeFilter.FILTER_ACCEPT;
});
var c = treeWalker.nextNode();
const c = treeWalker.nextNode();
return {
node: c ? c : root,
position: index

View file

@ -28,7 +28,7 @@ class Member {
continue;
}
if (thing === "roles") {
for (const strrole of memberjson["roles"]) {
for (const strrole of memberjson.roles) {
const role = SnowFlake.getSnowFlakeFromID(strrole, Role).getObject();
this.roles.push(role);
}
@ -38,7 +38,6 @@ class Member {
}
if (this.localuser.userMap.has(this?.id)) {
this.user = this.localuser.userMap.get(this?.id);
return;
}
}
get guild() {
@ -89,7 +88,6 @@ class Member {
const membjson = await membpromise;
if (membjson === undefined) {
res(undefined);
return undefined;
}
else {
const member = new Member(membjson, guild);
@ -149,7 +147,6 @@ class Member {
if (!this) {
return;
}
;
/*
if(this.error){

View file

@ -42,7 +42,9 @@ class Message {
return this.snowflake.id;
}
static setup() {
this.del = new Promise(_ => { this.resolve = _; });
this.del = new Promise(_ => {
this.resolve = _;
});
Message.setupcmenu();
}
static setupcmenu() {
@ -63,7 +65,7 @@ class Message {
Message.contextmenu.addbutton("Edit", function () {
this.channel.editing = this;
const markdown = document.getElementById("typebox")["markdown"];
markdown.txt = this.content.rawString.split('');
markdown.txt = this.content.rawString.split("");
markdown.boxupdate(document.getElementById("typebox"));
}, null, function () {
return this.author.id === this.localuser.user.id;
@ -199,7 +201,7 @@ class Message {
getimages() {
const build = [];
for (const thing of this.attachments) {
if (thing.content_type.startsWith('image/')) {
if (thing.content_type.startsWith("image/")) {
build.push(thing);
}
}
@ -209,7 +211,7 @@ class Message {
return await fetch(this.info.api + "/channels/" + this.channel.snowflake + "/messages/" + this.id, {
method: "PATCH",
headers: this.headers,
body: JSON.stringify({ content: content })
body: JSON.stringify({ content })
});
}
delete() {
@ -266,7 +268,7 @@ class Message {
this.generateMessage();
}
}
generateMessage(premessage = undefined, ignoredblock = false) {
generateMessage(premessage, ignoredblock = false) {
if (!this.div)
return;
if (!premessage) {
@ -277,21 +279,21 @@ class Message {
div.classList.add("replying");
}
div.innerHTML = "";
const build = document.createElement('div');
const build = document.createElement("div");
build.classList.add("flexltr", "message");
div.classList.remove("zeroheight");
if (this.author.relationshipType === 2) {
if (ignoredblock) {
if (premessage?.author !== this.author) {
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);
span.classList.add("blocked");
span.onclick = _ => {
const scroll = this.channel.infinite.scrollTop;
let next = this;
while (next?.author === this.author) {
next.generateMessage(undefined);
next.generateMessage();
next = this.channel.messages.get(this.channel.idToNext.get(next.id));
}
if (this.channel.infinite.scroll && scroll) {
@ -375,7 +377,7 @@ class Message {
}
div.appendChild(build);
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");
let pfpparent, current;
if (premessage != null) {
@ -545,7 +547,7 @@ class Message {
if (thing.emoji.name === data.name) {
thing.count--;
if (thing.count === 0) {
this.reactions.splice(+i, 1);
this.reactions.splice(Number(i), 1);
this.updateReactions();
return;
}
@ -565,16 +567,16 @@ class Message {
for (const i in this.reactions) {
const reaction = this.reactions[i];
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();
break;
}
}
}
buildhtml(premessage = undefined) {
buildhtml(premessage) {
if (this.div) {
console.error(`HTML for ${this.snowflake} already exists, aborting`);
return;
return this.div;
}
try {
const div = document.createElement("div");
@ -585,15 +587,16 @@ class Message {
catch (e) {
console.error(e);
}
return this.div;
}
}
let now = new Date().toLocaleDateString();
const now = new Date().toLocaleDateString();
const yesterday = new Date(now);
yesterday.setDate(new Date().getDate() - 1);
let yesterdayStr = yesterday.toLocaleDateString();
const yesterdayStr = yesterday.toLocaleDateString();
function formatTime(date) {
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) {
return `Today at ${formatTime(date)}`;
}

View file

@ -3,12 +3,12 @@ class Permissions {
deny;
hasDeny;
constructor(allow, deny = "") {
this.hasDeny = !!deny;
this.hasDeny = Boolean(deny);
try {
this.allow = BigInt(allow);
this.deny = BigInt(deny);
}
catch (e) {
catch {
this.allow = 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.`);

View file

@ -17,9 +17,9 @@ async function registertry(e) {
await fetch(apiurl + "/auth/register", {
body: JSON.stringify({
date_of_birth: dateofbirth,
email: email,
username: username,
password: password,
email,
username,
password,
consent: elements[6].checked,
captcha_key: elements[7]?.value
}),
@ -67,14 +67,14 @@ async function registertry(e) {
}
}
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);
const redir = new URLSearchParams(window.location.search).get("goback");
if (redir) {
window.location.href = redir;
}
else {
window.location.href = '/channels/@me';
window.location.href = "/channels/@me";
}
}
});
@ -93,7 +93,9 @@ function error(e, message) {
}
else {
element.classList.remove("suberror");
setTimeout(_ => { element.classList.add("suberror"); }, 100);
setTimeout(_ => {
element.classList.add("suberror");
}, 100);
}
element.textContent = message;
}

View file

@ -38,7 +38,6 @@ class Role {
if (this.color === 0) {
return null;
}
;
return `#${this.color.toString(16)}`;
}
}
@ -55,7 +54,6 @@ class PermissionToggle {
this.owner = owner;
}
watchForChange() { }
;
generateHTML() {
const div = document.createElement("div");
div.classList.add("setting");
@ -80,7 +78,6 @@ class PermissionToggle {
if (state === 1) {
on.checked = true;
}
;
on.onclick = _ => {
this.permissions.setPermission(this.rolejson.name, 1);
this.owner.changed();
@ -92,7 +89,6 @@ class PermissionToggle {
if (state === 0) {
no.checked = true;
}
;
no.onclick = _ => {
this.permissions.setPermission(this.rolejson.name, 0);
this.owner.changed();
@ -105,7 +101,6 @@ class PermissionToggle {
if (state === -1) {
off.checked = true;
}
;
off.onclick = _ => {
this.permissions.setPermission(this.rolejson.name, -1);
this.owner.changed();

View file

@ -4,7 +4,7 @@ function deleteoldcache() {
}
async function putInCache(request, response) {
console.log(request, response);
const cache = await caches.open('cache');
const cache = await caches.open("cache");
console.log("Grabbed");
try {
console.log(await cache.put(request, response));
@ -13,7 +13,6 @@ async function putInCache(request, response) {
console.error(error);
}
}
;
console.log("test");
let lastcache;
self.addEventListener("activate", async (event) => {
@ -37,7 +36,9 @@ async function checkCache() {
putInCache("/getupdates", data.clone());
}
checkedrecently = true;
setTimeout(_ => { checkedrecently = false; }, 1000 * 60 * 30);
setTimeout(_ => {
checkedrecently = false;
}, 1000 * 60 * 30);
});
}
var checkedrecently = false;
@ -83,7 +84,7 @@ async function getfile(event) {
console.error(e);
}
}
self.addEventListener('fetch', (event) => {
self.addEventListener("fetch", (event) => {
try {
event.respondWith(getfile(event));
}

View file

@ -9,7 +9,7 @@ class Buttons {
this.buttons = [];
this.name = name;
}
add(name, thing = undefined) {
add(name, thing) {
if (!thing) {
thing = new Options(name, this);
}
@ -380,7 +380,6 @@ class FileInput {
if (this.onchange) {
this.onchange(null);
}
;
this.value = null;
this.owner.changed();
};
@ -424,7 +423,6 @@ class HtmlArea {
}
}
watchForChange() { }
;
}
class Options {
name;
@ -451,7 +449,6 @@ class Options {
}
}
watchForChange() { }
;
addOptions(name, { ltr = false } = {}) {
const options = new Options(name, this, { ltr });
this.options.push(options);
@ -467,7 +464,7 @@ class Options {
this.generateContainter();
}
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;
}
@ -479,7 +476,7 @@ class Options {
this.generateContainter();
}
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;
}
@ -758,7 +755,6 @@ class Form {
watchForChange(func) {
this.onSubmit = func;
}
;
changed() {
if (this.traditionalSubmit) {
this.owner.changed();
@ -819,7 +815,6 @@ class Form {
if (!(errors instanceof Object)) {
return;
}
;
for (const error of Object.keys(errors)) {
const elm = this.names.get(error);
if (elm) {
@ -858,7 +853,9 @@ class Form {
}
else {
element.classList.remove("suberror");
setTimeout(_ => { element.classList.add("suberror"); }, 100);
setTimeout(_ => {
element.classList.add("suberror");
}, 100);
}
element.textContent = message;
}
@ -887,7 +884,9 @@ class Settings extends Buttons {
exit.textContent = "✖";
exit.classList.add("exitsettings");
background.append(exit);
exit.onclick = _ => { this.hide(); };
exit.onclick = _ => {
this.hide();
};
document.body.append(background);
this.html = background;
}

View file

@ -72,7 +72,7 @@ class User {
});
this.contextmenu.addbutton("Message user", function () {
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
});
});
@ -97,7 +97,7 @@ class User {
});
this.contextmenu.addbutton("Kick member", function (member) {
member.kick();
}, null, function (member) {
}, null, member => {
if (!member)
return false;
const us = member.guild.member;
@ -111,7 +111,7 @@ class User {
});
this.contextmenu.addbutton("Ban member", function (member) {
member.ban();
}, null, function (member) {
}, null, member => {
if (!member)
return false;
const us = member.guild.member;
@ -192,7 +192,7 @@ class User {
}
}
buildpfp() {
const pfp = document.createElement('img');
const pfp = document.createElement("img");
pfp.loading = "lazy";
pfp.src = this.getpfpsrc();
pfp.classList.add("pfp");
@ -419,7 +419,7 @@ class User {
}
return div;
}
profileclick(obj, guild = undefined) {
profileclick(obj, guild) {
obj.onclick = e => {
this.buildprofile(e.clientX, e.clientY, guild);
e.stopPropagation();