-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.js
82 lines (60 loc) · 1.67 KB
/
list.js
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
74
75
76
77
78
79
80
81
82
$( document ).ready(function() {
refreshUrls();
$("#button").click(function() {
console.log("clicked");
chrome.tabs.query({active: true, currentWindow: true }, function(tab) {
var url = $("#urlbox").val();
var text = $("#textbox").val();
var saveObj = {};
saveObj[text] = url;
chrome.storage.sync.set(saveObj, function() {
console.log('%s saves as %s',
url,
text);
$("#textbox").val('');
$("#urlbox").val('');
$("#link-list").empty();
refreshUrls();
});
});
});
$("#textbox").keyup(function(event){
if(event.keyCode == 13){
$("#button").click();
}
});
$("#urlbox").keyup(function(event){
if(event.keyCode == 13){
$("#button").click();
}
});
});
$(document).on('click', ".delete", function() {
var key = this.id;
console.log("delete " + key);
chrome.storage.sync.remove(key, function() {
console.log('%s removed', key);
$("#link-list").empty();
refreshUrls();
});
});
function refreshUrls() {
chrome.storage.sync.get(function(urls) {
var i = 0;
for (key in urls) {
var row = '<div class="row list-item';
if (i % 2 == 0) {
row += ' list-item-odd';
} else {
row += ' list-item-even';
}
row += '">';
row += '<div class="col-md-3 key">' + key + '</div>';
row += '<div class="col-md-6 url"><a href="' + urls[key] + '">' + urls[key] + '</a></div>';
row += '<div class="col-md-3"><a href="#" class="delete" id="' + key + '">delete</a></div>';
row += '</div>';
i += 1;
$("#link-list").append(row);
}
});
}