-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
37 lines (33 loc) · 1.11 KB
/
popup.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
$(function() {
chrome.windows.getCurrent(function(w) {
chrome.tabs.getSelected(w.id,function (tab){
$('#title').val(tab.title);
$('#title').select();
$('#url').val(tab.url);
});
});
//Add a bookmark
$('#add').click(function() {
var bookmarkTreeNodes = chrome.bookmarks.getTree(function(bookmarkTreeNodes) {
bookmarkTreeNodes = bookmarkTreeNodes[0].children;
//Add the bookmark in chrome
chrome.bookmarks.create({'parentId': bookmarkTreeNodes[0].id, 'title': $('#title').val(), 'url': $('#url').val()},
function(bookmark) {
//Add information to the storage
var callback = function(list) {
var index;
if(list.bookmarks != undefined) {
index = list.bookmarks.length;
}
else {
index = 0;
list.bookmarks = new Array();
}
list.bookmarks[index] = {'url': $('#url').val(), 'id': bookmark.id};
chrome.storage.sync.set({'bookmarks': list.bookmarks}, window.close()); //store the new bookmark
}
chrome.storage.sync.get('bookmarks', callback);
});
});
});
});