// ==UserScript==
// @name          LJ User Link Swap
// @namespace     http://hacks.atrus.org/greasemonkey/
// @description   Swaps the LJ user links, so the icon links to the journal and the bold text to their userinfo
// @include       http://*.livejournal.com/*
// ==/UserScript==

// LJ User Link Swap
// 
// Copyright (C) 2005 Nikolas Coukouma
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

(function(){
  var s;
  var j;
  var a1 = null;
  var a2 = null;
  var tmp = "";
  
  // get all span elements
  var resolver = document.createNSResolver( document );
  var spans = document.evaluate( "//span[@class=\"ljuser\"]",
                                 document,
                                 resolver,
                                 XPathResult.ORDERED_NODE_ITERATOR_TYPE,
                                 null );
  // look for lj user links
  try {
    while( s = spans.iterateNext() ) {
      // all lj user links have exactly two children
      if( s.childNodes.length == 2 ) {
          // get the two links
          if( s.childNodes[ 0 ].nodeName == "A" ) {
            a1 = s.childNodes[ 0 ];
          }
          if( s.childNodes[ 1 ].nodeName == "A" ) {
            a2 = s.childNodes[ 1 ];
          }
          // swap the link URLs
          if( a1 && a2 ) {
            tmp = a1.href;
            a1.href = a2.href;
            a2.href = tmp;
          }
      }
    }
  } catch( Exception ) {
    // do nothing .. we expect one
  }
})();