-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.html
73 lines (61 loc) · 2.04 KB
/
simple.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<title>Simple Local Storage Manager</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
function remove(key) {
localStorage.removeItem(key);
hide(key);
}
function hide(key){
var row = $('#' + reformat(key));
row.remove();
}
function reformat(key) {
return key.replace(/\./g, '_');
}
function display() {
$('#table').empty();
$('#table').append('<tr><th>Hide</th><th>Delete</th><th>Key</th><th>Data</th></tr>');
var size = 0;
for (var i = 0 ; i < localStorage.length ; i++)
{
var key = localStorage.key(i);
var data = localStorage.getItem(key);
var label = reformat(key);
size += key.length + data.length;
var hideButton = '<button type="button" onClick="hide(' + "'" + key + "'" +')">Hide</button>';
var deleteButton = '<button type="button" onClick="remove(' + "'" + key + "'" +')">Delete</button>';
var row = '<tr id="' + label + '">';
row += '<td>' + hideButton + '</td>';
row += '<td>' + deleteButton + '</td>';
row += '<td>' + key + '</td>';
row += '<td>' + data + '</td></tr>';
$('#table').append(row);
}
$('#total').empty();
$('#total').append('Total size=' + size + 'count=' + localStorage.length);
}
$(document).ready(function(){
display();
});
</script>
</head>
<body>
<div id="top">
<h1>Simple Local Storage Manager</h1>
<div>
<button type="button" onClick="localStorage.clear();$('#table').empty();">Clear</button>
<button type="button" onClick="display()">Display</button>
</div>
<div id="total">
</div>
<div>
<table id="table">
</tr>
</table>
</div>
</div>
</body>
</html>