Skip to content

Instantly share code, notes, and snippets.

@homostellaris
Last active February 26, 2024 07:06
Show Gist options
  • Select an option

  • Save homostellaris/13675a8480aca6bb008aeef076938d53 to your computer and use it in GitHub Desktop.

Select an option

Save homostellaris/13675a8480aca6bb008aeef076938d53 to your computer and use it in GitHub Desktop.
Count Chrome bookmarks
chrome.bookmarks.getTree(tree => {
let bookmarksCount = 0;
function countBookmarks(children) {
for (child of children) {
if (child.children) {
countBookmarks(child.children)
} else if (child.url) {
bookmarksCount += 1
} else {
throw new Error(`What is this? ${child}`, )
}
}
}
countBookmarks(tree)
console.log(bookmarksCount)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment