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:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: StopWatch (AFKTime Counter)
What about this? I think it's much more useful to store the time rather than counting the time yourself. :P
I also implemented a workaround for a possible problem: when the AFK message is sent, it'll trigger the OnEvent_ChatWndReceiveMessage event and thus launching an infinite loop of AFK messages! :O
js code:
var bAway = false;
var bOwnMessage = false;
var nCounterTime;

function OnEvent_ChatWndSendMessage( pChatWnd, sMessage ){
    if ( sMessage === '/counter' ) {
        if ( bAway === true ) {
            bAway = false;
        } else {
            bAway = true;
            nCounterTime = new Date().getTime();
        }
        return false;
    }

    bOwnMessage = true;
    MsgPlus.AddTimer( 'OwnMessage', 1000);
}

function OnEvent_ChatWndReceiveMessage( pChatWnd, sMessage, sOrigin, nMessageKind ){
    if ( bOwnMessage ) {
        bOwnMessage = false;
        MsgPlus.CancelTimer( 'OwnMessage' );
        return;
    }
    if( bAway ) {
        pChatWnd.SendMessage( 'I have been away from the computer for: '+parseTime( )+'.' );
    }
}

function OnEvent_Timer( sTimerId ) {
    if( sTimerId === "OwnMessage" ) {
        bOwnMessage = false;
    }
}

function parseTime( ){
    var nSeconds = Math.floor( ( new Date().getTime() - nCounterTime ) / 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';
}

This post was edited on 03-25-2009 at 06:59 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
03-25-2009 06:45 PM
Profile E-Mail PM Web 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