// welcomeNewUsers.js version 1.5 2008-04-20
//
// a Wiki script to add "welcome" links after links to blank talk pages
//
// author: [[b:User:Webaware]]
var welcomeNewUsers = {
win : null,
text_summary : "Welcome message",
text_message : "{{subst\:bigwelcome|\~\~\~\~}}",
flag_minorEdit : true,
flag_watch : false,
// open a new window at the user's talk page, and insert a welcome message
WelcomeUser : function(talkPageLk) {
try {
this.win = window.open(talkPageLk, "_blank");
var fn = new Function('{\n'
+ 'var doc = welcomeNewUsers.win.document;\n'
+ 'doc.getElementById("wpSummary").value = "' + this.text_summary.replace(/\"/g, '\\"') + '";\n'
+ 'doc.getElementById("wpTextbox1").value = "' + this.text_message.replace(/\"/g, '\\"') + '";\n'
+ 'doc.getElementById("wpMinoredit").checked = ' + this.flag_minorEdit + ';\n'
+ 'doc.getElementById("wpWatchthis").checked = ' + this.flag_watch + ';\n'
+ 'welcomeNewUsers.win = null;\n'
+ '}');
if (this.win.addEventListener)
this.win.addEventListener("load", fn, false);
else if (this.win.attachEvent)
this.win.attachEvent("onload", fn);
}
catch (e) {
if (this.win) {
this.win.close();
this.win = null;
}
alert("An error occurred: " + e);
}
},
// installation of object instance
// add a "welcome!" link wherever there is a talk page link for a named user
Install : function() {
var handler = function() { welcomeNewUsers.WelcomeUser(this.href); return false; };
var lks = document.getElementById('bodyContent').getElementsByTagName('a');
for (var i in lks) {
var l = lks[i];
// match only new page links to valid user names, not IP (anon) users, and no sub-pages
if (l.className == 'new' && l.href.match(/User_talk:((?!(\d{1,3}\.){3}\d{1,3}))[^\/]*action=edit/)) {
var newLink = document.createElement("a");
newLink.href = l.href + "§ion=new";
newLink.onclick = handler;
newLink.style.color = 'crimson';
newLink.style.fontWeight = 'bold';
newLink.appendChild(document.createTextNode('welcome!'));
l.parentNode.appendChild(document.createTextNode(' '));
l.parentNode.appendChild(newLink);
}
}
}
};
// hook it into the onload event
$(welcomeNewUsers.Install);