User:Ilmari Karonen/betterwatchlist.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:Ilmari Karonen/betterwatchlist. |
// Make expandable watchlist entries in "show all applicable changes" mode look more like normal ones
if (wgCanonicalNamespace == "Special" && wgCanonicalSpecialPageName == "Watchlist") {
addOnloadHook(function () {
var i = 0;
var toggleButton;
while (toggleButton = document.getElementById("RCM" + (++i))) {
var mainTable = toggleButton;
while (mainTable && mainTable.tagName.toLowerCase() != "table")
mainTable = mainTable.parentNode;
if (!mainTable) continue;
var mainTD = mainTable.getElementsByTagName("td")[1]; // second column
if (!mainTD) continue;
var subDiv = document.getElementById("RCI" + i);
if (!subDiv) continue;
var subTR = subDiv.getElementsByTagName("tr")[0]; // first row
if (!subTR) continue;
var subTD = subTR.getElementsByTagName("td")[1]; // second column of first row
if (!subTD) continue;
var mainLinks = mainTD.getElementsByTagName("a");
var mainSpans = mainTD.getElementsByTagName("span");
var subLinks = subTD.getElementsByTagName("a");
var subSpans = subTD.getElementsByTagName("span");
if (!mainLinks || !mainSpans || !subLinks || !subSpans) continue;
var totalBytes = mainSpans[0];
var moreEditors = mainSpans[1];
var allChanges = mainLinks[1];
var histLink = mainLinks[2];
var diffLink = subLinks[1];
if (!totalBytes || !moreEditors || !allChanges || !histLink || !diffLink) continue;
// TODO: check classes etc. to be sure we got what we wanted
while (diffLink.nextSibling)
moreEditors.parentNode.insertBefore(diffLink.nextSibling, moreEditors);
moreEditors.parentNode.insertBefore(document.createElement("br"), moreEditors);
moreEditors.parentNode.insertBefore(allChanges, moreEditors);
moreEditors.parentNode.insertBefore(document.createTextNode(" . . "), moreEditors);
moreEditors.parentNode.insertBefore(totalBytes, moreEditors);
moreEditors.parentNode.insertBefore(document.createTextNode(" . . "), moreEditors);
// remove some spacers (should really check that these are what we expect them to be):
histLink.parentNode.removeChild(histLink.nextSibling);
histLink.parentNode.removeChild(histLink.prevSibling);
histLink.parentNode.removeChild(histLink.prevSibling);
histLink.parentNode.insertBefore(diffLink, histlink);
histLink.parentNode.insertBefore(document.createTextNode("; "), histlink);
histLink.innerHTML = "hist";
subTR.parentNode.removeChild(subTR);
}
});
}