Jump to content

User:TheFearow/public/newuserlogwelcome.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.
//Config

//What template to welcome with
if(!nulwTemplate){
 var nulwTemplate = "W-screen";
}
//What template to welcome anons with
if(!nulwAnonTemplate){
 var nulwAnonTemplate = "Welcome-anon";
}

// Code - DO NOT MODIFY BELOW HERE

 importScript("User:TheFearow/qstring.js");
 importScript("User:TheFearow/simpleajax.js");

 addOnloadHook(initNewusers);
 
 function initNewusers(){
  if(wgPageName != "Special:Log" || !QueryString.get("type") == "newusers"){
   return;
  }
  var list = document.getElementById('bodyContent').getElementsByTagName("A");
  var ignore = [ ];
  for(i = 0; i < list.length; i++){
   link = list[i];
   if(link == null){
     continue;
   }
   if(ignore.indexOf(link.title) != -1){
    continue;
   }
   if(link.parentNode.innerHTML.indexOf("created new account") != -1){
    continue;
   }
   if(link.className == "new"){
    if(link.title.indexOf("User talk:") != -1){
     link.innerHTML = "<i>Welcome</i>";
     link.style.color = "blue";
     ignore[ignore.length] = link.title;
     var orighref = link.href;
     var uname = link.title.replace("User talk:", "");
     var template = nulwTemplate;
     var unameProcessed = uname.replace(".", "").replace(".", "").replace(".", "");
     if(unameProcessed.length == (uname.length-3)){
      template = nulwAnonTemplate;
     }
     link.href = "javascript:ajaxwelcome('" + uname + "', 'subst:" + template + "')";
     link.id = "welcomelink-" + uname;
     link.className = "";
     link.parentNode.innerHTML = link.parentNode.innerHTML.replace(" | <a", " | <a href=\"" + orighref + "\" class=\"new\" title=\"" + link.title + "\">Talk</a> | <a");
    }
   }
  }
 }

 function ajaxwelcome(username, template){
  simpleAJAXEdit("User talk:"+username, "{"+"{"+template+"}}", "Welcome to Wikipedia!", false, false, "<h3>Welcoming user " + username + "...</h3>", "<h3>User "+username+" welcomed!</h3>" );
  document.getElementById('welcomelink-' + username).style.display = 'none';
 }