Skip to content

Commit

Permalink
🎉 add text2color
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Jan 22, 2022
1 parent 83f4367 commit e91432f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions public/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e91432f

Please sign in to comment.