User:AuronFtw/wikiswap.js

addOnloadHook(function {       //WikiSwap Functions        function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) {            var node = document.getElementById(portlet);            if ( !node ) return null;            node = node.getElementsByTagName( "ul" )[0];            if ( !node ) return null;            var link = document.createElement( "a" );            link.appendChild( document.createTextNode( text ) );            link.href = href;            var item = document.createElement( "li" );            item.appendChild( link );            if ( id ) item.id = id;            if ( accesskey ) {                link.setAttribute( "accesskey", accesskey );                tooltip += " ["+accesskey+"]";            }            if ( tooltip ) {                link.setAttribute( "title", tooltip );            }            if ( accesskey && tooltip ) {                updateTooltipAccessKeys( new Array( link ) ); }           if ( nextnode && nextnode.parentNode == node ) node.insertBefore( item, nextnode ); else node.appendChild( item ); // IE compatibility (?) return item; }       function addTab(url, name, id, title, key) { return addPortletLink('p-cactions', url, name, id, title, key); }       // WikiSwap function wikiSwap { var url = window.location.href , current , name , names , urls; names = { "gww2": "GW2W", "gww": "GWW", "gwiki": "Cursewiki", "gw": "GWiki", };           urls = { "gww2": "//wiki.guildwars2.com/wiki/", "gww": "//wiki.guildwars.com/wiki/", "gwiki": "//guildwiki.gamepedia.com/", "gw": "//guildwars.wikia.com/wiki/", };           // Find current for (name in urls) { if (url.indexOf(urls[name]) !== -1) { current = name; break; }           }            // Link to others for (name in urls) { if (name === current) { continue; }               addTab(                    url.replace(urls[current], urls[name]),                    names[name],                    "ca-swap-" + name,                    "Switch to " + names[name],                    ""                ); }       }        wikiSwap; });