Skip to content

Commit

Permalink
randomize username colors
Browse files Browse the repository at this point in the history
  • Loading branch information
mudkipdev committed Dec 2, 2024
1 parent 0d7c4cf commit 5c71f6a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/chat/Chat.astro
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@
<script>
const input = document.querySelector(`#chat input[type="text"]`) as HTMLInputElement;
const history = document.querySelector("#history") as HTMLUListElement;
const colors = [
"red",
"peach",
"yellow",
"green",
"sky",
"blue",
"mauve",
"pink"
];

const username = "mudkip";
const color = colors[Math.floor(Math.random() * colors.length)];

if (!input || !history) {
console.error("could not find chat elements");
Expand All @@ -34,7 +46,7 @@

const usernameElement = document.createElement("span");
usernameElement.textContent = "<" + username + ">";
usernameElement.style.color = "var(--ctp-macchiato-green)";
usernameElement.style.color = `var(--ctp-macchiato-${color})`;
usernameElement.style.fontSize = "inherit";
element.appendChild(usernameElement);

Expand Down

0 comments on commit 5c71f6a

Please sign in to comment.