name-color serverside gens css :D
This commit is contained in:
parent
7262720f96
commit
ec12ce588f
1 changed files with 22 additions and 2 deletions
|
@ -31,7 +31,9 @@ async function get_name_color(name: string): Promise<string | undefined> {
|
||||||
for (const p of dom.querySelectorAll("p")) {
|
for (const p of dom.querySelectorAll("p")) {
|
||||||
const text = p.textContent;
|
const text = p.textContent;
|
||||||
if (text.startsWith("name-color: ")) {
|
if (text.startsWith("name-color: ")) {
|
||||||
return text.split("name-color: ")[1].slice(0, MAX_COLOR_LEN);
|
return text.split("name-color: ")[1]
|
||||||
|
.slice(0, MAX_COLOR_LEN)
|
||||||
|
.replaceAll(";", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +50,21 @@ async function update_name_color(name: string) {
|
||||||
colors[name] = { color, last_checked: now };
|
colors[name] = { color, last_checked: now };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cssify({ requester }: { requester?: string }): string {
|
||||||
|
let vars = `:root {\n`;
|
||||||
|
if (requester && colors[requester]) {
|
||||||
|
vars += `--name-color: var(--name-color-${requester});\n`;
|
||||||
|
}
|
||||||
|
let classes = ".name { color: var(--name-color); }\n";
|
||||||
|
for (const [name, { color }] of Object.entries(colors)) {
|
||||||
|
if (!color) continue;
|
||||||
|
vars += `--name-color-${name}: ${color};\n`;
|
||||||
|
classes += `.name-${name}{--name-color:var(--name-color-${name})}`;
|
||||||
|
}
|
||||||
|
vars += "}\n";
|
||||||
|
return vars + classes;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: ONE BIG REQUEST/RESPONSE DUHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHh
|
// TODO: ONE BIG REQUEST/RESPONSE DUHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHh
|
||||||
Deno.serve({ port: 61266 }, async (req) => {
|
Deno.serve({ port: 61266 }, async (req) => {
|
||||||
const url = new URL(req.url);
|
const url = new URL(req.url);
|
||||||
|
@ -55,5 +72,8 @@ Deno.serve({ port: 61266 }, async (req) => {
|
||||||
!name.match(/\/\?/)
|
!name.match(/\/\?/)
|
||||||
);
|
);
|
||||||
await Promise.all(names.map(update_name_color));
|
await Promise.all(names.map(update_name_color));
|
||||||
return Response.json(colors);
|
const css = cssify({
|
||||||
|
requester: url.searchParams.get("requester") ?? undefined,
|
||||||
|
});
|
||||||
|
return new Response(css, { headers: { "content-type": "text/css" } });
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue