User:TheFearow/welcomehelper.js

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 = "Welcome"; link.style.color = "blue"; ignore[ignore.length] = link.title; var orighref = link.href; var uname = link.title.replace("User talk:", ""); uname = uname.replace(" (page does not exist)", ""); 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 sign = false; var unameProcessed = uname.replace(".", "").replace(".", "").replace(".", ""); if(unameProcessed.length == (uname.length-3)){ template = "Welcome-anon"; sign = true; }    link.href = "javascript:ajaxwelcome('" + uname + "', 'subst:" + template + "', " + sign + ")"; 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(" | Talk | <a"); }  }  } }

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