From e91432fc778a8006c889ed506d78d09ac1a822d9 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sat, 22 Jan 2022 10:42:46 +0800 Subject: [PATCH] :tada: add text2color --- public/static/main.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/public/static/main.js b/public/static/main.js index 97b66fe..d32f4bc 100644 --- a/public/static/main.js +++ b/public/static/main.js @@ -2,6 +2,23 @@ let mainElement = undefined; let loading = false; let offset = 0; let token = localStorage.getItem('token'); +let colorList = [ + "#0074D9", "#7FDBFF", "#39CCCC", "#B10DC9", "#F012BE", + "#FF4136", "#FF851B", "#2ECC40", "#01FF70" +]; + +function text2color(text) { + let color = "#111111"; + if (text.length !== 0) { + let firstChar = text[0]; + let n = firstChar.charCodeAt(0); + if (!isNaN(n)) { + let idx = n % colorList.length; + color = colorList[idx]; + } + } + return color; +} function render(item, insertEnd = true) { item.content = parseLink(item.content);