User-friendly vchess presentation on index + some code cleaning
[vchess.git] / public / javascripts / utils / misc.js
diff --git a/public/javascripts/utils/misc.js b/public/javascripts/utils/misc.js
new file mode 100644 (file)
index 0000000..89a545c
--- /dev/null
@@ -0,0 +1,30 @@
+// Source: https://www.quirksmode.org/js/cookies.html
+
+function setCookie(name,value)
+{
+       var date = new Date();
+       date.setTime(date.getTime()+(183*24*60*60*1000)); //6 months
+       var expires = "; expires="+date.toGMTString();
+       document.cookie = name+"="+value+expires+"; path=/";
+}
+
+function getCookie(name) {
+       var nameEQ = name + "=";
+       var ca = document.cookie.split(';');
+       for (var i=0;i < ca.length;i++)
+       {
+               var c = ca[i];
+               while (c.charAt(0)==' ')
+                       c = c.substring(1,c.length);
+               if (c.indexOf(nameEQ) == 0)
+                       return c.substring(nameEQ.length,c.length);
+       }
+       return null;
+}
+
+function getRandString()
+{
+       // Random enough (for socket and game IDs)
+       return (Date.now().toString(36) + Math.random().toString(36).substr(2, 7))
+               .toUpperCase();
+}