From fed7b3af793ef542e1b6959b06c45f7703fabd40 Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 20 Sep 2023 14:30:22 +0200 Subject: [PATCH] Resolve #4 --- Website/interaction.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Website/interaction.js b/Website/interaction.js index 752ebeb..ee1626e 100644 --- a/Website/interaction.js +++ b/Website/interaction.js @@ -66,7 +66,8 @@ function Setup(){ }); GetAvailableControllers().then((json) => { - json.forEach(connector => { + newMangaConnector.replaceChildren(); + json.forEach(connector => { var option = document.createElement('option'); option.value = connector; option.innerText = connector; @@ -140,6 +141,7 @@ function CreateManga(manga, connector){ var connectorName = document.createElement('connector-name'); connectorName.innerText = connector; connectorName.className = "pill"; + connectorName.style.backgroundColor = stringToColour(connector); info.appendChild(connectorName); var mangaName = document.createElement('publication-name'); mangaName.innerText = manga.sortName; @@ -486,4 +488,17 @@ function UpdateJobProgress(jobId){ function GetValidSelector(str){ var clean = [...str.matchAll(/[a-zA-Z0-9]*-*_*/g)]; return clean.join(''); +} + +const stringToColour = (str) => { + let hash = 0; + str.split('').forEach(char => { + hash = char.charCodeAt(0) + ((hash << 5) - hash) + }) + let colour = '#' + for (let i = 0; i < 3; i++) { + const value = (hash >> (i * 8)) & 0xff + colour += value.toString(16).padStart(2, '0') + } + return colour } \ No newline at end of file