Mercurial > hg > index.fcgi > www > www-1
comparison cs/index.html @ 78:f833a888c548
add cookie-based PIN system, and update laterlinks to use it
author | paulo |
---|---|
date | Thu, 02 Jun 2016 00:27:50 -0700 |
parents | |
children | 01cf0e93c914 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:15f6a50d6a69 |
---|---|
1 <html> | |
2 <head> | |
3 <link rel="stylesheet" type="text/css" href="index.css"> | |
4 <script type="text/javascript" src="cookies.js"></script> | |
5 </head> | |
6 | |
7 <body> | |
8 <h1>Cookies set</h1> | |
9 <div id="set_cookies"></div> | |
10 <div> | |
11 <input id="set_k"> | |
12 <input type="password" id="set_v"> | |
13 <input type="button" value="Set" onclick="set()"> | |
14 </div> | |
15 </body> | |
16 <script type="text/javascript"> | |
17 var setCookiesDiv = document.getElementById("set_cookies"); | |
18 var setK = document.getElementById("set_k"); | |
19 var setV = document.getElementById("set_v"); | |
20 | |
21 function addSetCookie(k, v) { | |
22 var d = document.createElement("div"); | |
23 | |
24 var kInput = document.createElement("input"); | |
25 kInput.disabled = true; | |
26 kInput.value = k; | |
27 | |
28 var vInput = document.createElement("input"); | |
29 vInput.type = "password"; | |
30 vInput.disabled = true; | |
31 vInput.value = v; | |
32 | |
33 var unset = document.createElement("input"); | |
34 unset.type = "button"; | |
35 unset.value = "Unset"; | |
36 unset.onclick = function() { | |
37 docCookies.removeItem(k); | |
38 setCookiesDiv.removeChild(d); | |
39 }; | |
40 | |
41 d.appendChild(kInput); | |
42 d.appendChild(vInput); | |
43 d.appendChild(unset); | |
44 | |
45 setCookiesDiv.appendChild(d); | |
46 } | |
47 | |
48 function clear() { | |
49 while (setCookiesDiv.firstChild) { | |
50 setCookiesDiv.removeChild(setCookiesDiv.firstChild); | |
51 } | |
52 } | |
53 | |
54 function load() { | |
55 clear(); | |
56 for (var i=0; i<docCookies.keys().length; i++) { | |
57 var k = docCookies.keys()[i]; | |
58 if (docCookies.hasItem(k)) { | |
59 var v = docCookies.getItem(k); | |
60 addSetCookie(k, v); | |
61 } | |
62 } | |
63 } | |
64 | |
65 function set() { | |
66 docCookies.setItem(setK.value, setV.value, 600); | |
67 setK.value = ""; | |
68 setV.value = ""; | |
69 load(); | |
70 } | |
71 | |
72 load(); | |
73 </script> | |
74 </html> |