From 5ed479af20aad2cca2a0bda58b51a7a12cd88827 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Wed, 17 Jun 2020 17:44:50 +0200 Subject: [PATCH] Missed this one during the lintfix --- lib/darkmode.ts | 33 ++++++--------------------------- lib/userscript.ts | 2 +- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/lib/darkmode.ts b/lib/darkmode.ts index bce278a..4d697e1 100644 --- a/lib/darkmode.ts +++ b/lib/darkmode.ts @@ -16,8 +16,6 @@ export enum ColorFmt { } function hsvToRgb({ h, s, v }: ColorHSV): ColorRGB { - let r, g, b; - const i = Math.floor(h * 6); const f = h * 6 - i; const p = v * (1 - s); @@ -26,39 +24,20 @@ function hsvToRgb({ h, s, v }: ColorHSV): ColorRGB { switch (i % 6) { case 0: - r = v; - g = t; - b = p; - break; + return { r: v, g: t, b: p }; case 1: - r = q; - g = v; - b = p; - break; + return { r: q, g: v, b: p }; case 2: - r = p; - g = v; - b = t; - break; + return { r: p, g: v, b: t }; case 3: - r = p; - g = q; - b = v; - break; + return { r: p, g: q, b: v }; case 4: - r = t; - g = p; - b = v; - break; + return { r: t, g: p, b: v }; case 5: - r = v; - g = p; - b = q; - break; + return { r: v, g: p, b: q }; default: throw new Error("unreacheable"); } - return { r, g, b }; } function rgbToHsv({ r, g, b }: ColorRGB): ColorHSV { diff --git a/lib/userscript.ts b/lib/userscript.ts index 90d0064..3d2e7af 100644 --- a/lib/userscript.ts +++ b/lib/userscript.ts @@ -15,7 +15,7 @@ export default function userscript(root: HTMLElement, docname: string): void { // Shitty way to detect if it's hex or not // Basically, none of the css colors long 6 letters only use hex letters // THANK FUCKING GOD - if (bgcolor.length === 6 && Number.isNaN(parseInt(bgcolor, 16))) { + if (bgcolor.length === 6 && !Number.isNaN(parseInt(bgcolor, 16))) { bgcolor = `#${bgcolor}`; } td.setAttribute("bgcolor", darken(bgcolor, ColorFmt.HEX).slice(1));