User:TheFearow/welcomehelper.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

 importScript("User:TheFearow/simpleajax.js");
 
 addOnloadHook(initNewusers);
 
 function initNewusers(){
  var list = document.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 = "W-screen";
     var page = 1;
     if(wgPageName.indexOf("Recentchanges") != -1){
      page = 2;
     }
     if(wgPageName.indexOf("Newpages") != -1){
      page = 3;
     }
     if(page == 2){
      template = "welcomeg";
     }
     if(page == 3){
      template = "W-shout";
     }
     var unameProcessed = uname.replace(".", "").replace(".", "").replace(".", "");
     if(unameProcessed.length == (uname.length-3)){
      template = "Welcome-anon";
     }
     link.href = "javascript:ajaxwelcome('" + uname + "', 'subst:" + template + "')";
     link.id = "welcomelink-" + uname;
     //link.href = link.href + "&tag=subst:" + template + "&redir=" + escape(document.location.href);
     //link.parentNode.innerHTML = link.parentNode.innerHTML.replace(link.href, link.href+"&tag=subst:" + template);
     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';
 }