Revision loading, sync isses fix
This commit is contained in:
34
bookmark.js
Normal file
34
bookmark.js
Normal file
@@ -0,0 +1,34 @@
|
||||
// Recursively create bookmarks from nodes
|
||||
export async function createBookmarks(nodes, parentId) {
|
||||
for (const node of nodes) {
|
||||
if (node.url) {
|
||||
chrome.bookmarks.create({ parentId, title: node.title, url: node.url });
|
||||
} else {
|
||||
chrome.bookmarks.create({ parentId, title: node.title }, (newFolder) => {
|
||||
if (node.children && node.children.length > 0) {
|
||||
createBookmarks(node.children, newFolder.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively delete all children
|
||||
export async function removeBookmarks(parentId, done) {
|
||||
const children = await chrome.bookmarks.getChildren(parentId);
|
||||
if (!children || children.length === 0) return done?.();
|
||||
let count = children.length;
|
||||
children.forEach((child) => {
|
||||
if (child.url) {
|
||||
chrome.bookmarks.remove(child.id, () => {
|
||||
if (--count === 0) done?.();
|
||||
});
|
||||
} else {
|
||||
removeBookmarks(child.id, () => {
|
||||
chrome.bookmarks.remove(child.id, () => {
|
||||
if (--count === 0) done?.();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user