Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//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;
}