improve performance even more of that function

This commit is contained in:
MathMan05 2024-07-31 23:24:37 -05:00
parent ac4094394c
commit 983b7e3fa2
2 changed files with 77 additions and 75 deletions

View file

@ -910,51 +910,52 @@ Channel.setupcontextmenu();
export { Channel }; export { Channel };
{ {
let last; let last;
const dud = document.createElement("p");
dud.classList.add("svgtheme");
document.body.append(dud);
const css = window.getComputedStyle(dud);
function fixsvgtheme() { function fixsvgtheme() {
const things = document.getElementsByClassName("svgtheme");
//console.log(things); //console.log(things);
if (things.length) { const thing = css.color.replace("rgb(", "").replace(")", "").split(",");
const thing = window.getComputedStyle(things[0]).color.replace("rgb(", "").replace(")", "").split(","); //sconsole.log(thing);
//sconsole.log(thing); const r = +thing[0] / 255;
const r = +thing[0] / 255; const g = +thing[1] / 255;
const g = +thing[1] / 255; const b = +thing[2] / 255;
const b = +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 <= .5) { s = (max - min) / (max + min);
s = (max - min) / (max + min);
}
else {
s = (max - min) / (2.0 - max - min);
}
if (r === max) {
h = (g - b) / (max - min);
}
else if (g === max) {
h = 2 + (b - r) / (max - min);
}
else if (b === max) {
h = 4 + (r - g) / (max - min);
}
} }
else { else {
s = 0; s = (max - min) / (2.0 - max - min);
h = 0;
} }
const rot = Math.floor(h * 60) + "deg"; if (r === max) {
const invert = .5 - (s / 2) + ""; h = (g - b) / (max - min);
const brightness = Math.floor((l * 200)) + "%";
const current = rot + invert + brightness;
if (current !== last) {
last = current;
document.documentElement.style.setProperty('--rot', rot);
document.documentElement.style.setProperty('--invert', invert);
document.documentElement.style.setProperty('--brightness', brightness);
} }
else if (g === max) {
h = 2 + (b - r) / (max - min);
}
else if (b === max) {
h = 4 + (r - g) / (max - min);
}
}
else {
s = 0;
h = 0;
}
const rot = Math.floor(h * 60) + "deg";
const invert = .5 - (s / 2) + "";
const brightness = Math.floor((l * 200)) + "%";
const current = rot + invert + brightness;
if (current !== last) {
last = current;
document.documentElement.style.setProperty('--rot', rot);
document.documentElement.style.setProperty('--invert', invert);
document.documentElement.style.setProperty('--brightness', brightness);
} }
} }
setInterval(fixsvgtheme, 100); setInterval(fixsvgtheme, 100);

View file

@ -901,48 +901,49 @@ Channel.setupcontextmenu();
export {Channel}; export {Channel};
{ {
let last:string; let last:string;
const dud=document.createElement("p")
dud.classList.add("svgtheme")
document.body.append(dud);
const css=window.getComputedStyle(dud);
function fixsvgtheme(){ function fixsvgtheme(){
const things=document.getElementsByClassName("svgtheme");
//console.log(things); //console.log(things);
if(things.length){ const thing=css.color.replace("rgb(","").replace(")","").split(",");
const thing=window.getComputedStyle(things[0]).color.replace("rgb(","").replace(")","").split(","); //sconsole.log(thing);
//sconsole.log(thing); const r=+thing[0]/255;
const r=+thing[0]/255; const g=+thing[1]/255;
const g=+thing[1]/255; const b=+thing[2]/255;
const b=+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:number; let s:number;
let h:number; let h:number;
if(max!==min){ if(max!==min){
if(l<=.5){ if(l<=.5){
s=(max-min)/(max+min); s=(max-min)/(max+min);
}else{
s=(max-min)/(2.0-max-min);
}
if(r===max){
h=(g-b)/(max-min);
}else if(g===max){
h=2+(b-r)/(max-min);
}else if(b===max){
h=4+(r-g)/(max-min);
}
}else{ }else{
s=0; s=(max-min)/(2.0-max-min);
h=0;
} }
const rot=Math.floor(h*60)+"deg"; if(r===max){
const invert=.5-(s/2)+""; h=(g-b)/(max-min);
const brightness=Math.floor((l*200))+"%"; }else if(g===max){
const current=rot+invert+brightness; h=2+(b-r)/(max-min);
if(current!==last){ }else if(b===max){
last=current; h=4+(r-g)/(max-min);
document.documentElement.style.setProperty('--rot', rot);
document.documentElement.style.setProperty('--invert', invert);
document.documentElement.style.setProperty('--brightness', brightness);
} }
}else{
s=0;
h=0;
}
const rot=Math.floor(h*60)+"deg";
const invert=.5-(s/2)+"";
const brightness=Math.floor((l*200))+"%";
const current=rot+invert+brightness;
if(current!==last){
last=current;
document.documentElement.style.setProperty('--rot', rot);
document.documentElement.style.setProperty('--invert', invert);
document.documentElement.style.setProperty('--brightness', brightness);
} }
} }
setInterval(fixsvgtheme,100); setInterval(fixsvgtheme,100);