view 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
line source
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>
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");
21 function addSetCookie(k, v) {
22 var d = document.createElement("div");
24 var kInput = document.createElement("input");
25 kInput.disabled = true;
26 kInput.value = k;
28 var vInput = document.createElement("input");
29 vInput.type = "password";
30 vInput.disabled = true;
31 vInput.value = v;
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 };
41 d.appendChild(kInput);
42 d.appendChild(vInput);
43 d.appendChild(unset);
45 setCookiesDiv.appendChild(d);
46 }
48 function clear() {
49 while (setCookiesDiv.firstChild) {
50 setCookiesDiv.removeChild(setCookiesDiv.firstChild);
51 }
52 }
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 }
65 function set() {
66 docCookies.setItem(setK.value, setV.value, 600);
67 setK.value = "";
68 setV.value = "";
69 load();
70 }
72 load();
73 </script>
74 </html>