Skip to content

Instantly share code, notes, and snippets.

@tejashah88
Created April 16, 2025 14:02
Show Gist options
  • Save tejashah88/89f012fed204b69a96e7072eae44bf24 to your computer and use it in GitHub Desktop.
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.
// 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