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

@ -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);
}