-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
82 lines (77 loc) · 2.52 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Class with basic function and attributs but not in relation with the app
*
* @export
* @class Utils
* @typedef {Utils}
*/
export class Utils{
/**
* This is a sleep method, it's to wait a while, used to do infinite loop without crash
*
* @async
* @param {number} ms the time in milliseconds we want to sleep/stay
* @returns {} Nothing is returned
*/
static sleep = async (ms) => new Promise(r => setTimeout(r, ms));
/**
* This is a method to play a sound
*
* @async
* @param {string} sound the path to sound to play
* @returns {} Nothing is returned
*/
static playSound = async (sound) => new Audio(sound).play();
/**
* This is a method to get a stat grid node with a special inner and the type of node
*
* @param {string} inner the text to put in the node
* @param {number} type the type of node: 0 to a label node; 3 for a date content node ;
* 4 to a banning content node; no type for the other type
* @returns {node} the node with good class and inner
*/
static nodeStatGrid = (inner='', type=-1) => {
let node = document.createElement('div');
node.className = 'colContent';
switch(type){
// If the node is label of grid
case 0:
node.className += ' labelScoreboard';
node.innerHTML = inner;
break;
// If the node is the last edit
case 3:
let date = new Date(inner);
date = date.toLocaleString('fr-FR', { month: 'numeric', day: 'numeric'})
let time = inner.substring(11,19);
node.innerHTML = node.innerHTML = `Le ${date} à ${time}`;
break;
// If the node is the banned label
case 4:
if(inner === false){
node.innerHTML = '🟩';
}else if(inner === true){
node.innerHTML = '🟥';
}
break;
default:
node.innerHTML = inner;
}
return node;
}
/**
* This is a method to get a font-wheight with the score of user
*
* @param {string} score the score of user
* @returns {number} the weight of the text
*/
static scoreToWeight = (score) => {
if(score >= 1000){
return 900;
}else if(score <= 100){
return 100;
}else{
return Math.floor(score,100) * 100;
}
}
}