Unversion parameters.js
[vchess.git] / client / client_OLD / javascripts / utils / misc.js
CommitLineData
b019d603 1// Source: https://www.quirksmode.org/js/cookies.html
a897b421 2function setCookie(name, value)
b019d603
BA
3{
4 var date = new Date();
5 date.setTime(date.getTime()+(183*24*60*60*1000)); //6 months
6 var expires = "; expires="+date.toGMTString();
7 document.cookie = name+"="+value+expires+"; path=/";
8}
9
a897b421 10function getCookie(name, defaut) {
b019d603
BA
11 var nameEQ = name + "=";
12 var ca = document.cookie.split(';');
13 for (var i=0;i < ca.length;i++)
14 {
15 var c = ca[i];
16 while (c.charAt(0)==' ')
17 c = c.substring(1,c.length);
18 if (c.indexOf(nameEQ) == 0)
19 return c.substring(nameEQ.length,c.length);
20 }
a897b421 21 return defaut; //cookie not found
b019d603
BA
22}
23
92342261 24// Random (enough) string for socket and game IDs
b019d603
BA
25function getRandString()
26{
b019d603
BA
27 return (Date.now().toString(36) + Math.random().toString(36).substr(2, 7))
28 .toUpperCase();
29}
e6dcb115
BA
30
31// Used both on index and variant page, to switch language
32function setLanguage(e)
33{
e6dcb115
BA
34 setCookie("lang", e.target.value);
35 location.reload(); //to include the right .pug file
36}
8a477a7e
BA
37
38// Shortcut for an often used click (on a modal)
39function doClick(elemId)
40{
41 document.getElementById(elemId).click(); //or ".checked = true"
42}
d44df0b0 43
a3ab5fdb
BA
44function translate(msg)
45{
d44df0b0
BA
46 return translations[msg];
47}