Sort tag separations alphabetically

TalkRecommend Site Improvements

Join LibraryThing to post.

Sort tag separations alphabetically

This topic is currently marked as "dormant"—the last message is more than 90 days old. You can revive it by posting a reply.

1lemontwist
Apr 20, 2011, 12:42 pm

When I want to separate tags from a tag that has approximately 10,000 tags combined with it (see: http://www.librarything.com/tag/historical+fiction) it would be great to have the list that comes up be alphabetical. As it is, it constantly changes order so I have no idea if I've proposed all the separations or not. It's a really terrible system.

2norabelle414
Edited: Apr 20, 2011, 1:35 pm

I agree. This bothers me to no end, even when there are only 10 or so tags combined together.

3brightcopy
Edited: Apr 24, 2011, 12:08 am

Until such a time as this happens, I've whipped up a little something to help out. Create a bookmark and paste the following as the URL:

javascript:(function(){var p=document.evaluate('//p[@class="alsoknownas"]',document.body,null,XPathResult.ANY_UNORDERED_NODE_TYPE,null).singleNodeValue;var e=document.evaluate('.//a[starts-with(@href,"/tag")]',p,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);var a=[];var i;for(i=0;i<e.snapshotLength;i++)a.push(e.snapshotItem(i).textContent);a.sort();var html='';for(i=0;i<a.length;i++)html+='<a class="alwaysgrey" href="/tag/'+encodeURIComponent(a[i]).replace(/%20/g,'+')+'">'+a[i]+'</a><br>';p.innerHTML=html;f=document.evaluate('//select[@id="totag"]',document.body,null,XPathResult.ANY_UNORDERED_NODE_TYPE,null).singleNodeValue.innerHTML='<option>'+a.join('</option><option>')+'</option>'}())

Then when you are on the tag page, click the bookmark. This should sort the tags and put them each on one line for easier reading. Hopefully that's actually a helpful improvement for what you're using them for. If not, I can provide a version without that. All the links should remain intact. If not, let me know.

ETA: It also changes the dropdown box for separations so that all the items are sorted.

ETA: Updated to fix bugs.

4lemontwist
Apr 21, 2011, 6:18 am

3> Cool... except that I'm not sure how to bookmark something that's Javascript in Firefox. I can't see where to start a bookmark from scratch where I can define the URL. Any ideas?

5mene
Apr 21, 2011, 8:40 am

Make a bookmark of a random page and then change the url of that bookmark?

6lemontwist
Edited: Apr 21, 2011, 9:18 am

Ah, ok, well I got it to work. It lists all of the tags at the top of the page alphabetically but not in the drop down list of separations.

Also... it lists a lot of tags that are not actually combined. For example if you do that JavaScript thing on the historical fiction tag, you see a lot of tags like:

Afghanistan
American
American literature
Aubrey/Maturin
Britain, historical fiction, romance
British
China
Civil War
England
England, historical fiction, romance

Which are not combined with historical fiction.

7brightcopy
Apr 21, 2011, 10:36 am

I updated the code in the post above, so just paste that one back in. It was snagging data from "Related Tags" (among others). It was as simple as a missing "." in the code. I didn't even think about the dropdown, but it was fairly easy to add as well. Enjoy!

8brightcopy
Apr 21, 2011, 10:43 am

Sorry, forgot to do the whole escaping for < and []. Fixed now.

9lemontwist
Apr 21, 2011, 11:30 am

That is a beautiful thing! Thanks!!! :-D