Load custom colors from config

This commit is contained in:
Dominik Reh
2022-10-12 13:52:20 +02:00
parent 00a12b4e41
commit 6fa1d1d041
2 changed files with 35 additions and 6 deletions

View File

@@ -176,20 +176,29 @@ function insertTextAtCursor(text, tagword) {
previousTags = tags;
}
const colors_dark = ["lightblue", "indianred", "unused", "violet", "lightgreen", "orange"];
const colors_light = ["dodgerblue", "firebrick", "unused", "darkorchid", "darkgreen", "darkorange" ]
function addResultsToList(results, tagword) {
let resultsList = gradioApp().querySelector('#autocompleteResultsList');
resultsList.innerHTML = "";
let colors = gradioApp().querySelector('.dark') ? colors_dark : colors_light;
// Find right colors from config
let tagFileName = acConfig.tagFile.split(".")[0];
let tagColors = acConfig.colors;
//let colorIndex = Object.keys(tagColors).findIndex(key => key === tagFileName);
//let colorValues = Object.values(tagColors)[colorIndex];
let mode = gradioApp().querySelector('.dark') ? 0 : 1;
for (let i = 0; i < results.length; i++) {
let result = results[i];
let li = document.createElement("li");
li.innerHTML = result[0];
li.style = `color: ${colors[result[1]]};`;
// Set the color of the tag
let tagType = result[1];
li.style = `color: ${tagColors[tagFileName][tagType][mode]};`;
// Add listener
li.addEventListener("click", function() { insertTextAtCursor(result[0], tagword); });
// Add element to list
resultsList.appendChild(li);
}
}

View File

@@ -1,5 +1,25 @@
{
"tagFile": "danbooru.csv",
"maxResults": 5,
"replaceUnderscores": true
}
"replaceUnderscores": true,
"colors": {
"danbooru": {
"0": ["lightblue", "dodgerblue"],
"1": ["indianred", "firebrick"],
"3": ["violet", "darkorchid"],
"4": ["lightgreen", "darkgreen"],
"5": ["orange", "darkorange"]
},
"e621": {
"-1": ["red", "maroon"],
"0": ["lightblue", "dodgerblue"],
"1": ["gold", "goldenrod"],
"3": ["violet", "darkorchid"],
"4": ["lightgreen", "darkgreen"],
"5": ["tomato", "darksalmon"],
"6": ["red", "maroon"],
"7": ["whitesmoke", "black"],
"8": ["seagreen", "darkseagreen"]
}
}
}