User:Bob/script/easywelcome.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 = "green"; ignore[ignore.length] = link.title; var orighref = link.href; var uname = link.title.replace("User talk:", ""); var qstring = "welcome";

var unameProcessed = uname.replace(".", "").replace(".", "").replace(".", ""); if(unameProcessed.length == (uname.length-3)){ qstring = "welcome=anon"; }

link.href = link.href + "&" + qstring; //link.parentNode.innerHTML = link.parentNode.innerHTML.replace(link.href, link.href + "&" + qstring); link.className = ""; link.parentNode.innerHTML = link.parentNode.innerHTML.replace(" | Talk | The Save button has automatically been clicked; please wait while you are redirected.";      if(QueryString.get('welcome') == 'anon') {       welcome('anon');      } else {       welcome('');      }    }  } });

function welcome(type) { // Find the edit box var txt = document.editform.wpTextbox1;

if(txt.value.length == 0) {

//The welcome template you are wanting to use var tag = (type == 'anon') ? '{'+'{subst:User:Bob/welcome|anon=true|heading=true|headtext=Hello from ['+'[User:Bob|]'+']}'+'}' : '{'+'{subst:User:Bob/welcome|heading=true|headtext=Hello from ['+'[User:Bob|]'+']}'+'}';

// Append the tag txt.value += tag;

// Add an edit summary document.editform.wpSummary.value = 'Welcome to Wikipedia!';

// Press the Save page button document.editform.submit; } }

// Create a tab that calls this function when pressed addOnloadHook(function {    if(document.title.indexOf("Editing User talk:") == 0) {        addPortletLink('p-cactions', 'javascript:welcome', 'welcome', 'ca-welcome', 'Adds a welcome note to a new user', , );    } });