User:Jon Harald Søby/monobook.js

// Some code 'stolen' from Hippietrail's .js - thanks for the help with the implementation, by the way ;)

// add css and javascript links to personal toolbar function addTools { var myprefs = document.getElementById('pt-preferences'); var newpt; var newa;

var username = document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML;

}

// add "favourites" to navigation box function addToNav { var pagetitle = document.getElementById('p-cactions').getElementsByTagName('ul').item(0).getElementsByTagName('li').item(0).firstChild.href;

// reading mode if (pagetitle.search(/\/wiki\//) != -1) { pagetitle = pagetitle.replace(/^.*\/wiki\/(.*)/, "$1") // edit mode } else if (pagetitle.search(/\/w\//) != -1) { pagetitle = pagetitle.replace(/^.*\/w\/index\.php\?title=(.*)\&action\=edit$/, "$1"); }

pagetitle = pagetitle.replace(/_/g, ' '); var lastnav = document.getElementById('n-sitesupport'); var newnav; var newa;

newnav = document.createElement('li'); newa = document.createElement('a'); newa.href='/wiki/Wikipedia:Tinget'; newa.appendChild(document.createTextNode('Tinget')); newnav.appendChild(newa); lastnav.parentNode.appendChild(newnav);

newnav = document.createElement('li'); newa = document.createElement('a'); newa.href='http://commons.wikimedia.org/wiki/'+escape(pagetitle) ; newa.appendChild(document.createTextNode('Dette bildet på Commons')); newnav.appendChild(newa); lastnav.parentNode.appendChild(newnav);

}

// get name of article var pagetitle = document.getElementById('p-cactions').getElementsByTagName('ul').item(0).getElementsByTagName('li').item(0).firstChild.href;

// http://en.wiktionary.org/wiki/underpaid if (pagetitle.search(/\/wiki\//) != -1) { pagetitle = pagetitle.replace(/^.*\/wiki\/(.*)/, "$1") // http://en.wiktionary.org/w/index.php?title=amado&action=edit } else if (pagetitle.search(/\/w\//) != -1) { pagetitle = pagetitle.replace(/^.*\/w\/index\.php\?title=(.*)\&action\=edit$/, "$1"); }

pagetitle = pagetitle.replace(/_/g, ' ');

// find the spot and add our new tab var talktabli = document.getElementById('ca-talk');

if (!talktabli) { currentpagetype = 'special'; } else { pagetitle = pagetitle.replace(/^Editing (.*?)( \(section\))?$/, "$1");

if (pagetitle.search(/\/Citations$/) != -1) { currentpagetype = 'cite'; } else if (pagetitle.search(/^Talk:/) != -1) { currentpagetype = 'talk'; } else if (pagetitle.search(/[:\/]/) != -1) { currentpagetype = 'other'; } else { currentpagetype = 'article'; } }  //hack_pagetitle = 'Title: ' + pagetitle; //hack = 'Type: ' + currentpagetype;

if (currentpagetype == 'article' || currentpagetype == 'talk' || currentpagetype == 'cite') {

var lookfor;

// look for link to cite page so we know if it's red or blue if (currentpagetype == 'article') { lookfor = pagetitle + '/Citations'; } else if (currentpagetype == 'cite') { lookfor = pagetitle.replace(/^(.*)\/Citations$/, "$1"); }

if (currentpagetype == 'article' || currentpagetype == 'cite') { var allas = document.getElementById('bodyContent').getElementsByTagName('a'); //hack = 'lookfor: ' + lookfor;

if (allas != -1) { for (var i = 0; i < allas.length; i++) { if (allas[i].title == lookfor) { foundclass = allas[i].className; break; }       }      }    }

// create the cite tab var citetabli = document.createElement('li'); citetabli.id = 'ca-cite';

var citetablink = document.createElement('a');

if (currentpagetype == 'article') { // citation page definitely doesn't exist if (foundclass == 'new') { citetablink.href = '/w/index.php?title=' + pagetitle + '/Citations&action=edit'; citetabli.className = 'new'; // citation page definitely exists } else if (foundclass == '') { citetablink.href = '/wiki/' + pagetitle + '/Citations'; // impossible to tell whether citation page exists } else { citetablink.href = '/wiki/' + pagetitle + '/Citations'; citetabli.className = 'dunno'; }

citetablink.appendChild(document.createTextNode('citations')); citetabli.appendChild(citetablink);

} else if (currentpagetype == 'cite') { // fix up the article tab // citation page definitely doesn't exist if (foundclass == 'new') { talktabli.previousSibling.firstChild.href = pagetitle.replace(/^(.*)\/Citations$/, "/w/index.php?title=$1&action=edit"); talktabli.previousSibling.className = 'new'; // citation page definitely exists } else if (foundclass == '') { talktabli.previousSibling.firstChild.href = pagetitle.replace(/^(.*)\/Citations$/, "\/wiki\/$1"); talktabli.previousSibling.className = ''; // impossible to tell whether citation page exists } else { citetablink.href = '/wiki/' + pagetitle + '/Citations'; talktabli.previousSibling.firstChild.href = pagetitle.replace(/^(.*)\/Citations$/, "\/wiki\/$1"); talktabli.previousSibling.className = 'dunno'; }

// fix up the talk tab talktabli.firstChild.href = pagetitle.replace(/^(.*)\/Citations$/, "\/wiki\/Talk:$1"); talktabli.className = 'dunno';

// build the cite tab var citetablink = document.createElement('a'); citetablink.href = pagetitle.replace(/^(.*)$/, "\/wiki\/$1");

citetablink.appendChild(document.createTextNode('citations')); citetabli.appendChild(citetablink); citetabli.className = 'selected';

} else if (currentpagetype == 'talk') { // build the cite tab var citetablink = document.createElement('a'); citetablink.href = pagetitle.replace(/^Talk:(.*)$/, "\/wiki\/$1\/Citations");

citetablink.appendChild(document.createTextNode('citations')); citetabli.appendChild(citetablink); citetabli.className = 'dunno'; }

// add the cite tab talktabli.parentNode.insertBefore(citetabli, talktabli.nextSibling); } }

function reformatMyPage { addTools; addCiteTab; addToNav; }

var hack = 'failed'; var hack_articletitle ='';

if (window.addEventListener) window.addEventListener("load",reformatMyPage,false); else if (window.attachEvent) window.attachEvent("onload",reformatMyPage);