telekommander
9/15/2016 - 7:51 AM

Chrome extension to export all bookmarks

Chrome extension to export all bookmarks

//manifest.json
{
    "name": "bookmark-search-export",
    "version": "1.0",
    "manifest_version": 2,
    "description": "This extention will dump all bookmarks",
    "browser_action": {
        "default_icon": "icon.png"
    },
    "background": {
        "scripts": ["export.js"],
        "persistent": false
    },
    "permissions": [
        "bookmarks"
    ]
}
 
//export.js
chrome.runtime.onInstalled.addListener(function() {
 
    console.log("bookmark search exporter extention Installed.");
 
    var bm_urls = new Array();
 
    function fetch_bookmarks(parentNode) {
        parentNode.forEach(function(bookmark) {
            if(! (bookmark.url === undefined || bookmark.url === null)) {
                bm_urls.push(bookmark.url);
            }
            if (bookmark.children) {
                fetch_bookmarks(bookmark.children);
            }
        });
    }
 
    chrome.bookmarks.getTree(function(rootNode) {
        fetch_bookmarks(rootNode);
        console.log(JSON.stringify(bm_urls));
    });
});
 
 
chrome.bookmarks.onCreated.addListener(function(id, bookmark) {
    console.log("bookmark added .. " +  bookmark.url);
});
 
chrome.bookmarks.onRemoved.addListener(function(id, removeInfo) {
    console.log("bookmark removed .. " +  id);
});
 
chrome.bookmarks.onChanged.addListener(function(id, changeInfo){
    console.log("bookmark changed .. " +  id);
});