Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A small bookmarklet to export a bookmark folder as HTML, since Chrome does not provide this functionality
// by whitequark. released under CC0.
(function() {
function downloadFile(fileName, content) {
var dataURI = 'data:text/plain;charset=UTF-8,' +
encodeURIComponent(content);
var fakeLink = document.createElement('a');
fakeLink.setAttribute('href', dataURI);
fakeLink.setAttribute('download', fileName);
var fakeEvent = document.createEvent('MouseEvents');
fakeEvent.initEvent('click', true, true);
fakeLink.dispatchEvent(fakeEvent);
}
var out = '';
out += '<!DOCTYPE NETSCAPE-Bookmark-file-1>\n';
out += '<TITLE>Bookmarks</TITLE>\n';
out += '<DL>';
document.querySelectorAll('[role="listitem"]').forEach(function(elem) {
var label = elem.getElementsByClassName('label')[0].textContent;
var url = elem.getElementsByClassName('url')[0].textContent;
out += '<DT><A HREF="' + encodeURI(url) + '">' + label + '</A>\n';
});
out += '</DL>';
var name = 'bookmarks-';
name += document.querySelector('div[selected] .tree-label').textContent;
name += '.html';
downloadFile(name, out);
})();
javascript:(function(){var e="";e+="<!DOCTYPE NETSCAPE-Bookmark-file-1>\n",e+="<TITLE>Bookmarks</TITLE>\n",e+="<DL>",document.querySelectorAll('[role="listitem"]').forEach(function(t){var n=t.getElementsByClassName("label")[0].textContent,o=t.getElementsByClassName("url")[0].textContent;e+='<DT><A HREF="'+encodeURI(o)+'">'+n+"</A>\n"}),e+="</DL>";var t="bookmarks-";t+=document.querySelector("div[selected] .tree-label").textContent,function(e,t){var n="data:text/plain;charset=UTF-8,"+encodeURIComponent(t),o=document.createElement("a");o.setAttribute("href",n),o.setAttribute("download",e);var a=document.createEvent("MouseEvents");a.initEvent("click",!0,!0),o.dispatchEvent(a)}(t+=".html",e)})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.