take first line, downcase names, insensitive matching

This commit is contained in:
mehbark 2024-07-11 02:32:55 -04:00
parent 8a5ff92104
commit 08f5f5ad12

View file

@ -43,7 +43,8 @@ async function get_name_color(name: string): Promise<string | undefined> {
for (const p of dom.querySelectorAll("p")) {
const text = p.textContent;
if (text.startsWith("name-color: ")) {
const color = text.split("name-color: ")[1]
const line = text.split("\n", 1)[0];
const color = line.split("name-color: ")[1]
.slice(0, MAX_COLOR_LEN)
.replaceAll(/[;{}"']/g, "");
if (is_valid_color(color)) {
@ -77,15 +78,15 @@ function cssify({ requester }: { requester?: string }): string {
let vars = `:root {\n`;
if (requester && colors[requester]) {
vars += `--name-color: var(--name-color-${requester});\n`;
vars += `--name-color: var(--name-color-${requester.toLowerCase()});\n`;
}
let classes = "";
for (const name of Object.keys(colors).sort()) {
const { color } = colors[name];
if (!color) continue;
vars += `--name-color-${name}: ${color};\n`;
vars += `--name-color-${name.toLowerCase()}: ${color};\n`;
classes +=
`a[href$='/${name}']{color: var(--name-color-${name}) !important;}\n`;
`a[href$='/${name}' i]{color: var(--name-color-${name.toLowerCase()}) !important;}\n`;
}
vars += "}\n\n";
return preamble + vars + classes;