AwfulYearbook Username Search

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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);
}