At this point your code becomes a bit more difficult.
js code:
var bAway = false;
var dtTime;
var oChatWnd = {};
function OnEvent_ChatWndDestroyed ( pChatWnd ){
delete oChatWnd[ pChatWnd.Handle ];
}
function OnEvent_ChatWndSendMessage( pChatWnd, sMessage ){
oChatWnd[ pChatWnd.Handle ] = sMessage
if ( sMessage === '/counter' ) {
if ( bAway === true ) {
bAway = false;
} else {
bAway = true;
dtTime = new Date().getTime();
}
return false;
}
}
function OnEvent_ChatWndReceiveMessage( pChatWnd, sOrigin, sMessage, nMessageKind ){
if ( oChatWnd[ pChatWnd.Handle] !== sMessage && bAway === true ) {
pChatWnd.SendMessage( 'I have been away from the computer for: '+parseTime( )+'.' );
}
}
function parseTime( ){
var nSeconds = Math.floor( ( new Date().getTime() - dtTime ) / 1000 );
var s = nSeconds % 1000;
var m = Math.floor( nSeconds / 60 ) % 60;
var h = Math.floor( nSeconds / (60 * 60) );
return h+'hours, '+m+'minutes and '+s+' seconds';
}