Brave bookmarks recursively

Hey there 👋

I just discovered Script Kit today, and I absolutely love it, awesome idea @johnlindquist 🔥

I made a few changes to your script chrome-bookmarks so I can use it with Brave (small change), but also to parse the bookmarks JSON recursively. This is particularly useful to me as I nest all my bookmarks in subfolders of the bookmark bar. With this change, I can open any bookmark (however deep it is nested in the bookmarks JSON).

I thought I'd share the script here, in case anyone find it useful too.

// Menu: Brave Bookmarks
// Description: Select and open a bookmark from Brave
function parseBookmarks(node) {
const bookmarks = [];
node.forEach((item) => {
if (item.type === "url") {
bookmarks.push(item);
} else if (item.type === "folder") {
bookmarks.push(...parseBookmarks(item.children));
}
});
return bookmarks;
}
let bookmarksFile = await readFile(
home(
"Library/Application Support/BraveSoftware/Brave-Browser/Default/Bookmarks"
)
);
const rootNode = JSON.parse(bookmarksFile);
const bookmarkBar = rootNode.roots.bookmark_bar;
const bookmarks = parseBookmarks(bookmarkBar.children);
let url = await arg(
"Select bookmark",
bookmarks.map(({ name, url }) => {
return {
name: name || url,
description: url,
value: url,
};
})
);
exec(`open ${url}`);