Jump to content

User:Lupin/fixnew.js

From Wikipedia, the free encyclopedia
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.
var fixnewVersion="Tue Sep 13 23:26:16 EDT 2005";

contribsBase='http://en.wikipedia.org/w/index.php?title=Special:Contributions&target='

var ipUserRegex=RegExp('(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]))');

function fixupIpText () {
  var textNodes=getTextNodes();
  for (var i = 0; i < textNodes.length; i++) {
    var textNode=textNodes[i];
    var t=textNode.nodeValue;
    var m=ipUserRegex.exec(t);
    if (m) {
      var ip=m[1]; var s=t.split(ipUserRegex);  var n=s[0];
      var a=document.createElement('A');  a.href= contribsBase + ip;
      a.appendChild(document.createTextNode(ip));
      var newTextNode=document.createTextNode(s[5]);
      var element=textNode.parentNode;
      element.replaceChild(newTextNode, textNode);
      element.insertBefore(a,newTextNode);
      element.insertBefore(document.createTextNode(s[0]),a);
    }
  }
};

function getTextNodes(element) {
  var ret=[];
  if (!element)
    element = document.body;
  for (var c = 0; c < element.childNodes.length; c++) {
    if (element.childNodes[c].nodeType == 3) {
      ret.push(element.childNodes[c]);
    }
    else ret=ret.concat(getTextNodes(element.childNodes[c]));
  }
  return ret;
};