Created
April 16, 2025 14:02
-
-
Save tejashah88/89f012fed204b69a96e7072eae44bf24 to your computer and use it in GitHub Desktop.
(Recursively) Lists the count of bookmarks for each folder on your bookmarks bar. Supports all Chromium-based browsers.
This file contains 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
// README: Run this by copying the code and pasting it in DevTools | |
function countBookmarksRecursively(node) { | |
let count = 0; | |
if (node.children) { | |
for (const child of node.children) { | |
count += countBookmarksRecursively(child); | |
} | |
} else if (node.url) { | |
count += 1; | |
} | |
return count; | |
} | |
chrome.bookmarks.getTree((rootNodes) => { | |
const root = rootNodes[0]; | |
if (!root.children) { | |
console.log("No bookmarks found."); | |
return; | |
} | |
for (const topLevel of root.children) { | |
if (!topLevel.title || !topLevel.children) continue; | |
if (topLevel.title != "Bookmarks") continue; | |
for (const subfolder of topLevel.children) { | |
if (subfolder.children) { | |
const count = countBookmarksRecursively(subfolder); | |
console.log(`"${subfolder.title}": ${count}`); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment