Using Greasemonkey for Forum Friday

I read Declans post on Forum Friday as an addition to Show-and-Tell-Thursday and I think it’s a good idea. There was some discussion about a similar idea (Question Wedneyday) at the blogger BOF. If I’m to respond to posts in the Notes 8 forum (my primary focus) I want a nicer default footer.

I’m already using a Greasemonkey script I blogged about a while back for the LDD6/7 forum. Unfortunately there’s a difference between the HTML markup between the Notes 6/7 forum and the Notes 8 forum so the Greasemonkey script needs to take this into account.

Here’s the updated script (updates in bold):

// ==UserScript==
// @name          Notes/Domino 6/7/8 Forum Signature
// @namespace     https://lekkimworld.com/greasemonkey/ldd_signature
// @description	  Inserts my LDD Forum signature
// @include       http*://www-10.lotus.com/ldd/nd6forum.nsf/*?OpenForm*
// @include       http*://www-10.lotus.com/ldd/nd8forum.nsf/*?OpenForm*
// ==/UserScript==

// get elements
var e_subject = document.getElementById("Subject");
var e_body = document.getElementById("Body");

// handle Notes 8 forum
if (null == e_subject) {
	e_subject = document.forms[0].elements[1];
	e_body = document.forms[0].elements[2];
	e_body.style.fontFamily = "Verdana";
	e_body.style.fontSize = "11px";
}

// compose signature
var signature = "nn/Mikkel HeisterbergnVisit my Notes/Domino blog " +
    "@ http://lekkimworld.comnfor posts on Notes, Domino, Sametime " +
    "and how to use Java in Notes/Domino...";

// set signature
e_body.value = signature;

// set focus
if (e_subject.value == "") {
   e_subject.focus();
} else {
   e_body.focus();
   e_body.setSelectionRange(0, 0);
}

Feel free to copy the script and modify to your liking. Installation guide is in my previous post.

Show ‘n Tell Thursday: Automatically insert signature in the Notes/Domino 6/7 forum (22 June 2006)


The script is really simple. If I’m on a form in edit mode (https://www-10.lotus.com/ldd/nd6forum.nsf/*?OpenForm*) it composes the signature, inserts it in the body field and sets focus to the subject field if it’s empty (a new post) or the body field if it’s a reply. Sweet and simple.

// ==UserScript==
// @name          Notes/Domino 6/7 Forum Signature
// @namespace     https://lekkimworld.com/greasemonkey/ldd6_signature
// @description	  Inserts my LDD6/7 Forum signature
// @include       http*://www-10.lotus.com/ldd/nd6forum.nsf/*?OpenForm*
// ==/UserScript==

var e_subject = document.getElementById("Subject");
var e_body = document.getElementById("Body");

// compose signature
var signature = "nn/Mikkel HeisterbergnVisit my Notes/Domino blog " +
    "@ http://lekkimworld.comnfor posts on Notes/Domino " +
    "and how to use Java in Notes/Domino...";

// set signature
e_body.value = signature;

// set focus
if (e_subject.value == "") {
   e_subject.focus();
} else {
   e_body.focus();
   e_body.setSelectionRange(0, 0);
}

To install in Firefox you need Greasemonkey installed. Copy’n’paste the code above to a text file ending in .user.js and then drag the file onto Firefox to install. The tags at the top of the code determines the URL where the script should run, the name of the script etc.

The caveat is the call to the setSelectionRange() method to move the caret to the start of the Body textarea after setting the focus. Without this method the cursor would be at the end of the body field after the signature.

Feel free to change the script if need be…

Updated on 23 June 2006: Small change to make sure the script kicks in when connecting using HTTPS and HTTP.