Jimbo
Veteran Member
Posts: 1650 Reputation: 18
32 / /
Joined: Jul 2006
|
RE: [suggestion]Appear online when offline
SLM coded me something a while back, that automatically signs you off WLM after a certain amount of time.
code: /* This is a bastardized version *\
| of Shondoit\'s "TimeZone" script |
\* edited by SpunkyLoveMuff */
/////////////////////// EDIT THESE ONLY \\\\\\\\\\\\\\\\\\\\\\\
var Banned = "your email" //### The email to signout ###
var Remaining = 20; // Time the user has before signout (Minutes)
////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
var Minute = 60000; // One Minute
var Second = 1000 // One Second
var ChatWnds = new Array()
var ChildWnds = new Array()
var S = new Object()
S.AlwaysShowTimer = true
S.FixOffset = true
S.FixTabs = true
S.Mask = "h:mm a"
S.Width = 57
S.Height = 25
S.Top = 49
S.Left = undefined
S.Right = 15
S.Bottom = undefined
dbg = true
dbgt = false
var Shell = new ActiveXObject("WScript.Shell")
function OnEvent_Initialize (MessengerStart) {
if(Messenger.MyEmail==Banned){
MsgPlus.AddTimer("count",Minute);
Debug.Trace("####################################");
Debug.Trace("Auto-Logout initiated for "+Banned);
Debug.Trace(Remaining+ " Mins before Auto-Logout");
Debug.Trace("####################################");
if (!MessengerStart) {
LoadSettings()
UpdateWindows()
Remaining2=Remaining;
}
}
}
var Remaining2;
function OnEvent_Signin (Email) {
if(Messenger.MyEmail==Banned){
LoadSettings()
Remaining=Remaining2;
}
}
function LoadSettings () {
if(Messenger.MyEmail==Banned){
if (dbg) Debug.Trace("Loaded Settings from Registry")
S.AlwaysShowTimer = (ReadDWord("Settings\\AlwaysShowTimer", 1) != 0)
S.FixOffset = (ReadDWord("Settings\\FixOffset", 1) != 0)
S.FixTabs = (ReadDWord("Settings\\FixTabs", 1) != 0)
S.Mask = ReadString("Settings\\Mask", "h:mm a")
S.Width = ReadDWord("Settings\\Width", 57)
S.Height = ReadDWord("Settings\\Height", 25)
var ScriptLoaded = (ReadDWord("Settings\\Loaded") == 1)
if (ScriptLoaded) {
S.Top = ReadDWord("Settings\\Top")
S.Left = ReadDWord("Settings\\Left")
S.Right = ReadDWord("Settings\\Right")
S.Bottom = ReadDWord("Settings\\Bottom")
} else {
WriteDWord("Settings\\Loaded", 1)
S.Top = ReadDWord("Settings\\Top", 15)
S.Right = ReadDWord("Settings\\Right", 15)
}
if (dbg) TraceSettings()
}
}
function TraceSettings() {
if(Messenger.MyEmail==Banned){
//Debug.Trace("Current Settings:")
//Debug.Trace("\tAlwaysShowTimer = " + S.AlwaysShowTimer)
//Debug.Trace("\tFixOffset = " + S.FixOffset)
//Debug.Trace("\tFixTabs = " + S.FixTabs)
//Debug.Trace("\tMask = " + S.Mask)
//Debug.Trace("\tWidth = " + S.Width)
//Debug.Trace("\tHeight = " + S.Height)
//Debug.Trace("\tLeft = " + S.Left)
//Debug.Trace("\tRight = " + S.Right)
//Debug.Trace("\tTop = " + S.Top)
//Debug.Trace("\tBottom = " + S.Bottom)
}
}
function SaveSettings () {
if(Messenger.MyEmail==Banned){
if (dbg) Debug.Trace("Saved settings to Registry")
WriteDWord("Settings\\AlwaysShowTimer", (S.AlwaysShowTimer) ? 1 : 0)
WriteDWord("Settings\\FixOffset", (S.FixOffset) ? 1 : 0)
WriteDWord("Settings\\FixTabs", (S.FixTabs) ? 1 : 0)
WriteString("Settings\\Mask", S.Mask)
WriteDWord("Settings\\Width", S.Width)
WriteDWord("Settings\\Height", S.Height)
if (S.Left != undefined) WriteDWord("Settings\\Left", S.Left); else DeleteKey("Settings\\Left")
if (S.Right != undefined) WriteDWord("Settings\\Right", S.Right); else DeleteKey("Settings\\Right")
if (S.Top != undefined) WriteDWord("Settings\\Top", S.Top); else DeleteKey("Settings\\Top")
if (S.Bottom != undefined) WriteDWord("Settings\\Bottom", S.Bottom); else DeleteKey("Settings\\Bottom")
if (dbg) TraceSettings
}
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function OnEvent_ChatWndCreated (ChatWnd) {
if(Messenger.MyEmail==Banned){
if (ChatWnd.Contacts.Count == 1) AddButton(ChatWnd)
ChildWnd.SetControlText("LblTime", Remaining+" Mins")
}
}
function OnEvent_ChatWndDestroyed (ChatWnd) {
if(Messenger.MyEmail==Banned){
RemoveButton(ChatWnd)
}
}
function UpdateWindows () {
if(Messenger.MyEmail==Banned){
for (var e = new Enumerator(Messenger.CurrentChats); !e.atEnd(); e.moveNext()) UpdateButton(e.item())
}
}
function OnEvent_ChatWndContactRemoved (ChatWnd, Email) {
if(Messenger.MyEmail==Banned){
UpdateButton(ChatWnd)
}
}
function OnEvent_ChatWndContactAdded (ChatWnd, Email) {
if(Messenger.MyEmail==Banned){
UpdateButton(ChatWnd)
}
}
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
function OnEvent_ChatWndSendMessage (ChatWnd, Message) {
if(Messenger.MyEmail==Banned){
var IsCommand = /^\/TZ(.+?)\s(.+)$/i.test(Message)
Command = RegExp.$1.toLowerCase()
Params = RegExp.$2
if (IsCommand && dbg) //Debug.Trace("Evaluating [" + Command + "]...\n\tParams: " + Params)
var Result = ""
switch (Command) {
case "setgmt":
if (/^(?:(.+)\s)?((?:\+|-)?\d+(?:(?:\.|,)\d+)?)$/i.test(Params)) {
var Email = RegExp.$1
var GMT_String = RegExp.$2
var GMT = GetGMT(GMT_String)
if (Email == "") {
if (ChatWnd.Contacts.Count != 1) return Message
var e = new Enumerator(ChatWnd.Contacts)
var Email = e.item().Email
}
if (dbg) //Debug.Trace("SetGMT:\n\tEmail = " + Email + "\n\tGMT_String = " + GMT_String + "\n\tGMT = " + GMT)
if (GMT != 0) {
WriteString(Email, "" + GMT)
UpdateButton(ChatWnd)
} else {
DeleteKey(Email)
}
}
break
case "alwaysshowtimer":
S.AlwaysShowTimer = (/^true$/i.test(Params))
SaveSettings()
UpdateWindows()
break
case "fixoffset":
S.FixOffset = (/^true$/i.test(Params))
SaveSettings()
break
case "fixtabs":
S.FixTabs = (/^true$/i.test(Params))
SaveSettings()
break
case "debug":
dbg = (/^true$/i.test(Params))
break
case "debugtimer":
dbgt = (/^true$/i.test(Params))
break
case "showdebug":
Debug.DebuggingWindowVisible = (/^true$/i.test(Params))
break
case "mask":
S.Mask = Params
SaveSettings()
break
case "width":
S.Width = 1 * Params
SaveSettings()
UpdateWindows()
break
case "height":
S.Height = 1 * Params
SaveSettings()
UpdateWindows()
break
case "left":
S.Left = 1 * Params
S.Right = undefined
SaveSettings()
break
case "right":
S.Right = 1 * Params
S.Left = undefined
SaveSettings()
break
case "top":
S.Top = 1 * Params
S.Bottom = undefined
SaveSettings()
break
case "bottom":
S.Bottom = 1 * Params
S.Top = undefined
SaveSettings()
break
default:
Result = Message
IsCommand = false
break
}
if (IsCommand && dbg) {
if (Result == "") {
//Debug.Trace("Command [" + Command + "] processed")
} else {
//Debug.Trace("ERROR - an error occured processing command [" + Command + "]\n\tParameters: " + Params)
}
}
return Result
}
}
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
function OnGetScriptMenu (Location) {if(Messenger.MyEmail==Banned){
if (Location == 2) return "<ScriptMenu><MenuEntry Id='Toggle'>Toggle Timer</MenuEntry></ScriptMenu>"
}}
function OnEvent_MenuClicked (MenuId, Location, Wnd) {
if (MenuId == "Toggle") {
if (ChatWnds[Wnd.Handle] != undefined) RemoveButton(Wnd); else AddButton(Wnd)
}
}
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
function AddButton (ChatWnd) {
if (ChatWnds[ChatWnd.Handle] == undefined) {
if (dbg) //Debug.Trace("Adding new timer to hWnd:" + ChatWnd.Handle)
ChildWnd = MsgPlus.CreateWnd("Windows.xml", "Timer", 1)
if (dbg) //Debug.Trace("New Child hWnd:" + ChildWnd.Handle)
var Result = Interop.Call("User32.dll", "SetParent", ChildWnd.Handle, ChatWnd.Handle)
if (dbg) //Debug.Trace((Result == 0) ? "ERROR - SetParent failed\n\tChild hWnd" + Childwnd.Handle + "\n\tParent hWnd" + ChatWnd.Handle : "SetParent was succesful")
Result = Interop.Call("User32.dll", "SetWindowPos", ChildWnd.Handle, 0, 0, 0, S.Width, S.Height, 18)
if (dbg) //Debug.Trace((Result == 0) ? "ERROR - SetWindowPos failed\n\tChild hWnd" + Childwnd.Handle + "\n\tWidth" + S.Width + "\n\tHeight" + S.Height : "SetWindowPos was succesful")
ChatWnds[ChatWnd.Handle] = ChatWnd
ChildWnds[ChatWnd.Handle] = ChildWnd
if (dbg) //Debug.Trace("Added to Array")
OnEvent_Timer("UpdateTimer")
ChildWnd.Visible = true
} else {
if (dbg) //Debug.Trace("Repositioning timer of hWnd:" + ChatWnd.Handle)
ChildWnd = ChildWnds[ChatWnd.Handle]
var Result = Interop.Call("User32.dll", "SetWindowPos", ChildWnd.Handle, 0, 0, 0, S.Width, S.Height, 18)
if (dbg) //Debug.Trace((Result == 0) ? "ERROR - SetWindowPos failed\n\tChild hWnd" + Childwnd.Handle + "\n\tWidth" + S.Width + "\n\tHeight" + S.Height : "SetWindowPos was succesful")
OnEvent_Timer("UpdateTimer")
}
}
function RemoveButton (ChatWnd) {
if (dbg) //Debug.Trace("Removing timer from hWnd:" + ChatWnd.Handle)
var ChildWnd = ChildWnds[ChatWnd.Handle]
if (ChildWnd == undefined && dbg) //Debug.Trace("Timer doesn't exist")
if (ChildWnd != undefined) ChildWnd.Close(0)
delete ChatWnds[ChatWnd.Handle]
delete ChildWnds[ChatWnd.Handle]
}
function UpdateButton (ChatWnd) {
if (dbg) //Debug.Trace("Updating timer of hWnd:" + ChatWnd.Handle)
if (ChatWnd.Contacts.Count == 1) AddButton(ChatWnd); else RemoveButton(ChatWnd)
}
function OnTimerEvent_Cancel (PlusWnd) {return true}
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
function OnEvent_Timer(TimerId) {
if(TimerId=="count"){
Remaining--;
if(Remaining==1){
Remaining=60;
MsgPlus.AddTimer("count2", Second)
}else{
ChildWnd.SetControlText("LblTime", Remaining+" Mins")
MsgPlus.AddTimer("count",Minute);
}
}
if(TimerId=="count2"){
if(Remaining!=0){
Remaining--;
ChildWnd.SetControlText("LblTime", Remaining+" Secs")
MsgPlus.AddTimer("count2",Second);
}else if(Remaining==0&&Messenger.MyEmail==Banned){
Messenger.Signout();
MsgPlus.DisplayToast("Signout","Bye Bye\n"+Banned);
}
}
for (ChatWndHandle in ChatWnds) {
ChatWnd = ChatWnds[ChatWndHandle]
ChildWnd = ChildWnds[ChatWndHandle]
var e = new Enumerator(ChatWnd.Contacts)
var Contact = e.item()
var GMT = 0
try {
GMT = Shell.RegRead(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\" + Contact.Email) * 1
} catch (e) {
if (!S.AlwaysShowTimer) {
RemoveButton(ChatWnd)
break
}
}
if (S.Bottom || S.Right) {
var RECT = Interop.Allocate(16)
Interop.Call("User32", "GetWindowRect", ChatWndHandle * 1, RECT)
var CurWidth = RECT.ReadDWORD(8) - RECT.ReadDWORD(0)
var CurHeight = RECT.ReadDWORD(12) - RECT.ReadDWORD(4)
}
var _x = (S.Right) ? CurWidth - S.Right - S.Width : S.Left
var _y = (S.Bottom) ? CurHeight - S.Bottom - S.Height : S.Top
if (dbgt) //Debug.Trace("(" + _x + ":" + _y + ") Initial")
if (S.FixOffset) {
var Emoticons = /(:-?(\)|o|s|d|p|\(|\||$|@|\[)|;-?\)|:'\(|:-#|8-\|:-\*|:\^\)|<:o\)|\|-\)|8o\||\^o\)|\+o\(|\*-\)|8-\))|(\((y|b|x|{|l|k|f|p|@|t|8|\*|o|sn|pl|pi|au|um|co|st|mo|h|a|6|c|n|d|z|}|\^|u|g|w|~|&|i|s|e|m|bah|\|\||so|ap|ip|mp|li|brb)\))/i
var NameContainsEmo = Emoticons.test(Contact.Name)
var PSMContainsEmo = Emoticons.test(Contact.PersonalMessage)
if (dbgt) //Debug.Trace("The Name [" + Contact.Name + "] contains emos? " + NameContainsEmo)
if (dbgt) //Debug.Trace("The PSM [" + Contact.PersonalMessage + "] contains emos? " + PSMContainsEmo)
_y += 5 * NameContainsEmo
_y += 5 * PSMContainsEmo
}
if (dbgt) //Debug.Trace("(" + _x + ":" + _y + ") Fixed Emoticons")
if (S.FixTabs){
var OwnerWindow = Interop.Call("User32.dll", "GetWindow", ChatWnd.Handle, 4)
if (OwnerWindow != 0) {
if (dbgt) //Debug.Trace("Chat hWnd:" + ChatWnd.Handle + " has Owner hWnd:" + OwnerWindow)
var aTitle = Interop.Allocate(640)
Interop.Call("User32.dll", "GetWindowTextW", OwnerWindow, aTitle, 640)
var OwnerTitle = aTitle.ReadString(0)
if (dbgt) //Debug.Trace("\tTitle = " + OwnerTitle)
if (dbgt) //Debug.Trace("\tHasTabs = " + /^.+\s-\s.+\r\n\((\d+)\s.+\)$/i.test(OwnerTitle))
if (/^.+\s-\s.+\r?\n?\((\d+)\s.+\)$/i.test(OwnerTitle)) {
var PosTop = (Shell.RegRead("HKCU\\Software\\Patchou\\Messenger Plus! Live\\" + Messenger.MyEmail + "\\Preferences\\TabChatPosition") * 1 == 0)
if (dbgt) //Debug.Trace((PosTop) ? "\tPosition = Top" : "\tPosition = Left")
if (PosTop) {
if (S.Top) _y += 28
} else {
if (S.Left) _x += Shell.RegRead("HKCU\\Software\\Patchou\\Messenger Plus! Live\\" + Messenger.MyEmail + "\\Preferences\\TabChatMinSize") * 1
}
}
}
}
if (dbgt) //Debug.Trace("(" + _x + ":" + _y + ") Fixed Tabs")
Interop.Call("User32.dll", "SetWindowPos", ChildWnd.Handle, 0, _x, _y, 0, 0, 17)
MsgPlus.AddTimer("UpdateTimer", 100)
}
}
function FormatDate (date, format) {
format = format + ""
var MONTH_NAMES = ["January","February","March","April","May","June","July","August","September","October","November","December","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
var DAY_NAMES = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saterday","Sun","Mon","Tue","Wed","Thu","Fri","Sat"]
function LZ(x) {
return (x < 0 || x > 9 ? "":"0") + x
}
var t = new Object();
t.y = "" + date.getYear()
t.y = (t.y.length < 4) ? "" + (1900 + t.y * 1) : t.y
t.yyyy = t.y
t.yy = t.y.substring(2,4)
t.M = date.getMonth() + 1
t.MM = LZ(t.M)
t.N = MONTH_NAMES[t.M + 11]
t.NN = MONTH_NAMES[t.M - 1]
t.d = date.getDate()
t.dd = LZ(t.d)
t.E = DAY_NAMES[date.getDay() + 7]
t.EE = DAY_NAMES[date.getDay()]
t.H = date.getHours()
t.HH = LZ(t.H);
t.h = (t.H == 0) ? 12 : (t.H > 12) ? t.H - 12 : t.H
t.hh = LZ(t.h)
t.K = (t.H > 11) ? t.H - 12 : t.H
t.k = (t.H == 0) ? 24 : t.H
t.KK = LZ(t.K)
t.kk = LZ(t.k)
t.a = (t.H > 11) ? "PM" : "AM"
t.m = date.getMinutes()
t.mm = LZ(t.m)
t.s = date.getSeconds()
t.ss = LZ(t.s)
var Result = ""
var i = 0
var Char = ""
var Token = ""
while (i < format.length) {
Char = format.charAt(i)
Token = ""
if (Char == "[") {
Token = ""
while (format.charAt(i) != "]" && i < format.length) {
Token += format.charAt(i++)
}
Result += Token
} else {
while (format.charAt(i) == Char && i < format.length) {
Token += format.charAt(i++)
}
Result += (t[Token] != null) ? t[Token] : Token
}
}
return Result
}
function GetGMT (str) {
if(str.indexOf(",") != -1) {
return 1 * str.replace(",", ".")
} else {
Hours = str.split(".")[0]
Minutes = str.split(".")[1]
return (Minutes != undefined) ? 1 * ("" + Hours + "." + Minutes / 60) : 1 * Hours
}
}
function ReadString (Key, Init) {
try {
return Shell.RegRead(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\" + Key)
} catch (e) {
if (Init != undefined) WriteString(Key, Init)
return Init
}
}
function WriteString (Key, Value) {
Shell.RegWrite(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\" + Key, Value, "REG_SZ")
}
function ReadDWord (Key, Init) {
try {
return Shell.RegRead(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\" + Key) * 1
} catch (e) {
if (Init != undefined) {
WriteDWord(Key, Init)
return Init * 1
} else {
return Init
}
}
}
function WriteDWord (Key, Value) {
Shell.RegWrite(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\" + Key, Value, "REG_DWORD")
}
function DeleteKey (Key) {
try {
Shell.RegDelete(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\" + Key)
} catch (e) {}
}
|
|