further reduce overhead

This commit is contained in:
MathMan05 2024-07-31 23:13:02 -05:00
parent 08d25f5082
commit ac4094394c
2 changed files with 85 additions and 71 deletions

View file

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

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