mickael9
Full Member
Posts: 117 Reputation: 3
33 / /
Joined: Jul 2005
|
RE: RE: Window Close after Signout
quote: Originally posted by absorbation
I suggest adding a timer to the script. Which the user can customise to what they want, e.g. make the window close after 10 seconds of the contact signing out. I personally would want it 10 minutes after a contact signed out. I often have tabs with tons of offline contacts who I stopped speaking to say, an hour ago .
Adding a timer would make the script a lot better .
Done
code: var Timers = {};
var TimerCount = 0;
function OnEvent_ContactSignout(sEmail)
{
CloseWindows();
}
function OnEvent_ChatWndContactRemoved(ChatWnd, sEmail)
{
CloseWindows();
}
function OnEvent_Timer(sTimerId)
{
if (sTimerId.substr(0, 13) == "AutoCloseWin_")
{
try
{
Interop.Call("User32","SendMessageW", Timers[sTimerId].Wnd.Handle, 16, 0, 0);
}
catch (e){};
delete(Timers[sTimerId]);
TimerCount--;
}
else if (sTimerId.substr(0, 19) == "AutoCloseWinCancel_")
{
var oParams = Timers[sTimerId];
var sOldText = oParams.EditText;
var nOldSelStart = oParams.SelStart;
var nOldSelEnd = oParams.SelEnd;
var Wnd = oParams.Wnd;
Wnd.EditText = sOldText;
Wnd.EditText_SetCurSel(nOldSelStart, nOldSelEnd);
MsgPlus.DisplayToast("","Canceled !");
delete(Timers[sTimerId]);
TimerCount--;
}
}
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage)
{
if (sMessage.substr(0,8) == "!cancel ")
{
var regex = /^!cancel ([0-9]+)/;
var match = regex.exec(sMessage);
if (!match)
return sMessage;
var sId = match[1];
var sTimerId = "AutoCloseWin_" + sId;
if (typeof(Timers[sTimerId]) != "undefined")
{
MsgPlus.CancelTimer(sTimerId);
var Params = Timers[sTimerId];
delete(Timers[sTimerId]);
sTimerId = "AutoCloseWinCancel_" + sId;
Timers[sTimerId] = Params;
MsgPlus.AddTimer(sTimerId, 100);
return '';
}
}
}
function CloseWindows()
{
var chats = Messenger.CurrentChats;
var e = new Enumerator(chats);
for(; !e.atEnd(); e.moveNext())
{
var chat = e.item();
var e2 = new Enumerator(chat.Contacts);
var bCanClose = true;
for (; !e2.atEnd(); e2.moveNext())
{
var contact = e2.item();
bCanClose &= (contact.Status == 1);
}
if (bCanClose)
CloseWindow(chat);
}
}
function CloseWindow(oWnd)
{
var nId = (++TimerCount);
var sTimerId = "AutoCloseWin_" + nId;
var sText = "!cancel " + nId + " [This conversation will be closed in 10 seconds; send this text to cancel and restore the text typed here :)]";
var nSelStart = oWnd.EditText_GetCurSelStart();
var nSelEnd = oWnd.EditText_GetCurSelEnd();
var sOldText = oWnd.EditText;
var Params = {"Wnd" : oWnd, "SelStart" : nSelStart, "SelEnd" : nSelEnd, "EditText" : oWnd.EditText};
oWnd.EditText = sText;
oWnd.EditText_SetCurSel(0, sText.length);
Timers[sTimerId] = Params;
MsgPlus.AddTimer(sTimerId, 10000);
}
Attachment: Auto-close window.plsc (1.83 KB)
This file has been downloaded 120 time(s).
This post was edited on 08-21-2006 at 12:06 AM by mickael9.
|
|