What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » StopWatch (AFKTime Counter)

StopWatch (AFKTime Counter)
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: StopWatch (AFKTime Counter)
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';
}
03-25-2009 07:05 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
StopWatch (AFKTime Counter) - by NorteX on 03-25-2009 at 04:49 PM
RE: StopWatch (AFKTime Counter) - by matty on 03-25-2009 at 06:15 PM
RE: StopWatch (AFKTime Counter) - by Matti on 03-25-2009 at 06:45 PM
RE: StopWatch (AFKTime Counter) - by matty on 03-25-2009 at 06:50 PM
RE: StopWatch (AFKTime Counter) - by NorteX on 03-25-2009 at 06:54 PM
RE: StopWatch (AFKTime Counter) - by Matti on 03-25-2009 at 07:00 PM
RE: StopWatch (AFKTime Counter) - by NorteX on 03-25-2009 at 07:01 PM
RE: StopWatch (AFKTime Counter) - by Matti on 03-25-2009 at 07:04 PM
RE: StopWatch (AFKTime Counter) - by matty on 03-25-2009 at 07:05 PM
RE: StopWatch (AFKTime Counter) - by NorteX on 03-25-2009 at 07:21 PM
RE: StopWatch (AFKTime Counter) - by matty on 03-25-2009 at 07:52 PM
RE: StopWatch (AFKTime Counter) - by NorteX on 03-25-2009 at 08:05 PM
RE: StopWatch (AFKTime Counter) - by NorteX on 03-25-2009 at 11:52 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On