I have been writing a userscript for the past few months, for my company, and have just designed the main site for it with installation instructions (our employees are based
You can use this great javascript library: http://www.visitorjs.com/details It is open-sourced recently
Edit: Actually, it is now renamed to session.js http://github.com/codejoust/session.js and to my knowledge, that is the best you can get.