Bookmark Scrubber : json2html


Quick View

Here's how to use the JSON to HTML converter in a nutt shell.
<script type="text/javascript" src="JS/bkmkscrub.js"></script>
<script type="text/javascript">

	var myjsonobj = eval('(' + "the firefox bookmark JSON text data" + ')');

	function get_all_bookmarks() {
		var myhtml_full_data = bkmkscrub.json2html( myjsonobj );
	}

	function get_scrubbed_bookmarks() {
		var scrubTheseFoldersToo=["a folder to omit", "another folder to drop", "Nonvisible Stuff"];
		var myhtml_scrubbed_data = bkmkscrub.json2html( myjsonobj, 1, scrubTheseFoldersToo );
	}
</script>
Download the bookmark scrubber project.


Demo


The Details

First, include the javascript file:
	<script type="text/javascript" src="JS/bkmkscrub.js"></script>

Get the JSON data (text) file and feed it into eval(). There are a few ways to obtain the text data: URL, file browser or inlined. See the sample page for an example on using the file browser. The demo above shows how to fetch the data via the URL request. And inlining is just hard coding the text data.

	var myjsonobj = eval('(' + "the firefox bookmark JSON text data" + ')');
WARNING: eval() can take a long time if the bookmark file is pretty large.

Full Data
After myjsonobj is set with the JSON object, this can be passed into bkmkscrub.json2html() to obtain the HTML data.
To get the full data (nothing is filtered out - except Tags & Unsorted Bookmarks [1]) just call it like this:

	var myhtml_full_data = bkmkscrub.json2html( myjsonobj );
The results should be near identical to the export data from the Bookmarks Organizer utility. This is seen as [ ALL Bookmarks ] from the demo above.

Scrubbed Data
Before looking at how to obtain the scrubbed HTML data, a note about what bkmkscrub.json2html() is doing.

When an item (page or folder) has "DO_NOT_EXPORT" in the description box - the entry will be SCRUBBED from the generated file. Why the description box and not tags? There are no tag entries for folders. If you want this feature supported from the tags field, it is left as an exercise for the reader to implement. :P

The scrub option also automatically filters any bookmarks that finds the following matches in the URI:

Outside of the bookmark data, a scrub list of folders can be used. This is useful for folders which do not have description boxes (i.e. "Bookmarks Menu", "Bookmarks Toolbar", "Tags", "Unsorted Bookmarks", etc.). Why only folders and not also bookmarks? This option was meant to be on the fly, massive gross culling and flexible. I feel that bookmarks needs to be handled a little bit more delicately. Whereas folders (text/x-moz-place-container) can be used with an ax. However, this is also left as an exercise for the reader to implement if it is needed.

	// filter these folders on the fly
	var scrubTheseTitles=["a folder to omit", "another folder to drop", "Nonvisible Stuff"];

	// the second parameter tells bkmkscrub.json2html() to run the scrubber
	var myhtml_scrubbed_data = bkmkscrub.json2html( myjsonobj, 1, scrubTheseTitles );
The results from the [ Scrubbed Bookmarks ] demo above will show the following are omitted:

Notes

[1] What happened to "Tags" & "Unsorted Bookmarks"? These are those "root" folders that are seen in the Bookmark Organizer. They will be automatically omitted from the generated HTML files just like how the bookmark backup HTML exporter from the Bookmark Organizer does so as well.


Copyright © 2009 by ESTSS. All Rights Reserved.