User:Agent007bond/common.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. |
The accompanying .css page for this skin can be added at User:Agent007bond/common.css. |
//Contribution list items
var lilist = document.getElementById("bodyContent");
var lilistitems = lilist.getElementsByTagName("li");
//Toggle link text
var commonText1 = " | <a href=\"#\" onclick=\"";
var commonText2 = "\">Show ";
var commonText3 = " contributions</a>";
var filterLCtext = commonText1 + "filterLatestContrib();" + commonText2 + "latest" + commonText3;
var showAllText = commonText1 + "showAllContrib();" + commonText2 + "all" + commonText3;
if (mw.config.get('wgCanonicalSpecialPageName') == "Contributions") {
//Show the toggle link
document.getElementById("coordinates").innerHTML
+= "<span id=\"filterLatestContribLink\" style=\"color: gray;\">"
+ filterLCtext
+ "</span>";
//Get the target user name
var targetUserName = document.getElementsByName("target")[0].value;
//Compare target user name with logged in user name
var toggleLinkText = "";
if (targetUserName == mw.config.get('wgUserName')) {
filterLatestContrib();
}
}
function filterLatestContrib() {
var pagesAlreadySeen = new Array();
//Look for and hide older contributions
for (var i = 0; i < lilistitems.length; i++) {
var alist = lilistitems[i].getElementsByTagName("a");
if (alist.length >= 1) {
if (pagesAlreadySeen.indexOf(alist[0].title) == -1) {
pagesAlreadySeen.push(alist[0].title);
} else {
lilistitems[i].style.display = "none";
}
}
}
//Change toggle link text
document.getElementById("filterLatestContribLink").innerHTML = showAllText;
}
function showAllContrib() {
//Look for and show hidden contributions
for (var i = 0; i < lilistitems.length; i++) {
if (lilistitems[i].style.display == "none") {
lilistitems[i].style.display = "";
}
}
//Change toggle link text
document.getElementById("filterLatestContribLink").innerHTML = filterLCtext;
}