Skip to content

Instantly share code, notes, and snippets.

@Telematica
Last active February 20, 2024 03:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Telematica/0afb8492f0da2b7833f4 to your computer and use it in GitHub Desktop.
Save Telematica/0afb8492f0da2b7833f4 to your computer and use it in GitHub Desktop.
Simple Raw Text Export for Google Chrome Bookmarks

Chrome Bookmark Manager Extended Features

/**
* @function
* @description Gets all Bookmarks from Chrome Bookmark repository
* @param object window
* @return string
*/
;(function (window) {
var fetcher = {
groupByDomain : true,
wrapAsArray : false, //@todo bookmark array dump
url : document.createElement('a'),
urls : (this.groupByDomain) ? {} : [],
/**
* @function
* @description
* @param object tree
* @return undefined
*/
fetchFromTree : function (tree) {
return this.bookmarks = (function (tree) {
fetcher.url = document.createElement('a');
fetcher.urls = fetcher.groupByDomain ? {} : [];
tree[0].children.forEach(fetcher.getBookmarks);
return fetcher.urls;
})(tree);
},
/**
* @function
* @description
* @param object tree
* @return undefined
*/
getBookmarks : function (subTree) {
if (subTree.children) {
return fetcher.getBookmarks(subTree.children);
} else {
subTree.forEach(
fetcher.extractRecursiveFromSubTree
);
}
return void 0;
},
/**
* @function
* @description
* @param object tree
* @return undefined
*/
extractRecursiveFromSubTree : function (item) {
if (!item.url) {
return fetcher.getBookmarks(item);
} else {
fetcher.url.href = item.url;
if(fetcher.groupByDomain) {
var domain = fetcher.url.protocol + "//" + fetcher.url.host;
if (fetcher.urls[domain]) {
if (fetcher.urls[domain].indexOf(item.url) === -1) {
fetcher.urls[domain].push(item.url);
}
} else {
fetcher.urls[domain] = [item.url];
}
} else {
fetcher.urls.push(item.url);
}
}
return void 0;
},
/**
* @todo 's (Research how to embed generators within objects)
------------------------------------------------------------
*/
getDuplicatedBookmarks : function () {
return function* () {
}
}
}
try {
if (window.chrome === void 0 || window.chrome.bookmarks === void 0) {
throw new Error("Chrome Object is not available.");
}
fetcher.groupByDomain = true;
chrome.bookmarks.getTree(fetcher.fetchFromTree.bind(this));
console.log(window.bookmarks);
} catch (e) {
console.log('aaa',e);
}
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment