Permalink
Browse files

Safest setting and retrieval

  • Loading branch information...
1 parent ee2012f commit 1fd8498c783df08094a0c831b993b750d1d5bcb5 @philcali committed Apr 13, 2012
Showing with 27 additions and 20 deletions.
  1. +15 −12 options.js
  2. +12 −8 popup.js
View
@@ -7,18 +7,21 @@ $(function() {
var reload = function() {
$("#html-table").html('');
- for (var i = 0; i < localStorage.length; i += 3) {
- var url = localStorage.getItem(i),
- k = localStorage.getItem(url + '-key'),
- t = localStorage.getItem(url + '-title'),
- del = '<a href="#" class="delete" id="'+ i +'">' + deleteicon + '</a>',
- get = '<a href="'+ url +'" class="get" target="_blank">'+ urlicon +'</a>';
-
- $("#host-table").append(
- "<tr><td>"+ url +"</td><td>"+ k +"</td><td>" + t +
- "</td><td>"+ [get, del].join(' | ') +"</td></tr>"
+ $(localStorage).each(function(index) {
+ var i = localStorage.key(index);
+ if (i.match(/^host\-\d+/)) {
+ var url = localStorage.getItem(i),
+ k = localStorage.getItem(url + '-key'),
+ t = localStorage.getItem(url + '-title'),
+ del = '<a href="#" class="delete" id="'+ i +'">' + deleteicon + '</a>',
+ get = '<a href="'+ url +'" class="get" target="_blank">'+ urlicon +'</a>';
+
+ $("#host-table").append(
+ "<tr><td>"+ url +"</td><td>"+ k +"</td><td>" + t +
+ "</td><td>"+ [get, del].join(' | ') +"</td></tr>"
);
- }
+ }
+ });
};
$(".delete").live("click", function() {
@@ -45,7 +48,7 @@ $(function() {
return false;
}
- localStorage.setItem(localStorage.length, url);
+ localStorage.setItem("host-" + localStorage.length, url);
localStorage.setItem(url + '-key', $(key).val());
localStorage.setItem(url + '-title', name);
window.location.href = window.location.href;
View
@@ -5,15 +5,19 @@ $(function() {
);
}
- for (var i=0; i < localStorage.length; i += 3) {
- var url = localStorage.getItem(i),
- title = localStorage.getItem(url + '-title');
+ $(localStorage).each(function(index) {
+ var i = localStorage.key(index);
+ console.log(i);
+ if (i.match(/^host\-\d+/)) {
+ var url = localStorage.getItem(i),
+ title = localStorage.getItem(url + '-title');
- $("ul").append(
- '<li><a class="host" id="' + i + '" href="' +
- url + '">' + title + '</a></li>'
- );
- }
+ $("ul").append(
+ '<li><a class="host" id="' + i + '" href="' +
+ url + '">' + title + '</a></li>'
+ );
+ }
+ });
$(".host").on('click', function() {
var url = localStorage.getItem($(this).attr('id'));

0 comments on commit 1fd8498

Please sign in to comment.