That regular expression is just too complicated! You don't have to repeat a character set time and time again, just use accolades!
Anyway, this code will save the captured video in a global variable and uses a much cleaner regular expression. Try it!
code:
var video = "";
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
var tubeoption = TubeOption.RegRead(TubeOptionPath);
Debug.Trace(tubeoption);
if(MessageKind == 1 && tubeoption == 1) {
var reYouTube = /<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http:\/\/www\.youtube\.com\/v\/(.{11})\"><\/param><param name=\"wmode\" value=\"transparent\"><\/param><embed src=\"http:\/\/www\.youtube\.com\/v\/(.{11})\" type=\"application\/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"><\/embed><\/object>/g;
if(reTouTube.test(Message) {
video = RegExp.$1;
Message = "<YouTube Embed Video Link: "+video+">";
Debug.Trace("YouTube Embed Video Link captured: "+video);
MsgPlus.CreateWnd("youtubewindow.xml", "youtubequestion");
}
}
}
return Message;
}
function InternetExplorer() {
IE.width = "450";
IE.height = "350";
IE.statusbar = false;
IE.toolbar = false;
IE.menubar = false;
IE.addressbar = false;
IE.visible = true;
IE.navigate(video);
}
function OnyoutubequestionEvent_CtrlClicked(PlusWnd, ControlId) {
if(ControlId == "BtnYes") {
InternetExplorer();
PlusWnd.Close(1);
} else if(ControlId == "BtnNo") {
PlusWnd.Close(1);
}
}