5a32ff9ee6b56f48e5bf0f5241ac14ae5f4196dc
3 // Source: https://www.quirksmode.org/js/cookies.html
4 setCookie: function(name
, value
)
7 date
.setTime(date
.getTime()+(183*24*60*60*1000)); //6 months
8 var expires
= "; expires="+date
.toGMTString();
9 document
.cookie
= name
+"="+value
+expires
+"; path=/";
12 getCookie: function(name
, defaut
) {
13 var nameEQ
= name
+ "=";
14 var ca
= document
.cookie
.split(';');
15 for (var i
=0;i
< ca
.length
;i
++)
18 while (c
.charAt(0)==' ')
19 c
= c
.substring(1,c
.length
);
20 if (c
.indexOf(nameEQ
) == 0)
21 return c
.substring(nameEQ
.length
,c
.length
);
23 return defaut
; //cookie not found
26 random: function(min
, max
)
33 return Math
.floor(Math
.random() * (max
- min
) ) + min
;
36 // Inspired by https://github.com/jashkenas/underscore/blob/master/underscore.js
37 sample: function(arr
, n
)
40 let cpArr
= arr
.map(e
=> e
);
41 for (let index
= 0; index
< n
; index
++)
43 const rand
= getRandInt(index
, n
);
44 const temp
= cpArr
[index
];
45 cpArr
[index
] = cpArr
[rand
];
48 return cpArr
.slice(0, n
);
51 shuffle: function(arr
)
53 return sample(arr
, arr
.length
);
58 return [...Array(max
).keys()];
61 // TODO: rename into "cookie" et supprimer les deux ci-dessous
62 // Random (enough) string for socket and game IDs
63 getRandString: function()
65 return (Date
.now().toString(36) + Math
.random().toString(36).substr(2, 7))
69 // Shortcut for an often used click (on a modal)
70 doClick: function(elemId
)
72 document
.getElementById(elemId
).click(); //or ".checked = true"