forked from nisargkolhe/arcify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalstorage.js
More file actions
32 lines (30 loc) · 1.09 KB
/
localstorage.js
File metadata and controls
32 lines (30 loc) · 1.09 KB
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
const LocalStorage = {
getOrCreateArcifyFolder: async function () {
let [ folder ] = await chrome.bookmarks.search({ title: 'Arcify' });
if (!folder) {
folder = await chrome.bookmarks.create({ title: 'Arcify' });
}
return folder;
},
getOrCreateSpaceFolder: async function(spaceName) {
const arcifyFolder = await this.getOrCreateArcifyFolder();
const children = await chrome.bookmarks.getChildren(arcifyFolder.id);
let spaceFolder = children.find((f) => f.title === spaceName);
if (!spaceFolder) {
spaceFolder = await chrome.bookmarks.create({
parentId: arcifyFolder.id,
title: spaceName
});
}
return spaceFolder;
},
// Helper function to generate UUID
generateUUID: function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
}
export { LocalStorage };