WhatIsMyIp Whois Lookup

By David Eason Last update Aug 14, 2007 — Installed 400 times.
// ==UserScript==
// @name          WhatIsMyIp Whois Lookup
// @namespace     http://www.freewebs.com/daddydave
// @description   Makes the ip address on http://www.whatismyip.com a hyperlink to a lookup on http://whois.domaintools.com
// @include       http://www.whatismyip.com/
// @include       http://whatismyip.com/
// @version August 14, 2007
// ==/UserScript==

// DOM scripting shortcuts suggested by Slayer Office web site
function dce(obj) {
    return document.createElement(obj);
}

function dct(str) {
    return document.createTextNode(str);
}

function ac(pNode,cNode) {
    pNode.appendChild(cNode);
}

function sa(obj,attr,val) {
    obj.setAttribute(attr,val);
}

//Get IP address from string
function ipAddress(str) {
    return String(str).match('[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+');
}

function greasePage() {
    var nodeH1;
    nodeH1 = document.evaluate(
        '//table/tbody/tr[2]/td/h1[1]',
        document,
        null,
        XPathResult.ANY_UNORDERED_NODE_TYPE,
        null).singleNodeValue;
    ip = ipAddress(nodeH1.innerHTML);

    var nodeMyH1 = dce('H1');
    
    var nodeYourIPText = dct("Your IP is ");
    var nodeA = dce("a");
    sa(nodeA, "href", 'http://whois.domaintools.com/' + ip);

    var nodeIPText = dct(ip);

    nodeH1.parentNode.replaceChild(nodeMyH1, nodeH1);
    ac(nodeMyH1, nodeYourIPText);
    ac(nodeMyH1, nodeA);
    ac(nodeA, nodeIPText);
}
	
window.addEventListener(
    'load',
    function() { greasePage() },
    true);