diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/cs/index.html	Thu Jun 02 00:27:50 2016 -0700
     1.3 @@ -0,0 +1,74 @@
     1.4 +<html>
     1.5 +<head>
     1.6 +<link rel="stylesheet" type="text/css" href="index.css">
     1.7 +<script type="text/javascript" src="cookies.js"></script>
     1.8 +</head>
     1.9 +
    1.10 +<body>
    1.11 +<h1>Cookies set</h1>
    1.12 +<div id="set_cookies"></div>
    1.13 +<div>
    1.14 +	<input id="set_k">
    1.15 +	<input type="password" id="set_v">
    1.16 +	<input type="button" value="Set" onclick="set()">
    1.17 +</div>
    1.18 +</body>
    1.19 +<script type="text/javascript">
    1.20 +var setCookiesDiv = document.getElementById("set_cookies");
    1.21 +var setK = document.getElementById("set_k");
    1.22 +var setV = document.getElementById("set_v");
    1.23 +
    1.24 +function addSetCookie(k, v) {
    1.25 +	var d = document.createElement("div");
    1.26 +
    1.27 +	var kInput = document.createElement("input");
    1.28 +	kInput.disabled = true;
    1.29 +	kInput.value = k;
    1.30 +
    1.31 +	var vInput = document.createElement("input");
    1.32 +	vInput.type = "password";
    1.33 +	vInput.disabled = true;
    1.34 +	vInput.value = v;
    1.35 +
    1.36 +	var unset = document.createElement("input");
    1.37 +	unset.type = "button";
    1.38 +	unset.value = "Unset";
    1.39 +	unset.onclick = function() {
    1.40 +		docCookies.removeItem(k);
    1.41 +		setCookiesDiv.removeChild(d);
    1.42 +	};
    1.43 +
    1.44 +	d.appendChild(kInput);
    1.45 +	d.appendChild(vInput);
    1.46 +	d.appendChild(unset);
    1.47 +
    1.48 +	setCookiesDiv.appendChild(d);
    1.49 +}
    1.50 +
    1.51 +function clear() {
    1.52 +	while (setCookiesDiv.firstChild) {
    1.53 +		setCookiesDiv.removeChild(setCookiesDiv.firstChild);
    1.54 +	}
    1.55 +}
    1.56 +
    1.57 +function load() {
    1.58 +	clear();
    1.59 +	for (var i=0; i<docCookies.keys().length; i++) {
    1.60 +		var k = docCookies.keys()[i];
    1.61 +		if (docCookies.hasItem(k)) {
    1.62 +			var v = docCookies.getItem(k);
    1.63 +			addSetCookie(k, v);
    1.64 +		}
    1.65 +	}
    1.66 +}
    1.67 +
    1.68 +function set() {
    1.69 +	docCookies.setItem(setK.value, setV.value, 600);
    1.70 +	setK.value = "";
    1.71 +	setV.value = "";
    1.72 +	load();
    1.73 +}
    1.74 +
    1.75 +load();
    1.76 +</script>
    1.77 +</html>