Zap Ugly XML Buttons





Zap Ugly XML Buttons

Make weblogs more palatable by replacing those orange XML buttons.

If you read weblogs regularly, you have undoubtedly seen an orange XML button. What is this? It's a link to the site's syndicated feed, suitable for reading in a dedicated news aggregator.

So, why does it say "XML," and why is it that dreadful shade of orange? Nobody knows. It seems to be specifically designed to clash with every possible color scheme. This hack replaces it with a plain-text link that says "Feed."

Learn more about syndication at http://atomenabled.org.


The Code

This user script runs on all pages. It identifies the orange XML buttons by their size, so it won't catch custom buttons that are a different size. But it catches most of them.

Save the following user script as zapxmlbuttons.user.js:


	// ==UserScript==

	// @name		Zap XML buttons

	// @namespace	http://diveintomark.org/projects/greasemonkey/

	// @description	convert orange XML buttons to text

	// @include		*

	// ==/UserScript==



	var snapXMLImages = document.evaluate(

		"//img[@width='36'][@height='14']",

		document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);



	for (var i = snapXMLImages.snapshotLength - 1; i >= 0; i--) {

		var elmXMLImage = snapXMLImages.snapshotItem(i);

		if (/(xml|rss)/i.test(elmXMLImage.src)) {

			var elmXMLText = document.createTextNode('Feed');

			elmXMLImage.parentNode.replaceChild(elmXMLText, elmXMLImage);

		}

	}


Running the Hack

Before installing the user script, go to http://radio.weblogs.com/0001011/, which includes an orange XML button, as shown in Figure.

XML button


Now, install the user script (Tools Install This User Script) and refresh http://radio.weblogs.com/0001011/. You will see the XML button is gone, replaced by a plain-text link, as shown in Figure.

Feed link


Hacking the Hack

This hack makes the Web a prettier place, but it doesn't actually make it any more useful. If you click a feed link, it still just shows you the raw RSS or Atom feed, or worse, offers to download it. There is an emerging standard among desktop news aggregators for subscribing to feeds by using a feed:// URL instead of http://. News aggregators register themselves as the handler for the feed:// protocol, and when you click one, it launches your news aggregator and offers to subscribe to the feed.

We can make one small change to this script to make feed links launch your external news aggregator when you click them.

Add this code at the end of the loop:


	for (var i = snapXMLImages.snapshotLength - 1; i >= 0; i--) {

		var elmXMLImage = snapXMLImages.snapshotItem(i);



		if (/(xml|rss)/i.test(elmXMLImage.src)) { 

			var elmXMLText = document.createTextNode('Feed');

			elmXMLImage.parentNode.replaceChild(elmXMLText, elmXMLImage);

			var elmLink = elmXMLText.parentNode;

			while (elmLink && elmLink.nodeName.toUpperCase() != 'A' &&

				  elmLink.nodeName.toUpperCase() != 'BODY') {

				elmLink = elmLink.parentNode;

			}

			if (elmLink && elmLink.nodeName.toUpperCase() == 'A') {

				elmLink.href = elmLink.href.replace(/^http:\/\//, 'feed://');

			}

		}

	}


Now when you click a feed link, Firefox will automatically launch your desktop news aggregator and prompt you to subscribe to the feed.


     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows