User:.anaconda/monobook.js
From Wikipedia, a free encyclopedia written in simple English for easy reading.
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror:: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences.
// <pre><nowiki>
// Cosa:
// * aggiunge tab "ultima modifica" e "purge" nelle pagine
// * aggiunge tab "0" nelle pagine per modificare la sezione 0
// * aggiunge link "rimuovi" nella watch list
// * aggiunge un link al log dei blocchi nel menù "strumenti"
// Based on [[it:Utente:Helios89/monobook.js]]
// Licensed under the GFDL+GPL.
// Initialize on window load
if (window.addEventListener)
window.addEventListener("load", myLoadFuncs,false);
else if (window.attachEvent)
window.attachEvent("onload", myLoadFuncs);
else
{
window.previousLoadFunction = window.onload;
window.onload = function()
{
window.previousLoadFunction();
myLoadFuncs();
}
}
// Load custom functions
function myLoadFuncs()
{
// tab "0" nelle pagine
addEditSection0();
// link "rimuovi" nella watch list
AddUnwatch();
// aggiunge link al menù "strumenti"
AddToolboxLinks();
akeytt();
}
function addEditSection0()
{
ta['ca-edit-0'] = ['0', 'Modifica la sezione 0'];
if (!document.getElementById)
return;
var x = document.getElementById('ca-edit');
if (!x)
return;
var y = document.createElement('li');
y.id = 'ca-edit-0';
if (x.className == 'selected')
{
if (/&action=edit§ion=0$/.test(window.location.href))
{
x.className = 'istalk';
y.className = 'selected';
} else {
x.className = 'selected istalk';
}
} else if (x.className == 'selected istalk') {
if (/&action=edit§ion=0$/.test(window.location.href)) {
x.className = 'istalk';
y.className = 'selected istalk';
} else {
y.className = 'istalk';
}
} else {
y.className = x.className;
x.className = 'istalk';
}
var z = document.createElement('a');
if (x.children)
{
z.href = x.children[0].href + '§ion=0';
z.appendChild(document.createTextNode('0'));
y.appendChild(z);
document.getElementById('p-cactions').children[1].insertBefore(y, x.nextSibling);
} else {
z.href = x.childNodes[0].href + '§ion=0';
z.appendChild(document.createTextNode('0'));
y.appendChild(z);
document.getElementById('p-cactions').childNodes[3].insertBefore(y, x.nextSibling);
}
}
if (document.createElement && window.addEventListener)
{
function SoFixItInit() // pre-load, (don't want to slow down loading of article's content, though)
{
}
function SoFixItLoad() // post-load
{
PageMenu = new PortletMenu('p-cactions');
function GetByClass(sElem, sClass)
{
var i, a2 = [], a = document.getElementsByTagName(sElem);
for (i = 0; i < a.length; i++)
if (a[i].className == sClass)
a2.push(a[i]);
return a2;
}
var a, td = GetByClass('td', 'diff-otitle');
if ((td = td[0]) && (a = td.getElementsByTagName('a')[0]))
a.href = a.href + '&action=edit'; // need to change text, later
// Article's tabs
if (PageMenu['ca-history']) // If there's no history, then there's no last diff...
{
// tab "ultima modifica"
PageMenu.insertBefore('ca-move', 'ca-lastdiff', 'last diff', PageMenu.getHref('ca-history').replace(/action=history/, 'redirect=no&diff=0'));
// tab "purge"
PageMenu.append('ca-purge', 'purge', PageMenu.getHref('ca-history').replace(/action=history/, 'action=purge'));
}
}
function PortletMenu(id)
{
this.menu = document.getElementById(id);
this.list = this.menu.getElementsByTagName('ul')[0]; // bypass "<h5>Views</h5>", etc.
// sigh...as far as I can figure, there is empty whitespace being treated
// as TextNodes....
var LIs = this.list.getElementsByTagName('li');
for (var i = 0; i < LIs.length; i++)
{
this[LIs[i].id] = LIs[i];
}
this.newItem = function(id, txt, url)
{
var li = document.createElement('li');
li.id = id;
var a = document.createElement('a');
a.href = url;
a.appendChild(document.createTextNode(txt));
li.appendChild(a);
this[id] = li; // watch this!!!
return li;
}
this.append = function(id, txt, url)
{
this.list.appendChild(this.newItem(id, txt, url));
}
this.insertBefore = function(old, id, txt, url)
{
this.list.insertBefore(this.newItem(id, txt, url), this[old]);
}
// the ByTagName here is a bit annoying, but in Safari, I was picking
// up TextNodes by using this[id].firstChild.firstChild
this.getText = function(id) { return this[id].getElementsByTagName('a')[0].firstChild.data }
this.setText = function(id, txt) { this[id].getElementsByTagName('a')[0].firstChild.data = txt }
this.getHref = function(id) { return this[id].getElementsByTagName('a')[0].href }
this.setHref = function(id, url) { this[id].getElementsByTagName('a')[0].href = url }
}
SoFixItInit();
window.addEventListener('load', SoFixItLoad, false);
}
function AddToolboxLinks()
{
var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
addlilink(tb, '/wiki/Special:Log/block', 'Blocks log', 't-blocks');
}
function addlilink(tabs, url, name, id)
{
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
li.id = id;
li.appendChild(na);
tabs.appendChild(li);
return li;
}
// Aggiunge link "rimuovi" nella watch list
function AddUnwatch()
{
if (window.location.href.indexOf("Special:Watchlist") == -1)
return;
var links = document.getElementById('content').getElementsByTagName('a');
for (var i = 0; i < links.length; i++)
{
if (links[i].href.substring(links[i].href.length-15) != '&action=history')
continue;
var unwatch = document.createElement('a');
unwatch.href = "/w/index.php?title=Special:Watchlist&action=submit&remove=1&id[]=" + encodeURIComponent(links[i].title);
unwatch.title = "unwatch";
unwatch.appendChild(document.createTextNode("remove"));
links[i].parentNode.insertBefore(unwatch, links[i].nextSibling);
// workaround per testo "diff" senza link
var delim = links[i].previousSibling;
delim = (delim.nodeType == 3 ? delim.nodeValue : "");
links[i].parentNode.insertBefore(document.createTextNode(delim.replace(/^.*diff/, "")), unwatch);
}
}
// </nowiki></pre>

