MarseyWorld/files/assets/js/fix_collapse_lines.js

29 lines
918 B
JavaScript
Raw Normal View History

2023-07-14 17:45:28 +00:00
function deltaRgb (rgb1, rgb2) {
const [ r1, g1, b1 ] = rgb1,
[ r2, g2, b2 ] = rgb2,
drp2 = Math.pow(r1 - r2, 2),
dgp2 = Math.pow(g1 - g2, 2),
dbp2 = Math.pow(b1 - b2, 2),
t = (r1 + r2) / 2
return Math.sqrt(2 * drp2 + 4 * dgp2 + 3 * dbp2 + t * (drp2 - dbp2) / 256)
}
2023-07-22 23:55:18 +00:00
function toRGBArray(rgbStr) {
return rgbStr.match(/\d+/g).map(Number);
}
2023-07-14 17:45:28 +00:00
const background_color = toRGBArray(getComputedStyle(document.documentElement).getPropertyValue('--background'));
for (const line of document.getElementsByClassName('comment-collapse-line')) {
2023-07-23 00:29:30 +00:00
if (line.style.borderColor == 'var(--primary)')
continue
2023-07-14 17:45:28 +00:00
const line_color = toRGBArray(line.style.borderColor)
if (deltaRgb(line_color, background_color) < 100) {
const R = Math.abs(background_color[0] - 255)
const G = Math.abs(background_color[1] - 255)
const B = Math.abs(background_color[2] - 255)
line.style.borderColor = `rgb(${R}, ${G}, ${B})`
}
}