Warn Before Buying an Album





Warn Before Buying an Album

Find out whether an album is produced by a record label that supports the RIAA.

There are people in the world who dislike the Recording Industry Association of America (RIAA) because of their simultaneous disregard for both artists' rights (cheating artists with lopsided contracts) and customers' rights (suing fans and treating them like thieves). I am not one of those people, but I still like this hack, because it demonstrates Greasemonkey's role in enabling what I call passive activism.

My theory is that there is a small group of activists who will go out of their way to boycott the RIAA. But there is a much larger group of people who would like to boycott, but they don't actually get around to doing the necessary research when they're about to buy something. This hack helps that larger group, by adding an icon next to an album title on Amazon.com that shows whether this album is produced by a record label that supports the RIAA. It doesn't prevent you from buying the album; it just reminds you that you once cared enough to install a script that would remind you to think about this issue before buying.

The Code

This user script runs on all Amazon.com pages. It parses the URL to get the ASIN—a globally unique identifier that identifies the album you're browsing—and then uses the GM_xmlhttpRequest function to check the Magnetbox (http://www.magnetbox.com) database to determine whether this album is produced by a company that supports the RIAA.

This script sends information about your Amazon.com browsing habits to Magnetbox. You should run this script only if you are comfortable exposing this information.


Save the following user script as riaa-radar.user.js:


		// ==UserScript==

		// @name		RIAA Radar

		// @namespace	http://www.magnetbox.com/riaa/

		// @description Warn before buying albums produced by RIAA-supported labels

		// @include		http://*.amazon.tld/*

		// ==/UserScript==

		

		// based on code by Ben Tesch

		// included here with his gracious permission

		var radar = 'http://www.magnetbox.com/riaa/check.asp?asin=';

		var asin = "";

		var index = location.href.indexOf('/-/');

		if (index != -1) {

			asin = location.href.substring(index + 3, index + 13);

		} else { 

			index = location.href.indexOf('ASIN'); 

			if (index != -1) {

				asin = location.href.substring(index + 5, index + 15);

			} 

		} 

		if (!asin) { return; }

		GM_xmlhttpRequest({method:'GET', url: radar + asin,

			onload:function(results) {

			var status = "unknown";



			if (results.responseText.match('button_warn.gif')) {

				status = "Warning!";

			} else {

				if (results.responseText.match('No album was found.')) {

				status = "Unknown";

				} else {

				status = "Safe!";

				}

			}



			var origTitle = document.evaluate("//b[@class='sans']",

				document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,

				null).singleNodeValue;

			if (!origTitle) { return; }

			var div = origTitle.parentNode;

			var titlechld = origTitle.firstChild;

			var title = titlechld.nodeValue;

			var newTitle = document.createElement('b');

			newTitle.setAttribute('class', 'sans');

			var titleText = document.createTextNode(title);

			newTitle.appendChild(titleText);

			var sp = document.createTextNode(' ');

			var link = document.createElement('a');

			link.setAttribute('title', "RIAA Radar");

			link.setAttribute('href', radar + asin);

			

			var pic = document.createElement('img');

			pic.setAttribute('title', "RIAA Radar: " + status);

			if (status == 'Warning!') {

				pic.src = "http://www.magnetbox.com/riaa/images/button_warn2.gif";

			} else if (status == 'Safe!') {

				pic.src = "http://www.magnetbox.com/riaa/images/button_safe2.gif";

			} else {

				pic.src = "http://www.magnetbox.com/riaa/images/button_caution2.

		gif";

			}

				pic.style.border = "0px";

				link.appendChild(pic);

				

				div.insertBefore(newTitle, origTitle);

				div.insertBefore(sp, origTitle);

				div.insertBefore(link, origTitle);

				div.removeChild(origTitle);

			}});


Running the Hack

After installing the user script (Tools Install This User Script), go to http://www.amazon.com and search for dave matthews stand up. Click through to the album page. At the top of the page, next to the album title, you will see a warning icon, as shown in Figure.

"Warning" icon next to album title


The warning icon indicates that this album was produced by a record label that supports the RIAA. The script does not prevent you from buying the album, it simply informs you of its status.

Now, search Amazon.com for another album—for example, astral projection another world. Click through to the album page and you will see a "safe" icon next to the album title, as shown in Figure.

This album is produced by an independent record label out of Israel that is not a member of the RIAA.

"Safe" icon next to album title



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