colorize user names under messages

This commit is contained in:
or-else
2021-08-18 16:00:47 -07:00
parent fb3de109e0
commit 529486feb3
3 changed files with 15 additions and 9 deletions
+6 -1
View File
@@ -39,7 +39,7 @@ export function bytesToHumanSize(bytes) {
// Get 32 bit integer hash value for a string. Ideally it should produce the same value
// as Java's String#hash().
export function stringHash(value) {
function stringToColorHash(value) {
let hash = 0;
value = '' + value;
for (let i = 0; i < value.length; i++) {
@@ -48,3 +48,8 @@ export function stringHash(value) {
}
return hash;
}
// Converts user or topic ID to a CSS color class. Ideally it should produce the same color value as Java version.
export function idToColorClass(string, light) {
return (light ? 'light-color' : 'dark-color') + (Math.abs(stringToColorHash(string)) % 16);
}