Yeah, this has been my first attempt evar at J(ava)script and programming in general..
And the result of five(
) days learning Jscript from scratch is: "auto-send ISI"
The (pretty simple) idea was, that when I type a command in the conversation window, the script gets the Internal Sound Identifier for a Custom Sound (e.g. #CC506B2EDBC4) from the clipboard (if it's present) and sends the sound to the contact.
(might be useful when you're extremely lazy, browsing
mpsounds.net and you want to send just one sound from a huge soundpack (the ISI is called Sound ID over there, btw))
Maybe that's not such a big thing, (not very useful either), but it's an achievement for me, and I'm pretty happy that I got it working
I'll post the code below, and ask you to comment on it (style, efficiency and so on)
Commands:
enable script: +isi
disable script: -isi
send sound: isi
code:
var enabled = false;
var ISI;
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
if(Message == "+isi") {
enabled = true;
return("");
}
if(Message == "-isi") {
enabled = false;
return("");
}
if(Message == "isi") {
if(enabled == true)
return(startISI());
}
}
function startISI() {
readClipboard();
if(matchISI() == true) {
return(Message = "/sound " + ISI);
} else {
return("");
}
}
//http://shoutbox.menthix.net/showthread.php?tid=63067
function readClipboard() {
var CF_TEXT = 1;
var CF_OEMTEXT = 7;
var CF_UNICODETEXT = 13;
ISI = false;
try {
if(Interop.Call("User32", "OpenClipboard", 0)) {
if(Interop.Call("User32", "IsClipboardFormatAvailable", CF_TEXT | CF_OEMTEXT)) {
var hClipboardData = Interop.Call("User32", "GetClipboardData", CF_UNICODETEXT);
var pchData = Interop.Call("Kernel32", "GlobalLock", hClipboardData);
var size = Interop.Call("Kernel32", "GlobalSize", hClipboardData);
var str = Interop.Allocate(size+2);
Interop.Call("Kernel32", "RtlMoveMemory", str, pchData, size);
ISI = str.ReadString(0);
var unlocked = Interop.Call("Kernel32", "GlobalUnlock", hClipboardData);
} else {
Interop.Call("User32", "CloseClipboard");
return(false);
}
Interop.Call("User32", "CloseClipboard");
}
} catch(exeption) {
Interop.Call("User32", "CloseClipboard");
return(false);
}
return(ISI);
}
function matchISI() {
var re = /^\#[A-F0-9]{12}$/;
var foundArray = re.test(ISI);
if(foundArray == true) {
return(true);
} else {
return(false);
}
}