User:Kernigh/wikialink.js

//

/* * Monobook interwiki tab script * by Kernigh - public domain * * derived from Splarka's script * http://en.wikipedia.org/wiki/User:Splarka/wikialink.js * * The purpose of this script is to add a link to a wiki page * of the same name at another wiki. * * Usage: Before calling, define * function wikiabuttons { *  addwb( "action", "gameinfo", "gameinfo.wikia.com/wiki/", "" ); *  addwb( AT, LABEL, TO, KEY ); *  ... * } * * AT: "action", "navigation", "personal", "toolbox" * LABEL: the label of the link * TO: URL between "http://" and page name * KEY: access key, leave empty or use 1234567890bg`';-[] */

function addwb(btype, wlabel, wlink, wkey) { if((btype == "personal")||(btype == "1")) { var ab = document.getElementById('p-personal').getElementsByTagName('ul')[0]; } else if((btype == "navigation")||(btype == "3")) { var ab = document.getElementById('p-navigation').getElementsByTagName('ul')[0]; } else if((btype == "toolbox")||(btype == "4")) { var ab = document.getElementById('p-tb').getElementsByTagName('ul')[0]; } else { var ab = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; }   pt = extractTitle; if(pt) { ta['t-ex' + wlabel] = [wkey, 'http://'+ wlink + pt, wlabel ]; addlilink(ab, 'http://'+ wlink + pt, wlabel, 't-ex' + wlabel); } }

function addlilink(tabs, url, name, id, title, key){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); tabs.appendChild(li); if(id) {       if(key && title) {           ta[id] = [key, title]; }       else if(key) {           ta[id] = [key, '']; }       else if(title) {           ta[id] = ['', title]; }   }    // re-render the title and accesskeys from existing code in wikibits.js    akeytt; return li; }

// extract page title from url of toolbox "What links here" function extractTitle { var listItem = document.getElementById( "t-whatlinkshere" );

if( ! listItem ) return false; if( ! listItem.firstChild ) return false; if( ! listItem.firstChild.getAttribute ) return false;

var url = listItem.firstChild.getAttribute( "href" ); if( ! url ) return false;

url += "&"; var index= url.indexOf( "?target=" ); if( index < 0 ) index = url.indexOf( "&target=" ); if( index < 0 ) return false;

index += 8; // advance to start return( url.substring( index, url.indexOf( "&", index + 1 ) ) ); }

addOnloadHook(wikiabuttons);

//