/*
* This script adds a tab to Special:Prefixindex and Special:Allpages
* to reformat the list into one column. It also adds a tab to create
* a numbered list.
*
* Made by ]
*/
function reorganizePrefixIndexTable() {
var listTable = document.getElementById('mw-prefixindex-list-table');
if (!listTable)
var listTable = document.getElementsByClassName('mw-allpages-table-chunk');
if (!listTable)
return;
var tableRows = listTable.children.children;
var len = tableRows.length;
for (x = 0; x < len; x++) {
var tableRows = listTable.children.children;
var len2 = tableRows.children.length;
for (y = 0; y < len2; y++) {
var trNode = document.createElement('tr');
var tdNode = document.createElement('td');
tdNode.innerHTML = tableRows.children.innerHTML;
trNode.appendChild(tdNode);
listTable.children.appendChild(trNode);
}
listTable.children.removeChild(tableRows);
}
}
function makeNumberedPrefixIndexTable() {
var listTable = document.getElementById('mw-prefixindex-list-table');
if (!listTable)
var listTable = document.getElementsByClassName('mw-allpages-table-chunk');
if (!listTable)
return;
var tableRows = listTable.children.children;
var len = tableRows.length;
if (/\<li\>/i.test(tableRows.innerHTML))
return;
var trNode = document.createElement('tr');
var tdNode = document.createElement('td');
var olNode = document.createElement('ol');
tdNode.appendChild(olNode);
trNode.appendChild(tdNode);
listTable.children.appendChild(trNode);
for (x = 0; x < len; x++) {
var tableRows = listTable.children.children;
var len2 = tableRows.children.length;
for (y = 0; y < len2; y++) {
var liNode = document.createElement('li');
liNode.innerHTML = tableRows.children.innerHTML;
olNode.appendChild(liNode);
}
listTable.children.removeChild(tableRows);
}
}
$ ( function () {
if (wgCanonicalSpecialPageName == 'Prefixindex' || wgCanonicalSpecialPageName == 'Allpages') {
mw.util.addPortletLink('p-cactions', 'javascript:reorganizePrefixIndexTable();', '1 column', null, 'Change the results list into one column');
mw.util.addPortletLink('p-cactions', 'javascript:makeNumberedPrefixIndexTable();', 'Numbered list', null, 'Change the results list into a numbered list');
}
} );