// ==UserScript==
// @name                Forum user links
// @version             1.0
// @date                2008-11-09
// @author              Ian Malpass ( ian AT etsyhacks DOT com )
// @namespace           etsy.com
// @description         For each post in a fourm, adds links to the poster's profle, convos you've had with them, and a link to start a new convo
// @include             http://www.etsy.com/forums_thread.php?*
// ==/UserScript==

/*
This script adds some extra links to each forum post, to speed up replying off-forum
*/

// Build a couple of regexps that we're going to need
var isForumLink = /post-\d+/;
var extractUserId = /user_id=(\d+)/;

// Each forum post has an anchor tag, which happens to be in the table 
// cell we want to decorate. So, we go through all the anchors finding
// ones that are forum post identifiers.
var anchors = document.getElementsByTagName( 'a' );
for ( var a = 0; a < anchors.length; a++ ) {
    var anchor = anchors[ a ];
    if ( ! anchor.name || ! isForumLink.exec( anchor.name ) ) continue;
    // Get the user ID and name from the shop link
    var match = extractUserId.exec( anchors[ a + 2 ].href );
    var userId = match[ 1 ];
    var userName = anchors[ a + 2 ].innerHTML;
    // Build the HTML
    var html = '<div style="margin-top: 5px"><a style="color: #0192B5 !important" href="/profile.php?user_id=' + userId + '">' + userName + '\'s profile</a> | ';
    html += '<a style="color: #0192B5 !important" href="/add_favorite_shop.php?user_id=' + userId + '">add to favorites</a> | ';
    html += '<a style="color: #0192B5 !important" href="/convo_new.php?to_username=' + userName + '">send convo</a> | ';
    html += '<a style="color: #0192B5 !important" href="/convo_drop_search.php?drop_user_name=' + userName + '&drop_tag=&submit=Go">list convos</a></div>';
    // Add it to the parent cell and move on
    anchors[ a + 3 ].parentNode.innerHTML += html;
    a += 2;
}    

