Jump to content

User:Xrblsnggt/monobook.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.
function customiseMyPage() {
  runReplace();
}

if (window.addEventListener) window.addEventListener("load",customiseMyPage,false);
  else if (window.attachEvent) window.attachEvent("onload",customiseMyPage);



function runReplace()
{
    // NAMES
    var t1="REPLACEME";
    var t2="AFD_UTC_LOG_DATE";

    // VALUES
    var v1="REPLACED";
    //YYYY_Month_DD
    var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    var myDate=new Date()
    var v2="" + myDate.getUTCFullYear() + "_" + monthname[myDate.getUTCMonth()] + "_" + myDate.getUTCDate(); 

    // REPLACEMENT
    var replaceText = document.body.innerHTML;
    replaceText=doReplace(replaceText,t1,v1);
    replaceText=doReplace(replaceText,t2,v2);
    // ...
    document.body.innerHTML = replaceText;
}



function doReplace(bodyText, searchTerm, replaceTerm) 
{
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      // skip anything inside a <textarea> block
      if (lcBodyText.lastIndexOf("/textarea>", i) >= lcBodyText.lastIndexOf("<textarea", i)) {
        newText += bodyText.substring(0, i) + replaceTerm;
        bodyText = bodyText.substr(i + searchTerm.length);
        lcBodyText = bodyText.toLowerCase();
        i = -1;
      }
    }
  }
  
  return newText;
}