User:Nick1nildram/monobook.js
Jump to navigation
Jump to search
Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- This script lacks a documentation subpage. You may create it.
- Useful links: root page • root page’s subpages • links • redirects • your own
This JavaScript is executed for Nick1nildram on every page load, when User:Nick1nildram is using the Monobook skin.
// 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').item(0).firstChild.nodeValue;
newpt = document.createElement('li');
newa = document.createElement('a');
newa.href='/w/index.php?title=User:' + username + '/monobook.css&action=edit';
newa.appendChild(document.createTextNode('css'));
newpt.appendChild(newa);
myprefs.parentNode.insertBefore(newpt, myprefs);
newpt = document.createElement('li');
newa = document.createElement('a');
newa.href='/w/index.php?title=User:' + username + '/monobook.js&action=edit';
newa.appendChild(document.createTextNode('js'));
newpt.appendChild(newa);
myprefs.parentNode.insertBefore(newpt, myprefs);
}
// add "favourites" to navigation box
function addToNav() {
var lastnav = document.getElementById('n-sitesupport');
var newnav;
var newa;
newnav = document.createElement('li');
newa = document.createElement('a');
newa.href='/wiki/Wiktionary:Beer parlour';
newa.appendChild(document.createTextNode('Beer parlour'));
newnav.appendChild(newa);
lastnav.parentNode.appendChild(newnav);
newnav = document.createElement('li');
newa = document.createElement('a');
newa.href='/wiki/Wiktionary:Requested_articles';
newa.appendChild(document.createTextNode('Requests'));
newnav.appendChild(newa);
newnav.appendChild(document.createTextNode(' '));
newa = document.createElement('a');
newa.href='/wiki/Category:Requested_articles';
newa.appendChild(document.createTextNode('(cat)'));
newnav.appendChild(newa);
lastnav.parentNode.appendChild(newnav);
newnav = document.createElement('li');
newa = document.createElement('a');
newa.href='/wiki/Category:English words spelled with diacritics or ligatures';
newa.appendChild(document.createTextNode('Diacritics & ligatures'));
newnav.appendChild(newa);
lastnav.parentNode.appendChild(newnav);
newnav = document.createElement('li');
newa = document.createElement('a');
newa.href='/wiki/Category:English eponyms';
newa.appendChild(document.createTextNode('Eponyms'));
newnav.appendChild(newa);
lastnav.parentNode.appendChild(newnav);
newnav = document.createElement('li');
newa = document.createElement('a');
newa.href='/wiki/User:Hippietrail/Template/Pronunciation_section';
newa.appendChild(document.createTextNode('Pronunciation'));
newnav.appendChild(newa);
lastnav.parentNode.appendChild(newnav);
newnav = document.createElement('li');
newa = document.createElement('a');
newa.href='http://www.collins.co.uk/wordexchange/';
newa.className = 'external text';
newa.appendChild(document.createTextNode('Collins'));
newnav.appendChild(newa);
lastnav.parentNode.appendChild(newnav);
newnav = document.createElement('li');
newa = document.createElement('a');
newa.href='http://encarta.msn.com/encnet/features/dictionary/dictionaryhome.aspx';
newa.className = 'external text';
newa.appendChild(document.createTextNode('Encarta'));
newnav.appendChild(newa);
lastnav.parentNode.appendChild(newnav);
newnav = document.createElement('li');
newa = document.createElement('a');
newa.href='http://buscon.rae.es/diccionario/drae.htm';
newa.className = 'external text';
newa.appendChild(document.createTextNode('Real Academia'));
newnav.appendChild(newa);
lastnav.parentNode.appendChild(newnav);
//newnav = document.createElement('li');
//newnav.appendChild(document.createTextNode(hack_pagetitle));
//lastnav.parentNode.appendChild(newnav);
//newnav = document.createElement('li');
//newnav.appendChild(document.createTextNode(hack));
//lastnav.parentNode.appendChild(newnav);
}
// add citations tab
function addCiteTab() {
var currentpagetype = 'dunno';
var foundclass;
// 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);
}
}
// reparent the templates used list so it's in a div with an id for css to use
// the offending elements are a br, text, and ul at offset +5,6,7 from the closest
// previous id, which will be wpDiff or wpPreview
function reparentTemplateList() {
if (document.getElementById('editpage-copywarn')) {
var closestid = document.getElementById('wpDiff');
if (!closestid) {
closestid = document.getElementById('wpPreview');
}
var br = closestid.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling;
var txt = br.nextSibling;
var ul = txt.nextSibling;
//hack = 'br=' + br.tagName + ', txt=' + txt.tagName + ', ul=' +ul.tagName;
// is there a template list section?
if (br.tagName == 'BR' && txt.nodeType == 3 && ul.tagName == 'UL') {
var span = document.createElement('span');
span.id = 'templates-used';
// can we use surroundContents?
if (document.getElementById && document.createRange) {
//hack = '(firefox) ' + hack;
var range = document.createRange();
range.setStartBefore(br, 0);
range.setEndBefore(document.getElementById('editpage-copywarn'));
range.surroundContents(span);
// no surroundContents - do it manually
} else {
var form = document.getElementById('editform');
//hack = '(msie) ' + hack;
span.appendChild(br.cloneNode(false));
span.appendChild(txt.cloneNode(false));
span.appendChild(ul.cloneNode(true));
form.removeChild(br);
form.removeChild(txt);
ul.replaceNode(span);
}
}
}
}
function customiseMyPage() {
reparentTemplateList();
addTools();
addCiteTab();
addToNav();
}
var is_macmsie = false;
//var hack = 'nothing special';
//var hack_pagetitle ='';
// none of this seems to work on Mac Internet Explorer 5
if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("Mac") != -1) is_macmsie = true;
if (is_macmsie != true) {
if (window.addEventListener) window.addEventListener("load",customiseMyPage,false);
else if (window.attachEvent) window.attachEvent("onload",customiseMyPage);
}