Jump to content

User:TheFearow/welcomehelper.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.
 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:", "");
     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(" | <a", " | <a href=\"" + orighref + "\" class=\"new\" title=\"" + link.title + "\">Talk</a> | <a");
    }
   }
  }
 }

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