-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
108 lines (104 loc) · 3.89 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var defaultLocation = "";
var bookmark_ids=new Array();
var bookmark_titleEditor = "0";
function onchangeFolderLocation(id)
{
chrome.storage.sync.get("bookmark_location", function (obj) {
defaultLocation=obj.bookmark_location;
//console.debug("before setting def loc : "+ defaultLocation);
chrome.storage.sync.set({"bookmark_location":id}, function () {});
chrome.storage.sync.get("bookmark_location", function (obj) {
defaultLocation=obj.bookmark_location;
//console.debug("after setting def loc : "+ defaultLocation);
});
});
}
var folderlist="<select id='folderlocation' class='ask' >";
var foldername ="";
var listDiv="<label class='listAll' ><ul>";
function printBookmarkForNode(id)
{
chrome.bookmarks.getChildren(id, function(children) {
children.forEach(function(bookmark) {
if(bookmark.url) {
//console.debug(bookmark_ids);
if(bookmark_ids.indexOf(bookmark.id.toString()) >= 0){
//console.debug(bookmark.id);
listDiv += '<li><a href="'+bookmark.url+'" target="_blank" >'+bookmark.title+'</a></li>';
}
}
printBookmarkForNode(bookmark.id);
});
});
listDiv+='</ul></label>';
document.getElementById("listAllBookmarks").innerHTML=listDiv;
}
function printAllBookmarks() {
printBookmarkForNode('1');
}
function loadBookmarkLocations(id) {
chrome.bookmarks.getChildren(id, function(children) {
//console.debug(children);
for (i = 0; i < children.length; i++) {
if(!children[i].url){
if(children[i].id == defaultLocation) //watever nikil set variable
foldername += '<option value="'+children[i].id+'" selected>'+children[i].title+'</option>';
else
foldername += '<option value="'+children[i].id+'" >'+children[i].title+'</option>';
}
}
folderlist+=foldername+'</select>';
document.getElementById("bookmarks").innerHTML=folderlist;
document.getElementById("folderlocation").addEventListener('change', function() {
onchangeFolderLocation(this.options[this.selectedIndex].value);
},false);
});
}
function updateBookmarkedIds()
{
chrome.storage.sync.get('bookmark_ids', function (bookmark_ids_object){
if(bookmark_ids_object.bookmark_ids){
bookmark_ids=bookmark_ids_object.bookmark_ids.split(",");
}
printAllBookmarks();
});
}
function onclickTitleEditor(status)
{
if(status){
chrome.storage.sync.set({"bookmark_title_editor":"1"}, function () {});
bookmark_titleEditor="1";
}else{
chrome.storage.sync.set({"bookmark_title_editor":"0"}, function () {});
bookmark_titleEditor="0";
}
}
function activateSocialPlugin()
{
var like='<iframe src="http://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FFB-Bookmark-Post%2F1441303972751258&width&layout=standard&action=like&show_faces=true&share=true&height=80&appId=277671059020997" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"></iframe>';
document.getElementById("facebookLike").innerHTML=like;
}
document.addEventListener('DOMContentLoaded', function () {
chrome.storage.sync.get("bookmark_location", function (obj) {
defaultLocation=obj.bookmark_location;
//console.debug("initial def loc "+defaultLocation);
if(!defaultLocation){
chrome.storage.sync.set({"bookmark_location":"1"}, function () {});
}
loadBookmarkLocations('1');
updateBookmarkedIds();
});
chrome.storage.sync.get("bookmark_title_editor", function (obj) {
bookmark_titleEditor=obj.bookmark_title_editor;
if(bookmark_titleEditor=="1")
document.getElementById("titleEditor").checked=true;
else
document.getElementById("titleEditor").checked=false;
});
document.getElementById("titleEditor").addEventListener('click', function() {
onclickTitleEditor(this.checked);
},false);
document.getElementById("socialPlugin").addEventListener('click', function() {
activateSocialPlugin();
},false);
});