I want a simple text sortable list of the names of all my bookmarks.
When I save some bookmarks, I add a remark about the site or a hint about the password. I would like to extract a simple sortable list of all the bookmark names so that I can sort and list and take it with me when travelling, print it, etc. The more sophisticated bookmark programs aren't suitable for my purposes.
วิธีแก้ปัญหาที่เลือก
Hmm, actually, maybe you didn't mean an opening parenthesis at the beginning of the name, but anywhere in the name? In that case:
var aels=document.querySelectorAll('a[href]:not([href^="javascript:"]'); var tbl=document.createElement("table"); document.body.appendChild(tbl); tbl.outerHTML = '<table border="1" cellspacing="0" style="width:1200px; table-layout:fixed;"><thead><tr><th>Name</th><th>URL</th></tr></thead><tbody id="tbod"></tbody></table>'; var i, n, l, d, t=document.getElementById("tbod"); for (i=0; i<aels.length; i++){ n=aels[i].textContent; if (n.indexOf('(')>-1){ l=aels[i].href; t.insertAdjacentHTML('beforeend', '<tr><td>'+n+'</td><td>'+l+'</td></tr>'); } } t.parentNode.scrollIntoView();อ่านคำตอบนี้ในบริบท 👍 0
การตอบกลับทั้งหมด (14)
You can create an HTML backup and open this file in a Firefox tab.
No, if I open the HTML backup in Firefox I get an unsortable HTML list. If I open the backup in a text editor, I get the complete HTML code for the bookmarks.
Hi zootsuit, you can use a script to modify the HTML document on the fly or extract the links into a separate document. Since you criticized the HTML document as "unsortable" could you describe in more detail exactly what you want to end up with?
By the way, there's an add-on to create a CSV file showing the particular fields (e.g., name, URL, description) of interest to you but I haven't tried it myself:
https://addons.mozilla.org/firefox/addon/places-to-csv-sdk/
A CSV file can be opened in Microsoft Excel, Google Sheets, or a free office suite like OpenOffice.org or LibreOffice. Once in a spreadsheet program, it can be sorted and formatted.
Thanks, but I tried it but it keeps failing. Don't know why. Maybe I have too many bookmarks. I've got more than 800.
Another bookmarklet to sort the links:
javascript:(function(){ function bm(h,t,y){with(this){uri=h;title=t;type=y}} bm.prototype={uri:"",title:"",type:""}; function soh(a,b){return(a.uri>b.uri)} function sot(a,b){return(a.title.toLowerCase()>b.title.toLowerCase())} var s=prompt('%S','%S'),S=s?new RegExp(s,'i'):/.*/,L=1,O=1; var BM=[],BS=[null,soh,sot],T=[],ty="text/x-moz-place"; for(i=0;N=document.links[i];i++){if(S.test(N.href)){BM.push(new bm(N.href,N.innerHTML,ty))}} if(O){BM=BM.sort(BS[O])} T='<html><body><style>body{counter-reset:links}a{color:#000;}a:before{content:"["counter(links)"] ";counter-increment:links;}</style>'; for(i=0;B=BM[i];i++){T+='<a href="'+B.uri+'">'+(L==2?B.title:B.uri)+'</a><br>'} T+='</body></html>'; if(prompt('JSON',JSON.stringify(BM).replace(/^\[/,"").replace(/\]$/,""))){with(window.open().document){write(T);close()}} })()
(updated for JSON output)
เปลี่ยนแปลงโดย cor-el เมื่อ
zootsuit said
Thanks, but I tried it but it keeps failing. Don't know why. Maybe I have too many bookmarks. I've got more than 800.
Hmm, that doesn't seem like an excessive number.
By the way, if you can't solve the problem in Firefox, another option would be to create the HTML export file then import that into Internet Explorer, which will convert them to Windows Favorites. There probably are more tools to work with Windows Favorites than with Firefox bookmarks.
As long as we're hacking about with scripts... this one will gather the bookmarks (other than bookmarklets) into a three column table: name, URL, description (assuming that's where you put your notes). You can select and copy the table and paste it into a word processor or spreadsheet program.
Select and copy this script:
var aels=document.querySelectorAll('a[href]:not([href^="javascript:"]'); var tbl=document.createElement("table"); document.body.appendChild(tbl); tbl.outerHTML = '<table border="1" cellspacing="0" style="width:1200px; table-layout:fixed;"><thead><tr><th>Name</th><th>URL</th><th>Description</th></tr></thead><tbody id="tbod"></tbody></table>'; var i, n, l, d, t=document.getElementById("tbod"); for (i=0; i<aels.length; i++){ n=aels[i].textContent; l=aels[i].href; if (aels[i].parentNode.nextElementSibling){ if (aels[i].parentNode.nextElementSibling.nodeName=="DD") d=aels[i].parentNode.nextElementSibling.textContent; else d=""; } else d=""; t.insertAdjacentHTML('beforeend', '<tr><td>'+n+'</td><td>'+l+'</td><td>'+d+'</td></tr>'); } t.parentNode.scrollIntoView();
Then after opening your exported bookmarks file in a tab, open the Web Console using either:
- Ctrl+Shift+k
- "3-bar" menu button > Developer > Web Console
- Tools menu > Web Developer > Web Console
Paste the script in the blank line at the bottom of the console and press Enter to run it. It will take a moment, and then the page should scroll to the table. You can close the web console at that point.
I'll try the script. I've also found a complicated way to get the bookmarks into Word, where their names can be sorted.
RE Internet Explorer, it can't import all the bookmarks. I don't know if there are simply too many or some of the names or URLs can't fit into IE's rules for favorites, or what. In any case, importing didn't work.
The script works great. I can copy the table into Excel.
I don't use descriptions, so I was able to remove saving them from the script.
You've been generous. Can I ask you how to edit the script to select only bookmarks with an opening parenthesis in the name?
zootsuit said
I don't use descriptions, ... Can I ask you how to edit the script to select only bookmarks with an opening parenthesis in the name?
CSS selectors (the criteria used by querySelectorAll()) cannot read the actual display text of an link, so that needs to be checked for each name. Here's a revised version along those lines:
var aels=document.querySelectorAll('a[href]:not([href^="javascript:"]'); var tbl=document.createElement("table"); document.body.appendChild(tbl); tbl.outerHTML = '<table border="1" cellspacing="0" style="width:1200px; table-layout:fixed;"><thead><tr><th>Name</th><th>URL</th></tr></thead><tbody id="tbod"></tbody></table>'; var i, n, l, d, t=document.getElementById("tbod"); for (i=0; i<aels.length; i++){ n=aels[i].textContent; if (n.length>2 && n.substr(0,1)=='('){ l=aels[i].href; t.insertAdjacentHTML('beforeend', '<tr><td>'+n+'</td><td>'+l+'</td></tr>'); } } t.parentNode.scrollIntoView();
Note: the script is formatted for posting on the forum and may be garbled in email notifications, so please check the site if something seems wrong.
วิธีแก้ปัญหาที่เลือก
Hmm, actually, maybe you didn't mean an opening parenthesis at the beginning of the name, but anywhere in the name? In that case:
var aels=document.querySelectorAll('a[href]:not([href^="javascript:"]'); var tbl=document.createElement("table"); document.body.appendChild(tbl); tbl.outerHTML = '<table border="1" cellspacing="0" style="width:1200px; table-layout:fixed;"><thead><tr><th>Name</th><th>URL</th></tr></thead><tbody id="tbod"></tbody></table>'; var i, n, l, d, t=document.getElementById("tbod"); for (i=0; i<aels.length; i++){ n=aels[i].textContent; if (n.indexOf('(')>-1){ l=aels[i].href; t.insertAdjacentHTML('beforeend', '<tr><td>'+n+'</td><td>'+l+'</td></tr>'); } } t.parentNode.scrollIntoView();
That's perfect! I can't thank you enough.
By the way, it handled 867 bookmarks without error.
Thanks a million.
Here are two other versions of the above posted bookmarklet with background color in case someone is interested. You can modify the regular expression to limit what URLs and names to include. Try the second version on this website.
Natural sorting (unsorted):
var d=document; var stl=d.createElement("style"); d.getElementsByTagName('head')[0].appendChild(stl); stl.textContent = 'body{counter-reset:links}td.name:before{content:"["counter(links)"] "; counter-increment:links; background-color:#ff7;}\n'+ 'body>h1,body>dl{display:none}\n'+ 'table{background-color:#ffb; empty-cells:show;}\n'+ 'td{font-family:Verdana,Arial,Sans-Serif; font-size: 100%; padding: 1px 2px; vertical-align:top;}\n'+ '.header{background-color:#ffd;}\n'+ '.wrap{table-layout:fixed; width:100%; overflow:hidden; word-wrap:break-word; border-spacing:0;}\n'; var tbl=d.createElement("table"); d.body.appendChild(tbl); var aels=d.querySelectorAll('a[href]'); tbl.outerHTML='<table border="1" cellspacing="0"><thead><tr class="header"><th>Name</th><th>URL</th><th>Description</th></tr></thead><tbody id="tbod"></tbody></table>'; var i,n,l,c,t=d.getElementById("tbod"); for (i=0;a=aels[i];i++){ l=a.href; n=a.textContent; if (/^https?:|^ftps?:/.test(l) && /.+/.test(n)){ c=a.parentNode.nextElementSibling && a.parentNode.nextElementSibling.nodeName=="DD"?a.parentNode.nextElementSibling.textContent:""; t.insertAdjacentHTML('beforeend','<tr><td><table class="wrap"><tr><td class="name">'+n+'</td></tr></table></td><td><table class="wrap"><tr><td class="link">'+l+'</td></tr></table></td><td ><table class="wrap"><tr><td class="desc">'+c+'</td></tr></table></td></tr>'); } } t.parentNode.scrollIntoView();
Sorted list:
var d=document; function bm(h,t,y,d){with(this){uri=h;title=t;type=y;description=d;}} bm.prototype={uri:"",title:"",type:"",description:""}; function soh(a,b){return(a.uri>b.uri)} function sot(a,b){return(a.title.toLowerCase()>b.title.toLowerCase())} var s='',S=s?new RegExp(s,'i'):/^https?:|^ftps?:/,L=1,O=1; var BM=[],BS=[null,soh,sot],T=[],ty="text/x-moz-place"; var n=d.querySelectorAll('a[href]'),N; for(i=0;N=n[i];i++){ if(S.test(N.href)){ dd=N.parentNode.nextElementSibling && N.parentNode.nextElementSibling.nodeName=="DD"?N.parentNode.nextElementSibling.textContent:""; BM.push(new bm(N.href,N.textContent,ty,dd))} } if(O){BM=BM.sort(BS[O])} var stl=d.createElement("style"); d.getElementsByTagName('head')[0].appendChild(stl); stl.textContent = 'body{counter-reset:links}td.name:before{content:"["counter(links)"] ";counter-increment:links;background-color:#ff7;}\n'+ 'body>h1,body>dl{display:none}\n'+ 'table{background-color:#ffb; empty-cells:show;}\n'+ 'td{font-family:Verdana,Arial,Sans-Serif; font-size: 100%; padding: 1px 2px; vertical-align:top;}\n'+ '.header{background-color:#ffd;}\n'+ '.wrap{table-layout:fixed; width:100%; overflow:hidden; word-wrap:break-word; border-spacing:0;}\n'; var tbl=d.createElement("table"); d.body.appendChild(tbl); tbl.outerHTML = '<table border="1" cellspacing="0"><thead><tr class="header"><th>Name</th><th>URL</th><th>Description</th></tr></thead><tbody id="tbod"></tbody></table>'; var i,n,l,t=d.getElementById("tbod"); for (i=0; b=BM[i]; i++){ n = b.textContent; if (/.+/.test(n)){ l=b.uri; t.insertAdjacentHTML('beforeend','<tr><td><table class="wrap"><tr><td class="name">'+b.title+'</td></tr></table></td><td><table class="wrap"><tr><td class="link">'+b.uri+'</td></tr></table></td><td ><table class="wrap"><tr><td class="desc">'+b.description+'</td></tr></table></td></tr>'); } } t.parentNode.scrollIntoView();
เปลี่ยนแปลงโดย cor-el เมื่อ