Created
September 20, 2014 13:40
-
-
Save H7-25/9708527a039bbf7a7dff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var network = kiwi.components.Network(); | |
function randString(n) { | |
if(!n) | |
{ | |
n = 5; | |
} | |
var text = ''; | |
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
for(var i=0; i < n; i++) | |
{ | |
text += possible.charAt(Math.floor(Math.random() * possible.length)); | |
} | |
return text; | |
} | |
// Cookies | |
function createCookie(name, value, days) { | |
if (days) { | |
var date = new Date(); | |
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | |
var expires = "; expires=" + date.toGMTString(); | |
} | |
else var expires = ""; | |
document.cookie = name + "=" + value + expires + "; path=/"; | |
} | |
function readCookie(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 eraseCookie(name) { | |
createCookie(name, "", -1); | |
} | |
var cookie = readCookie('cookie_name'); | |
//console.log(cookie); | |
if (cookie == null) { | |
var value = randString(9); | |
createCookie('cookie_name', value, 30); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment