| 1 |
/** |
| 2 |
* Add/read cookie |
| 3 |
* |
| 4 |
* Based on code from |
| 5 |
* http://www.quirksmode.org/js/cookies.html |
| 6 |
*/ |
| 7 |
function sdCreateCookie(name) { |
| 8 |
var unix = Math.round(+new Date()/1000); // Current time in seconds |
| 9 |
var expire = new Date(); // Current time in miliseconds |
| 10 |
expire.setTime(expire.getTime()+(spam_destroyer.lifetime*1000)); // Cookie lifetime in seconds * 1000 miliseconds |
| 11 |
var expires = "; expires="+expire.toUTCString(); |
| 12 |
document.cookie = name+"="+unix+expires+"; path=/"; |
| 13 |
} |
| 14 |
|
| 15 |
function sdReadCookie(name) { |
| 16 |
var nameEQ = name + "="; |
| 17 |
var ca = document.cookie.split(';'); |
| 18 |
for(var i=0;i < ca.length;i++) { |
| 19 |
var c = ca[i]; |
| 20 |
while (c.charAt(0)==' ') c = c.substring(1,c.length); |
| 21 |
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); |
| 22 |
} |
| 23 |
return null; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Set cookie if not exists |
| 28 |
*/ |
| 29 |
function sdCheckCookies() { |
| 30 |
var x = sdReadCookie(spam_destroyer.key) |
| 31 |
if (x) { |
| 32 |
// If cookie is set, do nothing |
| 33 |
} else { |
| 34 |
sdCreateCookie(spam_destroyer.key); |
| 35 |
} |
| 36 |
} |
| 37 |
sdCheckCookies(); |
| 38 |
|
| 39 |
// Replace hidden input field with key |
| 40 |
try { |
| 41 |
document.getElementById('killer_value').value = spam_destroyer.key; |
| 42 |
} catch (e) {} |