Last active
June 23, 2017 08:33
-
-
Save whitequark/fd8ac25d0ab6c84fa6b206ac88b824a5 to your computer and use it in GitHub Desktop.
A small bookmarklet to export a bookmark folder as HTML, since Chrome does not provide this functionality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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