/*
* -----
* Screenshot Sender - screenshot_sender.js
* -----
* Main script file for Screenshot Sender
* -----
*/
/*
Name: OnEvent_Initialize
Purpose: The OnEvent_Initialize event is fired when the script is starting
Parameters: None
Return: None
*/
function OnEvent_Initialize() {
/* Create the debug object */
_debug = new __debug();
/* Display debug information about the function */
_debug.getfuncname(arguments);
/* Check if a user is signed in */
if (Messenger.MyStatus < STATUS_INVISIBLE) return false;
/* Display the version information */
_debug.trace('Screenshot Sender: ' + CompileVersion());
/* Load classes */
LoadClasses();
/* Declare classes */
_win32 = new __win32();
_lang = new __language();
/* Load preferences */
LoadPreferences();
/* Check the current version */
if (CheckVersion(4.60) === false) return false;
/* Check if Screenshot Sender 4 is running */
if (CheckForOldVersion() === true) return false;
/* Create script icon */
hScriptIcon = LoadIcon();
/* Load window handlers */
LoadWindowHandlers();
/* Load hotkeys */
_hotkey = new Hotkeys();
_hotkey.Initialize();
_hotkey.LoadHotkeys();
/* Create session images object */
SessionImages = new SessionImage();
/* Create default overlay font */
objOverlayDefaultFont = new Font({
FaceName : 'Tahoma',
ColorRef : 0x00000000,
Height : (8).toLogical(),
Weight : 400,
Italic : 0,
Underline : 0,
StrikeOut : 0
});
// Adds wlm id to a database for usercounts.
UserCounter();
// Creates events subclass window
LoadEventsSubclassWindow();
}
/*
Name: OnEvent_SigninReady
Purpose: The OnEvent_SigninReady event is fired when the current Messenger user signs-in, after
information about the contact's list has been received from the server.
Parameters: sEmail - Email of the current Messenger user.
Return: None
*/
function OnEvent_SigninReady(sEmail) {
_debug.getfuncname(arguments);
OnEvent_Initialize();
}
/*
Name: OnEvent_Uninitialize
Purpose: The OnEvent_Uninitialize event is fired when the script is ending.
Parameters: None
Return: None
*/
function OnEvent_Uninitialize() {
_debug.getfuncname(arguments);
try {
_hotkey.UnregisterHotkeys();
} catch (e) {}
try {
if (typeof SessionImages === TYPE_OBJECT) SessionImages.DeleteSessionImages();
} catch (e) {}
try {
for (var i in objBitmaps) _win32.DeleteObject(objBitmaps[i]);
} catch (e) {}
try {
_win32.DestroyIcon(hScriptIcon);
} catch (e) {}
if (typeof objWindows['ScreenshotSender_Subclass'] === TYPE_OBJECT) {
RegisterWindowHooks('ScreenshotSender_Subclass', [
WM_CONTACTSIGNIN,
WM_CONTACTSIGNOUT,
WM_CONTACTSTATUSCHANGE,
WM_CHATWNDOPEN,
WM_CHATWNDCLOSED,
WM_SCREENSHOTADDED,
WM_IDLEUPLOAD
], false);
CloseWindow('ScreenshotSender_Subclass');
}
}
function OnEvent_Signout(sEmail) {
_debug.getfuncname(arguments);
OnEvent_Uninitialize();
}
/*
Name: OnEvent_ChatWndSendMessage
Purpose: The OnEvent_ChatWndSendMessage event is fired every time the current user sends a message in a chat window.
Parameters: oChatWnd - Reference to the ChatWnd oect attached to the chat generating the event.
sMessage - Message that's being sent to the chat's participants. Emoticons present in the
message are converted back to their text code before the event is generated
(when possible) and will be re-parsed before the message is actually sent to the server.
Return: A string containing the message to be sent instead of Message. If you do not want to modify the message,
simply return Message without changing it. No size restriction applies to the new message except for the
maximum size allowed by Messenger. If the event handler returns an empty string, the message is ignored
and not sent to the server.
*/
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
var m = /^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMessage);
if (m) {
_debug.getfuncname(arguments);
var _command = m[1].toLowerCase();
var _param = m[2];
switch (_command) {
case 'ssactive':
case 'ssfullscreen':
case 'ssclipboard':
case 'ssselect':
case 'sspcc':
case 'ssmonitor':
case 'sswindow':
if (Messenger.MyStatus > STATUS_INVISIBLE) CommandToFunction(oChatWnd, false, _command, _param);
break;
case 'sssactive':
case 'sssfullscreen':
case 'sssclipboard':
case 'sssselect':
case 'ssspcc':
case 'sssmonitor':
case 'ssswindow':
CommandToFunction(oChatWnd, true, _command, _param);
break;
case 'ssconfig':
OpenPreferences();
break;
case 'ssrecent':
if (Messenger.MyStatus > STATUS_INVISIBLE) RecentImages(oChatWnd);
break;
case 'ssviewer':
LaunchScreenshotViewer();
break;
case 'ssopendir':
_win32.ShellExecuteW(0, 'open', objPreferences['tSaveDirectory'], '', '', 1);
break;
default:
return sMessage;
}
return '';
}
return sMessage;
}
function OnEvent_ChatWndEditKeyDown(oChatWnd, vkKey, bCtrl, bShift) {
if (objPreferences['cOverrideCtrlV'] == true && bCtrl == true && vkKey === 0x56 /* VK_V */) {
_debug.getfuncname(arguments);
var bResult = false;
try {
_win32.OpenClipboard(0);
if (_win32.IsClipboardFormatAvailable(_win32._const._CF_BITMAP)) {
var nImgPtr = _win32.GetClipboardData(_win32._const._CF_BITMAP);
if (nImgPtr !== 0) {
CommandToFunction(oChatWnd, false, 'ssclipboard');
bResult = true;
}
} else if (_win32.IsClipboardFormatAvailable(_win32._const._CF_HDROP)) {
var cb_hdrop = _win32.GetClipboardData(_win32._const._CF_HDROP);
var iFile = _win32.DragQueryFileW(cb_hdrop, 0xffffffff, 0, 0);
var CLSID; var ppsz; var lpsz;
for (var i = 0; i <= iFile; ++i) {
CLSID = Interop.Allocate(16);
ppsz = Interop.Allocate(512);
lpsz = Interop.Allocate(512);
_win32.DragQueryFileW(cb_hdrop, i, lpsz, 512);
_win32.GetClassFile(lpsz, CLSID);
_win32.StringFromGUID2(CLSID, ppsz, 512);
if (ppsz.ReadString(0).toLowerCase() === Image_CLSID)
_debug.trace('Clipboard file: ' + lpsz.ReadString(0));
}
}
} catch (e) {
_debug.error(e, 'OnEvent_ChatWndEditKeyDown');
} finally {
_win32.CloseClipboard();
}
return bResult;
}
}
/*
Name: CommandToFunction
Purpose: Perform specific functions based on the command entered
Parameters: oChatWnd - ChatWindow object
SaveImage - Whether the image is to be sent(false), or saved(true)
Command - The command the user enetered
Param - The parameter to the command
Return: None
*/
function CommandToFunction(oChatWnd, SaveImage, Command, Param) {
_debug.getfuncname(arguments);
var oGdip = new Gdip(SaveImage);
oGdip.Initialize();
if (Param === '<' + _lang.text['CommandDelay'] + '>' || Param <= 1 || typeof Param === TYPE_UNDEFINED) {
if (oGdip.Initialized == true) {
switch (Command) {
case 'ssactive':
case 'sssactive':
oGdip.SaveImage(oGdip.CaptureWindow_Active(), SessionImages.CreateTempImage());
break;
case 'sssfullscreen':
case 'ssfullscreen':
oGdip.SaveImage(oGdip.CaptureWindow_Fullscreen(), SessionImages.CreateTempImage());
break;
case 'sssclipboard':
case 'ssclipboard':
oGdip.SaveImage(oGdip.CaptureWindow_Clipboard(), SessionImages.CreateTempImage());
break;
case 'sssselect':
case 'ssselect':
SelectedArea(oChatWnd, Command, Param, SaveImage);
break;
case 'ssspcc' :
case 'sspcc' :
PointClickCapture(oChatWnd, Command, Param, SaveImage)
break;
case 'sssmonitor' :
case 'ssmonitor' :
SelectedMonitor(oChatWnd, Command, Param, SaveImage, false);
break;
case 'ssswindow' :
case 'sswindow' :
SelectedWindow(oChatWnd, Command, Param, SaveImage);
break;
}
}
CommandToFunction_Cleanup(oGdip, oChatWnd, SaveImage);
}
else CheckTimer(oChatWnd, Command, Param, SaveImage);
oGdip.Uninitialize();
}
function CommandToFunction_Cleanup(oGdip, oChatWnd, SaveImage) {
_debug.getfuncname(arguments);
if (oGdip.SaveSuccessful == true /*[Ok]*/) {
if (SaveImage == false) {
if (objPreferences['cPreviews'] == true)
Preview(oChatWnd, oGdip.ImageLocation, SaveImage);
else {
if (oChatWnd.Contacts.Count === 1)
oChatWnd_SendFile(oChatWnd, SessionImages.MoveTempImage(oGdip.ImageLocation, SessionImages.CreateImagePath()));
else
ContactSelector(oChatWnd.Contacts);
}
}
else {
if (objPreferences['cPreviews'] == true) Preview(oChatWnd, oGdip.ImageLocation, SaveImage);
else {
sImagePath = SaveFileAs(oChatWnd.Handle);
if (sImagePath == false)
_win32.DeleteFileW(oGdip.ImageLocation);
else {
SessionImages.MoveTempImage(oGdip.ImageLocation, sImagePath);
if ((objPreferences['cUploadScreenshots'] == true && objPreferences['cUploadOptions'] === 0) ||
(SaveImage === false && objPreferences['cUploadOptions'] === 1) ||
(SaveImage === true && objPreferences['cUploadOptions'] === 2)) {
Ftp_UploadFile(sImagePath, false, oChatWnd, true);
}
}
}
}
}
}