// ==UserScript==
// @name        Launchpad Friends
// @author      Kees Cook
// @email       outflux.net | kees
// @version     1.0
// @namespace   http://outflux.net/greasemonkey
// @description Adds links to friends in Launchpad
// @include     https://launchpad.net/~*
// @include     https://*.launchpad.net/~*
// @include     https://launchpad.net/people/*
// @license     GNU General Public License
// ==/UserScript==

(function() {
  window.addEventListener("load", function(e) {

    // tags we will scan
    var allowedParents = [
        "h2"
        ];
    nodes = document.evaluate(
        '//text()[parent::' + allowedParents.join(" or parent::") + ']',
        document,
        null,
        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
        null);
    for (var i = 0; i < nodes.snapshotLength; i++) {
        var node = nodes.snapshotItem(i);
        if (node.nodeValue == 'YOUR FULL NAME HERE') {
            var list = node.parentNode.parentNode;
            var div = document.createElement("div");
            div.setAttribute("class","portlet");
            div.innerHTML = '<h2>Friends</h2>';
            list.parentNode.insertBefore(div,list.nextSibling)

            var friends = document.createElement("div");
            friends.setAttribute("class","portletBody portletContent");
            friends.innerHTML = '<ul>'+
'<li><a href="/~person1">Person 1</a></li>'+
'<li><a href="/~person2">Person 2</a></li>'+
'</ul>';

            div.appendChild(friends);
        }
    }
  }, false);
})();
