-
Notifications
You must be signed in to change notification settings - Fork 0
/
asyncFunctions.js
198 lines (175 loc) · 5.05 KB
/
asyncFunctions.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// async forEach
asyncForEach = async (arr,callback) => {
for (let i=0; i < arr.length; i++) {
await callback(arr[i],i,arr);
};
};
/* promisified Chrome API functions */
/*---------------------------------------------------------------------------------------------*/
// chrome bookmark get
const bookmarkGet = async bookmarkId => {
return new Promise(resolve => {
chrome.bookmarks.get(bookmarkId,bookmarkTreeNode => {
if (chrome.runtime.lastError) {
return resolve(false);
}
return resolve(bookmarkTreeNode);
});
});
};
// chrome bookmark remove
const bookmarkRemove = async bookmarkId => {
return new Promise(resolve => {
chrome.bookmarks.remove(bookmarkId,() => {
if (chrome.runtime.lastError) {
return resolve(false);
}
return resolve(true);
});
});
};
// chrome bookmarks remove
const bookmarksRemove = async bookmarkId => {
console.log(bookmarkId);
return new Promise(resolve => {
chrome.bookmarks.removeTree(bookmarkId,() => {
if (chrome.runtime.lastError) {
return resolve(false);
}
return resolve('successfully removed folder w/ urls');
});
});
};
// chrome bookmarks create
const bookmarkCreate = async options => {
return new Promise(resolve => {
chrome.bookmarks.create(options,bookmarkTreeNode => {
if (chrome.runtime.lastError) {
return resolve(false);
}
return resolve(bookmarkTreeNode);
});
});
};
// chrome bookmarks update
const bookmarkUpdate = async (bookmarkId,changes) => {
return new Promise(resolve => {
chrome.bookmarks.update(bookmarkId,changes,bookmarkTreeNode => {
if (chrome.runtime.lastError) {
return resolve(false);
}
return resolve(bookmarkTreeNode);
});
});
};
// chrome bookmarks move
const bookmarkMove = async (bookmarkId,destination) => {
return new Promise(resolve => {
chrome.bookmarks.move(bookmarkId,destination,bookmarkTreeNode => {
return resolve(bookmarkTreeNode);
});
});
};
// chrome bookmarks get subtree
const bookmarkGetSubTree = async bookmarkId => {
return new Promise(resolve => {
chrome.bookmarks.getSubTree(bookmarkId,bookmarkNodeTrees => {
if (chrome.runtime.lastError) {
return resolve(false);
}
return resolve(bookmarkNodeTrees);
});
});
};
// chrome storage set
const storageSet = async modifiedData => {
return new Promise(resolve => {
chrome.storage.local.set(modifiedData,() => {
return resolve('successfully updated storage');
});
});
};
// chrome storage get
const storageGet = async () => {
return new Promise(resolve => {
chrome.storage.local.get(null,res => {
return resolve(res);
});
});
};
// chrome storage remove
const storageRemove = async groupId => {
return new Promise(resolve => {
chrome.storage.local.remove(groupId,() => {
return resolve(null);
});
});
};
// chrome storage clear
const storageClear = async () => {
return new Promise(resolve => {
chrome.storage.local.clear(() => {
return resolve('cleared!');
});
});
};
// chrome sync storage get
const syncStorageGet = async () => {
return new Promise(resolve => {
chrome.storage.sync.get(null,res => {
return resolve(res);
});
});
};
// chrome sync storage set
const syncStorageSet = async modifiedData => {
return new Promise(resolve => {
chrome.storage.sync.set(modifiedData,() => {
return resolve('successfully updated storage');
});
});
};
// chrome sync storage clear
const syncStorageClear = async () => {
return new Promise(resolve => {
chrome.storage.sync.clear(() => {
return resolve(true);
});
});
};
// chrome tabs create
const tabsCreate = async options => {
return new Promise(resolve => {
chrome.tabs.create(options, tab => {
return resolve(tab);
});
});
};
// chrome tabs query
const tabsQuery = async options => {
return new Promise(resolve => {
chrome.tabs.query(options, tabs => {
return resolve(tabs);
});
});
};
// chrome get all trees
const treesGet = async () => {
return new Promise(resolve => {
chrome.bookmarks.getTree(bookmarkTreeNodes => {
if (chrome.runtime.lastError) {
return resolve(false);
}
return resolve(bookmarkTreeNodes);
});
});
};
// chrome open new window && create list of tabs
const windowOpenNTabsCreate = async urls => {
return new Promise(resolve => {
chrome.windows.create({ url: urls },() => {
return resolve(null);
});
});
};
/*----------------------------------------------------------------------------------------------*/