User:Iceblock/prefixindexonecolumn.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Iceblock/prefixindexonecolumn. |
/*
* 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 [[User:Iceblock]]
*/
function reorganizePrefixIndexTable() {
var listTable = document.getElementById('mw-prefixindex-list-table');
if (!listTable)
var listTable = document.getElementsByClassName('mw-allpages-table-chunk')[0];
if (!listTable)
return;
var tableRows = listTable.children[0].children;
var len = tableRows.length;
for (x = 0; x < len; x++) {
var tableRows = listTable.children[0].children;
var len2 = tableRows[0].children.length;
for (y = 0; y < len2; y++) {
var trNode = document.createElement('tr');
var tdNode = document.createElement('td');
tdNode.innerHTML = tableRows[0].children[y].innerHTML;
trNode.appendChild(tdNode);
listTable.children[0].appendChild(trNode);
}
listTable.children[0].removeChild(tableRows[0]);
}
}
function makeNumberedPrefixIndexTable() {
var listTable = document.getElementById('mw-prefixindex-list-table');
if (!listTable)
var listTable = document.getElementsByClassName('mw-allpages-table-chunk')[0];
if (!listTable)
return;
var tableRows = listTable.children[0].children;
var len = tableRows.length;
if (/\<li\>/i.test(tableRows[0].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[0].appendChild(trNode);
for (x = 0; x < len; x++) {
var tableRows = listTable.children[0].children;
var len2 = tableRows[0].children.length;
for (y = 0; y < len2; y++) {
var liNode = document.createElement('li');
liNode.innerHTML = tableRows[0].children[y].innerHTML;
olNode.appendChild(liNode);
}
listTable.children[0].removeChild(tableRows[0]);
}
}
$ ( 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');
}
} );