Usuario:Dodo/monobook.js
Nota: Después de guardar, debes refrescar la caché de tu navegador para ver los cambios. Internet Explorer: mantén presionada Ctrl mientras pulsas Actualizar. Firefox: mientras presionas Mayús pulsas el botón Actualizar, (o presiona Ctrl-Shift-R). Los usuarios de Google Chrome y Safari pueden simplemente pulsar el botón Recargar. Para más detalles e instrucciones acerca de otros exploradores, véase Ayuda:Cómo limpiar la caché.
//<pre><nowiki>
// under heavy development: do NOT use!
function cbRequest(url) {
var r = false;
if (window.XMLHttpRequest && !window.ActiveXObject)
r = new XMLHttpRequest(); // native mode
else if (window.ActiveXObject)
try {
r = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
r = new ActiveXObject('Microsoft.XMLHTTP');
}
if (r && url) {
r.open('GET', url, false);
r.send(null);
}
return r;
}
function cbCatLinkHTML(cat, full) {
//TODO: escape bad characters from cat
return '<SPAN CLASS="CategoryTreeBullet">[<A HREF="javascript:cbOpen(\'' + cat + '\');" TITLE="Navegar por la ' + cat + '">+</A>] </SPAN>' + (full ? '<A HREF="/wiki/' + encodeURIComponent(cat) + '">' + cat + '</A>' : '');
}
function cbAddLinks() {
if (!cbRequest())
return;
var catlinksdiv = document.getElementById('mw-normal-catlinks');
if (catlinksdiv) {
var i = catlinksdiv.firstChild;
while (i) { //TODO: reorder categories
if (i.nodeName == 'SPAN')
i.innerHTML = cbCatLinkHTML(i.firstChild.title.replace(/[^:]+:/, ''), false) + i.innerHTML;
i = i.nextSibling;
}
}
}
function cbCMBlock(cat, subcats, cmc) {
var url = '/w/api.php?action=query&list=categorymembers&format=json&cmprop=ids|title|sortkey&cmlimit=180&cmnamespace=' + (subcats ? '14' : '0|1|2|3|4|5|6|7|8|9|10|11|12|13|15|100|101|102|103|104|105') + (cmc ? '&cmcontinue=' + encodeURIComponent(cmc) : '') + '&cmtitle=Category:' + encodeURIComponent(cat);
var r = cbRequest(url);
if (r)
return eval('(' + r.responseText + ')');
return null;
}
function cbOpen(cat) {
// TODO: Change "button" to avoid reopens
var box = document.getElementById('cb-box');
if (!box) {
box = document.createElement('DIV');
box.id = 'cb-box';
box.style.border = 'solid 1px #a0a0a0';
box.style.padding = '5px';
box.style.marginTop = '5px';
box.style.fontSize = '90%';
var catlinks = document.getElementById('catlinks')
catlinks.parentNode.insertBefore(box, catlinks.nextSibling);
}
// TODO: Better format
box.innerHTML = '<H3><SPAN><IMG SRC="http://up.wiki.x.io/wikipedia/commons/d/d2/Spinning_wheel_throbber.gif" /> Cargando </SPAN>' + cat + '</H3>';
var r = cbRequest('/w/api.php?action=parse&prop=text|categories&format=json&text=' + encodeURIComponent('{{Category:' + cat + '}}'));
if (r) {
var catr = eval('(' + r.responseText + ')');
var pcats = catr['parse']['categories'];
var h = '';
for (var i = 0; i < pcats.length; i++)
h = h + (h.length > 0 ? ' \u2022 ' : ' \u25b2 ') + cbCatLinkHTML(pcats[i]['*'].replace(/_/g, ' '), true);
if (h) {
var div = document.createElement('DIV');
div.innerHTML = h;
box.appendChild(div);
}
var s = catr['parse']['text']['*'];
if (s.length > 0) { // TODO: remove when only contains comments?
var div = document.createElement('DIV');
div.style.borderTop = 'solid 1px #a0a0a0';
div.style.marginTop = '5px';
div.style.marginBottom = '5px';
div.innerHTML = s + '<BR CLEAR="ALL">';
box.appendChild(div);
}
}
var block = cbCMBlock(cat, true, '');
var catm = block['query']['categorymembers'];
if (catm.length > 0) { // TODO: better format, split in blocks
var s = 'Subcategorías:<BR /><UL>';
for (var i = 0; i < catm.length; i++)
s = s + '<LI>' + cbCatLinkHTML(catm[i]['title'].replace(/[^:]+:/, ''), true) + '</LI>';
s = s + '</UL>';
var div = document.createElement('DIV');
div.style.borderTop = 'solid 1px #a0a0a0';
div.innerHTML = s;
box.appendChild(div);
}
var block = cbCMBlock(cat, false, '');
var catm = block['query']['categorymembers'];
if (catm.length > 0) {
var div = null;
var sl = '';
var cc = Math.ceil(catm.length / 3);
while (true) {
var s = '<TD WIDTH="33%"><UL>';
for (var i = 0; i < catm.length; i++) {
var j = catm[i];
var br = ((i % cc) == 0 && i > 0);
if (br) {
s = s + '</UL></TD><TD WIDTH="33%"><UL>';
sl = '';
}
var jl = j['sortkey'].charAt(0);
if (sl != jl) {
sl = jl;
s = s + '</UL><STRONG>' + sl + '</STRONG>' + (br ? ' (cont.)' : '') + '<UL>';
}
s = s + '<LI><A HREF="/wiki/' + encodeURIComponent(j['title']) + '">' + j['title'] + '</A></LI>';
}
s = s + '</UL></TD>';
if (div)
div.innerHTML = div.innerHTML.replace(/<\/TR>/i, s + '</TR>');
else {
div = document.createElement('DIV');
div.style.borderTop = 'solid 1px #a0a0a0';
box.appendChild(div);
div.innerHTML = '<TABLE><TR VALIGN="top">' + s + '</TR></TABLE>';
}
if (block['query-continue']) {
block = cbCMBlock(cat, false, block['query-continue']['categorymembers']['cmcontinue']);
catm = block['query']['categorymembers'];
} else
break;
}
}
box.firstChild.removeChild(box.firstChild.firstChild);
}
// addOnloadHook(cbAddLinks);
//</nowiki></pre>