// ==UserScript==
// @name          Rdio Explicit Links
// @namespace     http://jeffpalm.com/rdioexplicitlinks/
// @description   Make explicit what links refer to for self titled albums
// @include       http://rdio.com/*
// @include       http://www.rdio.com/*
// ==/UserScript==

(function () {

  function main() {
    setTimeout(realMain,3*1000);
    setInterval(realMain,60*1000);
  }

  function addEventListeners(a,type) {
    var _a = a;
    var text = a.innerHTML;
    var overText = text + ' (The ' + type + ')';
    var outText = text;
    a.addEventListener('mouseover',function(e) {
	_a.innerHTML = overText;
      },true);
    a.addEventListener('mouseout',function(e) {
	_a.innerHTML = outText;
      },true);
  }

  function isPlayerParent(el) {
    var par = el.parentNode;
    return par.id && par.id.match(/^playerNowPlaying/);
  }

  function realMain() {
    var as = document.getElementsByTagName('A');
    for (var i=0; i<as.length; i++) {
      var a = as[i];
      if (a.href.match(/\/album\/[^\/]+\/?$/) && isPlayerParent(a)) {
	addEventListeners(a,'album');
      } else if (a.href.match(/\/artist\/[^\/]+\/?$/) && isPlayerParent(a)) {
	addEventListeners(a,'artist');
      }
    }
  }

  main();

})();
