compiled js changes
This commit is contained in:
parent
1183dc40ce
commit
f8b80b65fe
2 changed files with 90 additions and 100 deletions
|
@ -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,6 +45,8 @@ class Contextmenu {
|
||||||
}
|
}
|
||||||
div.appendChild(intext);
|
div.appendChild(intext);
|
||||||
}
|
}
|
||||||
|
if (visibleButtons == 0)
|
||||||
|
return;
|
||||||
if (Contextmenu.currentmenu != "") {
|
if (Contextmenu.currentmenu != "") {
|
||||||
Contextmenu.currentmenu.remove();
|
Contextmenu.currentmenu.remove();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
@ -305,35 +303,15 @@ class Localuser {
|
||||||
break;
|
break;
|
||||||
case "MESSAGE_DELETE":
|
case "MESSAGE_DELETE":
|
||||||
console.log(temp.d);
|
console.log(temp.d);
|
||||||
temp.d.guild_id ??= "@me";
|
SnowFlake.getSnowFlakeFromID(temp.d.id, Message).getObject().deleteEvent();
|
||||||
const guild = this.guildids.get(temp.d.guild_id);
|
|
||||||
if (guild) {
|
|
||||||
const channel = guild.channelids[temp.d.guild_id];
|
|
||||||
if (channel) {
|
|
||||||
const message = channel.messages.get(temp.d.id);
|
|
||||||
if (message) {
|
|
||||||
message.deleteEvent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "READY":
|
case "READY":
|
||||||
this.gottenReady(temp);
|
this.gottenReady(temp);
|
||||||
break;
|
break;
|
||||||
case "MESSAGE_UPDATE": {
|
case "MESSAGE_UPDATE":
|
||||||
temp.d.guild_id ??= "@me";
|
const message = SnowFlake.getSnowFlakeFromID(temp.d.id, Message).getObject();
|
||||||
const guild = this.guildids.get(temp.d.guild_id);
|
message.giveData(temp.d);
|
||||||
if (guild) {
|
|
||||||
const channel = guild.channelids[temp.d.guild_id];
|
|
||||||
if (channel) {
|
|
||||||
const message = channel.messages.get(temp.d.id);
|
|
||||||
if (message) {
|
|
||||||
message.giveData(temp.d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case "TYPING_START":
|
case "TYPING_START":
|
||||||
if (this.initialized) {
|
if (this.initialized) {
|
||||||
this.typingStart(temp);
|
this.typingStart(temp);
|
||||||
|
@ -438,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];
|
||||||
}
|
}
|
||||||
|
@ -670,7 +648,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) {
|
||||||
|
@ -738,13 +716,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", {
|
||||||
|
@ -758,7 +736,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", {
|
||||||
|
@ -792,7 +770,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) {
|
||||||
|
@ -826,15 +804,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 = "";
|
||||||
|
@ -858,7 +836,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);
|
||||||
|
@ -867,7 +844,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);
|
||||||
|
@ -892,7 +869,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(_ => {
|
||||||
|
@ -913,11 +890,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();
|
||||||
});
|
});
|
||||||
|
@ -945,7 +922,7 @@ class Localuser {
|
||||||
fixsvgtheme();
|
fixsvgtheme();
|
||||||
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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1009,7 +986,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"
|
||||||
|
@ -1017,7 +996,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"
|
||||||
|
@ -1029,7 +1010,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"
|
||||||
|
@ -1041,7 +1024,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"
|
||||||
|
@ -1102,23 +1087,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";
|
||||||
|
@ -1311,7 +1300,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();
|
||||||
});
|
});
|
||||||
|
@ -1347,7 +1336,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) => {
|
||||||
|
@ -1362,13 +1353,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, [[], [], []]);
|
||||||
|
@ -1387,7 +1376,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)) {
|
||||||
|
@ -1459,24 +1447,23 @@ let fixsvgtheme;
|
||||||
if (color === last) {
|
if (color === last) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
last = color;
|
last = color;
|
||||||
const thing = color.replace("rgb(", "").replace(")", "").split(",");
|
const thing = color.replace("rgb(", "").replace(")", "").split(",");
|
||||||
//sconsole.log(thing);
|
//sconsole.log(thing);
|
||||||
const r = +thing[0] / 255;
|
const r = Number(thing[0]) / 255;
|
||||||
const g = +thing[1] / 255;
|
const g = Number(thing[1]) / 255;
|
||||||
const b = +thing[2] / 255;
|
const b = Number(thing[2]) / 255;
|
||||||
const max = Math.max(r, g, b);
|
const max = Math.max(r, g, b);
|
||||||
const min = Math.min(r, g, b);
|
const min = Math.min(r, g, b);
|
||||||
const l = (max + min) / 2;
|
const l = (max + min) / 2;
|
||||||
let s;
|
let s;
|
||||||
let h;
|
let h;
|
||||||
if (max !== min) {
|
if (max !== min) {
|
||||||
if (l <= .5) {
|
if (l <= 0.5) {
|
||||||
s = (max - min) / (max + min);
|
s = (max - min) / (max + min);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
s = (max - min) / (2.0 - max - min);
|
s = (max - min) / (2 - max - min);
|
||||||
}
|
}
|
||||||
if (r === max) {
|
if (r === max) {
|
||||||
h = (g - b) / (max - min);
|
h = (g - b) / (max - min);
|
||||||
|
@ -1493,11 +1480,11 @@ let fixsvgtheme;
|
||||||
h = 0;
|
h = 0;
|
||||||
}
|
}
|
||||||
const rot = Math.floor(h * 60) + "deg";
|
const rot = Math.floor(h * 60) + "deg";
|
||||||
const invert = .5 - (s / 2) + "";
|
const invert = 0.5 - (s / 2) + "";
|
||||||
const brightness = Math.floor((l * 200)) + "%";
|
const brightness = Math.floor((l * 200)) + "%";
|
||||||
document.documentElement.style.setProperty('--rot', rot);
|
document.documentElement.style.setProperty("--rot", rot);
|
||||||
document.documentElement.style.setProperty('--invert', invert);
|
document.documentElement.style.setProperty("--invert", invert);
|
||||||
document.documentElement.style.setProperty('--brightness', brightness);
|
document.documentElement.style.setProperty("--brightness", brightness);
|
||||||
}
|
}
|
||||||
fixsvgtheme = fixsvgtheme_;
|
fixsvgtheme = fixsvgtheme_;
|
||||||
setTimeout(fixsvgtheme_, 100);
|
setTimeout(fixsvgtheme_, 100);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue