Revision loading, sync isses fix

This commit is contained in:
2025-09-24 07:34:25 +00:00
parent 4f120b68f5
commit 9f7f4c470e
5 changed files with 143 additions and 120 deletions

34
bookmark.js Normal file
View 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?.();
});
});
}
});
}