import "@johnlindquist/kit";
let rawBookmarks = await readFile(
home("Library/Application Support/Google/Chrome/Default/Bookmarks"),
"utf8"
);
const parsedBookmarks = JSON.parse(rawBookmarks);
const bookmarkStructure = parsedBookmarks.roots.bookmark_bar.children;
const bookmarks = (function flatten(
bookmarkElements
) {
return bookmarkElements.reduce((acc, cur) => {
if (cur.type === "folder") {
return [...acc, ...flatten(cur.children)];
}
return [...acc, cur];
}, []);
})(bookmarkStructure);
let bookmarkChoices = bookmarks.map(({ name, url }) => {
return {
name: name,
description: url,
value: url,
};
});
let bookmarksAndOpen = [...bookmarkChoices];
let choices = _.uniqBy(bookmarksAndOpen, "name");
let url = await arg("Oepn Chrome tab:", choices);
focusTab(url);