AwfulYearbook Username Search

Adds a search link to the "Features" menu of AwfulYearbook.com.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name           AwfulYearbook Username Search
// @description    Adds a search link to the "Features" menu of AwfulYearbook.com.
// @namespace      http://www.mathemaniac.org
// @namespace      http://awfulyearbook.com/user/view/50339
// @include        http://www.awfulyearbook.com/*
// @include        http://awfulyearbook.com/*
// @include        http://forums.somethingawful.com/member.php?action=getinfo&awfulyearbook=1&username=*
// @version 0.0.1.20140827095728
// ==/UserScript==
if ((document.location+"").match(/somethingawful\.com.+awfulyearbook=1/)) {
    var il = document.evaluate('//input[@name="userid"]', document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
    var userId = il.iterateNext().getAttribute('value');
    document.location = 'http://awfulyearbook.com/user/view/'+userId;
} else {
    var il = document.evaluate('//ul[contains(@class,"mainmenu")]/li/a[@href="http://awfulyearbook.com/user/view/random"]', document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
    var randomuser = il.iterateNext().parentNode;
    var features = randomuser.parentNode;
    var searchLi = document.createElement('li');
    var searchLink = document.createElement('a');
    searchLink.href = '#';
    function searchClickHandler(event) {
        var user = prompt("For whom do you wish to search?","");
        if (user) {
            document.location = "http://forums.somethingawful.com/member.php?action=getinfo&awfulyearbook=1&username="+user;
        }
        event.preventDefault();
    }
    searchLink.addEventListener('click',searchClickHandler,true);
    searchLink.appendChild(document.createTextNode('Search'));
    searchLi.appendChild(searchLink);
    searchLi.appendChild(document.createTextNode(' -'));
    features.insertBefore(searchLi,randomuser.nextSibling);
}