Last active
February 26, 2024 07:06
-
-
Save homostellaris/13675a8480aca6bb008aeef076938d53 to your computer and use it in GitHub Desktop.
Count Chrome bookmarks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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