refactor: Separate backend and frontend, avoid template-filling on the fly. Resolve #158.
This commit is contained in:
@ -2,6 +2,42 @@ export function isOverflown(element) {
|
||||
return element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth;
|
||||
}
|
||||
|
||||
export function hash(string) {
|
||||
if (typeof string != "string") return 0;
|
||||
let hash = 0;
|
||||
if (string.length === 0) {
|
||||
return hash;
|
||||
}
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
let char = string.charCodeAt(i);
|
||||
hash = ((hash<<5)-hash)+char;
|
||||
hash = hash & hash; // Convert to 32bit integer
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
export function getColor(string) {
|
||||
let num = hash(string) % 8;
|
||||
switch(num) {
|
||||
case 0:
|
||||
return "primary";
|
||||
case 1:
|
||||
return "secondary";
|
||||
case 2:
|
||||
return "success";
|
||||
case 3:
|
||||
return "danger";
|
||||
case 4:
|
||||
return "warning";
|
||||
case 5:
|
||||
return "info";
|
||||
case 6:
|
||||
return "light";
|
||||
case 7:
|
||||
return "dark";
|
||||
}
|
||||
}
|
||||
|
||||
export function setProgressBar(bar, progress, text = '') {
|
||||
const progPos = (-1 * (1 - progress) * bar.scrollWidth).toString();
|
||||
const progStr = (progress * 100).toString();
|
||||
@ -32,4 +68,4 @@ export function coverArtString(title) {
|
||||
}
|
||||
|
||||
return 'Cover art for ' + nameOfSong;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user