Omnom_Parser.js.s 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /*
  2. OmnomIRC COPYRIGHT 2010,2011 Netham45
  3. This file is part of OmnomIRC.
  4. OmnomIRC is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. OmnomIRC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with OmnomIRC. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. messageList = Array();
  16. UserListArr = Array();
  17. curLine = 0;
  18. messageBox = document.getElementById("MessageBox");
  19. mBoxCont = document.getElementById("mBoxCont");
  20. Userlist = Array();
  21. //******************************
  22. // Start Request Loop functions*
  23. //******************************
  24. function startLoop()
  25. {
  26. xmlhttp=getAjaxObject();
  27. if (xmlhttp==null) {
  28. alert ("Your browser does not support AJAX! Please update for OmnomIRC compatibility.");
  29. return;
  30. }
  31. xmlhttp.onreadystatechange=getIncomingLine;
  32. sendRequest();
  33. }
  34. function sendRequest()
  35. {
  36. url = "Update.php?lineNum=" + curLine + "&channel=" + getChannelEn() + "&nick=" + base64.encode(parent.userName) + "&signature=" + base64.encode(parent.Signature);
  37. xmlhttp.open("GET",url,true);
  38. xmlhttp.send(null);
  39. }
  40. function getIncomingLine()
  41. {
  42. if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") {
  43. if (xmlhttp.status == 200) addLine(xmlhttp.responseText); //Filter out 500s from timeouts
  44. sendRequest();
  45. }
  46. }
  47. function getAjaxObject()
  48. {
  49. xmlhttp=new XMLHttpRequest(); //Decent Browsers
  50. if (!xmlhttp || xmlhttp == undefined || xmlhttp == null) xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); //IE7+
  51. if (!xmlhttp || xmlhttp == undefined || xmlhttp == null) xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); //IE6-
  52. return xmlhttp;
  53. }
  54. //******************************
  55. // End Request Loop functions *
  56. //******************************
  57. //******************************
  58. // Start Parser *
  59. //******************************
  60. function addLine(message)
  61. {
  62. if (!message || message == null || message == undefined)
  63. return;
  64. doScroll = false;
  65. if (mBoxCont.clientHeight + mBoxCont.scrollTop > mBoxCont.scrollHeight - 50) doScroll = true;
  66. messageBox = document.getElementById("MessageBox");
  67. if ("\v" != "v") //If IE, take the slow but sure route (This is enough of a performance hit in all browsers to use the optimized code if possible. Also, IE can go fuck itself.)
  68. mBoxCont.innerHTML = '<table style="width:100%" class="messageBox" id="MessageBox">' + messageBox.innerHTML + parseMessage(message) + '</table>';
  69. else //If not IE, yay!
  70. messageBox.innerHTML = messageBox.innerHTML + parseMessage(message);
  71. if (doScroll)mBoxCont.scrollTop = mBoxCont.scrollHeight + 50;
  72. lnNum = message.split(":")[0];
  73. if (lnNum > curLine)
  74. curLine = lnNum;
  75. }
  76. function parseMessage(message)
  77. {
  78. a = message;
  79. var parts = message.split(":");
  80. lnumber = parts[0];
  81. type = parts[1];
  82. online = parts[2];
  83. parsedMessage = "";
  84. for (i = 4;i < parts.length;i++)
  85. parts[i] = base64.decode(parts[i]);
  86. name = clickable_names(parts[4],online);
  87. var undefined;
  88. if (parts[5] == undefined || parts[5] == "")
  89. parts[5] = " ";
  90. if (parts[5] != undefined && parts[5] != null)
  91. {
  92. parsedMessage = parseColors(parts[5]);
  93. if (parts[5].toLowerCase().indexOf(parent.userName.toLowerCase().substr(0,4)) >= 0 && hasLoaded && notifications && parts[4].toLowerCase() != "spybot45")
  94. {
  95. showNotification("<" + parts[4] + "> " + parts[5]);
  96. if (highDing)
  97. {
  98. document.getElementById('ding').play();
  99. }
  100. }
  101. }
  102. if ((type == "message" || type == "action") && parts[4].toLowerCase() != "spybot45")
  103. {
  104. parsedMessage = parseHighlight(parsedMessage);
  105. }
  106. retval = "";
  107. if (type != "message" && type != "pm")
  108. retVal='<td class="name">';
  109. switch (type)
  110. {
  111. case "join":
  112. retval += '<td class="name"> </td><td class="join"> * ' + name + " has joined "+getChannelDe() + "</td>";
  113. addUserJoin(parts[4],online);
  114. if (online == "1")
  115. return "";
  116. break;
  117. case "part":
  118. retval += '<td class="name"> </td><td class="part"> * ' + name + " has left "+getChannelDe()+" (" + parsedMessage + ")" + "</td>";
  119. removeUser(parts[4]);
  120. if (online == "1")
  121. return "";
  122. break;
  123. case "quit":
  124. retval += '<td class="name"> </td><td class="quit"> * ' + name + " has quit IRC (" + parsedMessage + ")" + "</td>";
  125. removeUser(parts[4]);
  126. break;
  127. case "kick":
  128. retval += '<td class="name"> </td><td class="kick"> * ' + name + " has kicked " + parts[5] + " from "+getChannelDe()+" (" + parts[6] + ")" + "</td>";
  129. removeUser(parts[4]);
  130. break;
  131. case "message":
  132. retval = '<span class="message"><td class="name">' + name + "</td><td>" + parsedMessage + "</td></span>";break;
  133. case "action":
  134. retval += '<td class="name"> </td><td class="action"> * ' + name + " " + parsedMessage + "</td>";break;
  135. case "mode":
  136. retval += '<td class="name"> </td><td class="mode"> * ' + name + " set "+getChannelDe()+" mode " + parts[5] + "</td>";break;
  137. case "nick":
  138. retval += '<td class="name"> </td><td class="nick"> * ' + name + " has changed his nick to " + parsedMessage + "</td>";
  139. removeUser(parts[4]);
  140. addUserJoin(parts[5],online);
  141. break;
  142. case "topic":
  143. retval += '<td class="name"> </td><td class="topic"> * ' + name + " has changed the topic to " + parsedMessage + "</td>";break;
  144. case "internal":
  145. retval += parts[4];
  146. break;
  147. case "pm":
  148. if (getChannelDe().toLowerCase() != ("*" + parts[4]).toLowerCase() && parts[4] != parent.userName)//Not in the PM window
  149. {
  150. retval = '<span class="pm"><td class="name">(PM)' + name + "</td><td>" + parsedMessage + "</td></span>";
  151. if (hasLoaded)
  152. {
  153. openPMWindow(parts[4]);
  154. if (notifications)
  155. showNotification("(PM) <" + parts[4] + "> " + parts[5]);
  156. if (highDing)
  157. document.getElementById('ding').play();
  158. document.getElementById("*" + parts[4]).style.color="#C22";
  159. }
  160. }
  161. else
  162. {
  163. retval = '<td class="name">' + name + "</td><td>" + parsedMessage + "</td></span>"; //In the PM window
  164. }
  165. break;
  166. case "curline":
  167. return "";
  168. break;
  169. case "highlight":
  170. if (parts[6].toLowerCase() == "spybot45") return "";
  171. document.getElementById(parts[4]).style.color="#C22"; //This call will fail if they aren't in the chan. Crude, but effective.
  172. if (notifications)
  173. showNotification("(" + parts[4] + ") <" + parts[6] + "> " + parts[7]);
  174. if (highDing)
  175. document.getElementById('ding').play();
  176. return "";
  177. break;
  178. case "default":
  179. return "";
  180. break;
  181. }
  182. if (type != "message" && type != "pm")
  183. retVal+="</td>";
  184. pretag = '<tr style="width:100%;">';
  185. doHigh = !doHigh;
  186. if (lineHigh && doHigh)
  187. {
  188. pretag = '<tr style="width:100%;" class="linehigh">';
  189. }
  190. doLineHigh = !doLineHigh;
  191. d = new Date(parts[3]*1000);
  192. retval = pretag + '<td class="irc-date">[' + d.toLocaleTimeString() + ']</td>' + retval + "</tr>";
  193. return retval;
  194. }
  195. function parseColors(colorStr)
  196. {
  197. if (!colorStr || colorStr == null || colorStr == undefined) return;
  198. colorStr = clickable_links(colorStr);
  199. lcount = 0;
  200. a = colorStr;
  201. arrayResults = Array();
  202. arrayResults2 = Array();
  203. while(colorStr.indexOf("\x03") >= 0)
  204. {
  205. arrayResults = colorStr.match("(^.*)\x03([0-9]{1,2}),([0-9]{1,2})(.*)");
  206. arrayResults2 = colorStr.match("(^.*)\x03([0-9]{1,2})(.*)");
  207. arrayResults3 = colorStr.match("(^.*)\x03([0-9]{1,2})(.*)");
  208. if(arrayResults != null && arrayResults.length > 4) //FG & BG
  209. {
  210. b = arrayResults;
  211. colorStr = arrayResults[1]+'<span class="fg-'+arrayResults[2]*1 +'"><span class="bg-'+arrayResults[3]*1 +'">'+arrayResults[4]+"</span></span>";
  212. lcount+=2;
  213. }
  214. else if(arrayResults2 != null && arrayResults2.length > 3) //FG Only
  215. {
  216. colorStr = arrayResults2[1]+'<span class="fg-' + arrayResults2[2]*1 + '">'+arrayResults2[3]+"</span></span>";
  217. lcount++;
  218. }
  219. else //We have a color control character w/o a color, most clients interperet this as clear colors.
  220. {
  221. for(lcount;lcount;lcount--)
  222. colorStr=colorStr+"</span>";
  223. colorStr = colorStr.replace(/\x03/,"");
  224. lcount--;
  225. }
  226. lcount++;
  227. }
  228. for(;lcount>=0;lcount--)
  229. colorStr=colorStr+"</span>";
  230. colorStr=colorStr+"</span>";
  231. /*Strip codes*/
  232. colorStr = colorStr.replace(/(\x03|\x02|\x1F|\x09|\x0F)/g,"");
  233. return(colorStr);
  234. }
  235. function parseHighlight(text)
  236. {
  237. if (text.toLowerCase().indexOf(parent.userName.toLowerCase().substr(0,4)) >= 0)
  238. {
  239. style = "";
  240. if (highRed)
  241. style = style + "color:#C73232;";
  242. if (highBold)
  243. style = style + "font-weight:bold;";
  244. return '<span class="highlight" style="' + style + '">' + text + "</span>";
  245. }
  246. return text;
  247. }
  248. function clickable_links(text)
  249. {
  250. if (!text || text == null || text == undefined) return;
  251. text = text.replace(/http:\/\/www.omnimaga.org\//g,"h111://www.omnimaga.org/");
  252. text = text.replace(/http:\/\/omniurl.tk\//g,"h111://omniurl.tk/");
  253. text = text.replace(/((h111:\/\/(www.omnimaga.org\/|omniurl.tk))[-a-zA-Z0-9@:;%_+.~#?&//=]+)/, '<a target="_TOP" href="$1">$1</a>');
  254. text = text.replace(/(((f|ht)(tp|tps):\/\/)[-a-zA-Z0-9@:;%_+.~#?&\/\/=]+)/g,'<a target="_blank" href="$1">$1</a>');
  255. text = text.replace(/([[ ]|[{}])(www.[-a-zA-Z0-9@:;%_+.~#?&//=]+)/,'$1 <a target="_blank" href="http://$2">$2</a>');
  256. text = text.replace(/h111/g,"http");
  257. return text;
  258. }
  259. function clickable_names(name,isOnline)
  260. {
  261. if (isOnline == "1")
  262. return '<a target="_TOP" href="http://www.omnimaga.org/index.php?action=ezportal;sa=page;p=13&userSearch=' + name + '">' + colored_names(name) + '</a>';
  263. return colored_names(name);
  264. }
  265. function colored_names(name)
  266. {
  267. if (!coloredNames)
  268. return name;
  269. if (!name || name == null || name == undefined)
  270. return;
  271. rcolors = Array(19, 20, 22, 24, 25, 26, 27, 28, 29);
  272. sum = i = 0;
  273. while (name[i])
  274. sum += name.charCodeAt(i++);
  275. sum %= 9;
  276. return '<span class="uName-'+rcolors[sum]+'">'+name+'</span>';
  277. }
  278. //******************************
  279. // End Parser *
  280. //******************************
  281. //******************************
  282. // Userlist Start *
  283. //******************************
  284. userListContainer = document.getElementById("UserListArrContainer");
  285. userListDiv = document.getElementById("UserList");
  286. function addUser(user)
  287. {
  288. UserListArr.push(user);
  289. }
  290. function addUserJoin(user,online)
  291. {
  292. if(!hasLoaded) return;
  293. var userp = base64.encode(user) + ":" + online;
  294. UserListArr.push(userp);
  295. parseUsers();
  296. }
  297. function parseUsers()
  298. {
  299. if (!userListDiv || userListDiv == null)
  300. userListDiv = document.getElementById("UserList");
  301. userText = "";
  302. i = 0;
  303. UserListArr.sort(function(a,b)
  304. {
  305. var al=base64.decode(a).toLowerCase(),bl=base64.decode(b).toLowerCase();
  306. return al==bl?(a==b?0:a<b?-1:1):al<bl?-1:1;
  307. });
  308. for (i=0;i<UserListArr.length;i++)
  309. {
  310. parts = UserListArr[i].split(":");
  311. if (parts[1] == "0") userText = userText + "#" + base64.decode(parts[0]) + "<br/>";
  312. if (parts[1] == "1")
  313. userText = userText + '<a target="_TOP" href="http://www.omnimaga.org/index.php?action=ezportal;sa=page;p=13&userSearch=' +base64.decode(parts[0]) +
  314. '"><img src="http://netham45.org/irc/efnet/ouser.png" alt="Omnimaga User" title="Omnimaga User" border=0 width=8 height=8 />' + base64.decode(parts[0]) + '</a><br/>';
  315. if (parts[1] == "2") userText = userText + "!" + base64.decode(parts[0]) + "<br/>";
  316. }
  317. userText = userText + "<br/><br/>";
  318. userListDiv.innerHTML = userText;
  319. }
  320. function removeUser(user)
  321. {
  322. if(!hasLoaded) return;
  323. for (i in UserListArr)
  324. {
  325. parts = UserListArr[i].split(":");
  326. if (base64.decode(parts[0]) == user)
  327. UserListArr.splice(i,1);
  328. }
  329. parseUsers();
  330. }
  331. //******************************
  332. // Userlist End *
  333. //******************************
  334. //******************************
  335. // Load Start *
  336. //******************************
  337. function load()
  338. {
  339. cookieLoad();
  340. lineHigh = getOption(6,"T") == "T";
  341. doHigh = false;
  342. coloredNames = getOption(3,"F") == "T";
  343. highRed = getOption(2,"T") == "T";
  344. highBold = getOption(1,"T") == "T";
  345. enabled = getOption(5,"T") == "T";
  346. notifications = getOption(7,"F") == "T";
  347. highDing = getOption(8,"F") == "T";
  348. showExChans = getOption(9,"F") == "T";
  349. hasLoaded = false;
  350. if (!enabled)
  351. {
  352. messageBox.innerHTML = '<a href="#" onclick="toggleEnable();">OmnomIRC is disabled. Click here to enable.</a>';
  353. return false;
  354. }
  355. doLineHigh=true;
  356. var body= document.getElementsByTagName('body')[0];
  357. var chanScr= document.createElement('script');
  358. chanScr.type= 'text/javascript';
  359. chanScr.src= 'Channels.php';
  360. chanScr.onload= function(){channelSelectorCallback();};
  361. body.appendChild(chanScr);
  362. chanList = document.getElementById('chanList');
  363. }
  364. window.onLoad = load();
  365. //******************************
  366. // Load End *
  367. //******************************
  368. //******************************
  369. // Links Start *
  370. //******************************
  371. function toggleEnable()
  372. {
  373. setOption(5,!(getOption(5,'T') == 'T')?'T':'F');
  374. window.location.reload(true);
  375. }
  376. //******************************
  377. // Links End *
  378. //******************************
  379. //******************************
  380. // Message Send Start *
  381. //******************************
  382. function sendAJAXMessage(name,signature,message,chan) //'chan' kept for legacy purposes.
  383. {
  384. if (message[0] == "/")
  385. {
  386. if (parseCommand(message.substr(1)))
  387. return;
  388. }
  389. if (getChannelDe()[0] == "*")
  390. {
  391. d = new Date();
  392. str="0:pm:0:" + base64.encode(d.getTime()) + ":" + base64.encode(name) + ":" + base64.encode(HTMLEncode(message)); //Print PMs locally.
  393. addLine(str);
  394. }
  395. var theURL = "message.php?nick=" + base64.encode(name) + "&signature="+base64.encode(signature)+"&message=" + base64.encode(message) +"&channel=" + getChannelEn();
  396. xmlhttp2=new XMLHttpRequest();
  397. xmlhttp2.open("GET", theURL ,false);
  398. xmlhttp2.send(null);
  399. }
  400. //******************************
  401. // Message Send End *
  402. //******************************
  403. //******************************
  404. // Channel Selector Start *
  405. //******************************
  406. function channelSelectorCallback()
  407. {
  408. if (showExChans)
  409. for (i in exChannels)
  410. channels.push(exChannels[i]);
  411. /*if (parent.moreChans)
  412. for(i in parent.moreChans)
  413. channels.push(base64.encode(parent.moreChans[i]));*/
  414. loadChannels(); //From cookies
  415. drawChannels();
  416. var body= document.getElementsByTagName('body')[0];
  417. var script= document.createElement('script');
  418. script.type= 'text/javascript';
  419. script.src= 'Load.php?count=50&channel=' + getChannelEn() + "&nick=" + base64.encode(parent.userName) + "&signature=" + base64.encode(parent.Signature) + "&time=" + (new Date).getTime();;
  420. script.onload= function(){parseUsers();startLoop();mBoxCont.scrollTop = mBoxCont.scrollHeight;hasLoaded = true;};
  421. body.appendChild(script);
  422. }
  423. function changeChannel()
  424. {
  425. //Empty out dirty holders
  426. mBoxCont.innerHTML = '<table style="width:100%" class="messageBox" id="MessageBox"><tr><td>OmnomIRC</td></tr></table>';
  427. hasLoaded = false;
  428. curLine = 0;
  429. UserListArr = Array();
  430. userListDiv.innerHTML = "";
  431. drawChannels();
  432. var body= document.getElementsByTagName('body')[0];
  433. var script= document.createElement('script');
  434. script.type= 'text/javascript';
  435. script.src= 'Load.php?count=50&channel=' + getChannelEn() + "&nick=" + base64.encode(parent.userName) + "&signature=" + base64.encode(parent.Signature) + "&time=" + (new Date).getTime();;
  436. script.onload= function(){parseUsers();startLoop();mBoxCont.scrollTop = mBoxCont.scrollHeight;hasLoaded = true;};
  437. body.appendChild(script);
  438. }
  439. function drawChannels()
  440. {
  441. var chanText = '';//'<table>';
  442. for (i in channels)
  443. {
  444. var chanName = base64.decode(channels[i]);
  445. //partChannel
  446. style = "chan";
  447. chanText += '<table class="chanList"><td id="' + chanName + '" class="';
  448. if (getChannelIndex()==i)
  449. style = "curchan";
  450. chanText += style;
  451. chanText += '">';
  452. if (chanName.substr(0,1) != "#")
  453. chanText += '<span onclick="partChannel(\'' + chanName + '\')" onmouseover="this.style.color=\'#C73232\';this.style.font-weight=\'bolder\'" onmouseout="this.style.color=\'' + ((getChannelIndex()==i)?'#FFF':'#22C') + '\';this.style.font-weight=\'normal\'">x</span> ';
  454. chanText += '<span onclick="selectChannel(' + i + ')">';
  455. chanText += chanName;
  456. chanText += "</span>";
  457. chanText += "</td></table>";
  458. }
  459. //chanText += "</table>";
  460. document.getElementById("ChanList").innerHTML = chanText;
  461. }
  462. function selectChannel(index)
  463. {
  464. setOption(4,String.fromCharCode(index + 32),true);
  465. changeChannel();
  466. }
  467. function getChannelEn()
  468. {
  469. return channels[getChannelIndex()];
  470. }
  471. function getChannelDe()
  472. {
  473. return base64.decode(channels[getChannelIndex()]);
  474. }
  475. function getChannelIndex()
  476. {
  477. var index = getOption(4,String.fromCharCode(32)).charCodeAt(0) - 32;
  478. if (index > (channels.length - 1))
  479. index = 0;
  480. return index;
  481. }
  482. //******************************
  483. // Channel Selector End *
  484. //******************************
  485. //******************************
  486. // Tab Completion Start *
  487. //******************************
  488. function searchUser(start,startAt)
  489. {
  490. if(!startAt)
  491. startAt = 0;
  492. for (i=0;i<UserListArr.length;i++)
  493. {
  494. parts = UserListArr[i].split(":");
  495. name = base64.decode(parts[0]).toLowerCase();
  496. if (name.indexOf(start.toLowerCase()) == 0 && startAt-- <= 0)
  497. return base64.decode(parts[0]);
  498. }
  499. return start;
  500. }
  501. //******************************
  502. // Tab Completion End *
  503. //******************************
  504. //******************************
  505. // Commands Start *
  506. //******************************
  507. function sendInternalMessage(message)
  508. {
  509. d = new Date();
  510. str="0:internal:0:" + base64.encode(d.getTime()) + ":" + base64.encode(message);
  511. addLine(str);
  512. }
  513. function joinChannel(paramaters)
  514. {
  515. if (paramaters.substr(0,1) != "@" && paramaters.substr(0,1) != "#")
  516. paramaters = "@" + paramaters;
  517. //Check if it already exists or not. If so, try to join it.
  518. var count = 0;
  519. for (i in channels)
  520. {
  521. if (base64.decode(channels[i]).toLowerCase() == paramaters.toLowerCase())
  522. {
  523. selectChannel(count);
  524. return;
  525. }
  526. count++;
  527. }
  528. //Channel not in existance.
  529. if (paramaters.substr(0,1) == "#")
  530. {
  531. sendInternalMessage('<span style="color:#C73232;"> Join Error: Cannot join new channels starting with #.</span>');
  532. return;
  533. }
  534. //Valid chan, add to list.
  535. channels.push(base64.encode(paramaters));
  536. saveChannels();
  537. selectChannel(channels.length-1);
  538. }
  539. function openPMWindow(paramaters)
  540. {
  541. if (paramaters.substr(0,1) == "@" && paramaters.substr(0,1) == "#")
  542. sendInternalMessage('<span style="color:#C73232;"> Query Error: Cannot query a channel. Use /join instead.</span>');
  543. if (paramaters.substr(0,1) != "*")
  544. paramaters = "*" + paramaters;
  545. for (i in channels)
  546. if (base64.decode(channels[i]).toLowerCase() == paramaters.toLowerCase())
  547. return; //PM already opened, don't open another.
  548. channels.push(base64.encode(paramaters));
  549. saveChannels();
  550. drawChannels();
  551. }
  552. function partChannel(paramaters)
  553. {
  554. if (paramaters == "")
  555. {
  556. partChannel(getChannelDe());
  557. return;
  558. }
  559. if (paramaters.substr(0,1) != "#")
  560. {
  561. for (i in channels)
  562. {
  563. if (base64.decode(channels[i]) == paramaters)
  564. {
  565. if (getChannelDe() == paramaters)
  566. {
  567. channels.splice(i,1);
  568. selectChannel(i-1);
  569. }
  570. else
  571. {
  572. channels.splice(i,1);
  573. drawChannels();
  574. }
  575. saveChannels();
  576. return;
  577. }
  578. }
  579. if (paramaters.substr(0,1) != "@" && paramaters.substr(0,1) != "#")
  580. {
  581. paramaters = "@" + paramaters;
  582. partChannel(paramaters);
  583. }
  584. else
  585. {
  586. sendInternalMessage('<span style="color:#C73232;"> Part Error: I cannot part ' + paramaters + '. (You are not in it.)</span>');
  587. }
  588. }
  589. else
  590. sendInternalMessage('<span style="color:#C73232;"> Part Error: I cannot part ' + paramaters + '. (That is not an OmnomIRC channel.)</span>');
  591. }
  592. function parseCommand(message)
  593. {
  594. var command = message.split(" ")[0];
  595. var paramaters = message.substr(command.length+1).toLowerCase();
  596. switch(command)
  597. {
  598. case "j":
  599. case "join":
  600. joinChannel(paramaters);
  601. return true;
  602. case "q":
  603. case "query":
  604. openPMWindow(paramaters);
  605. return true;
  606. case "win":
  607. case "w":
  608. case "window":
  609. if (parseInt(paramaters) > channels.length || parseInt(paramaters) <= 0)
  610. sendInternalMessage('<span style="color:#C73232;"> Invalid window selection. Valid options: 1-'+channels.length+'</span>');
  611. else
  612. selectChannel(parseInt(paramaters)-1);
  613. return true;
  614. case "p":
  615. case "part":
  616. partChannel(paramaters);
  617. return true;
  618. case "test":
  619. sendInternalMessage(parent.Signature);
  620. return true;
  621. default:
  622. return false;
  623. }
  624. }
  625. //******************************
  626. // Commands End *
  627. //******************************
  628. //******************************
  629. // Dynamic Channels Start *
  630. //******************************
  631. function loadChannels()
  632. {
  633. if (document.cookie.indexOf("OmnomChannels") >= 0)
  634. {
  635. var moreChans = document.cookie.split(";")[0].replace(/^.*OmnomChannels=(.+?)|.*/, "\$1").split("%");
  636. for (i in moreChans)
  637. if (moreChans[i][0] != "#" && moreChans[i] != "")
  638. channels.push(moreChans[i]);
  639. }
  640. }
  641. function saveChannels()
  642. {
  643. var chanList = "";
  644. for (i in channels)
  645. {
  646. if (base64.decode(channels[i]).substr(0,1) != "#")
  647. {
  648. chanList = chanList + channels[i] + "%";
  649. }
  650. }
  651. chanList = chanList.substr(0,chanList.length-1);
  652. document.cookie = "OmnomChannels=" + chanList + ";expires=Sat, 20 Nov 2286 17:46:39 GMT;";
  653. }
  654. //******************************
  655. // Dynamic Channels End *
  656. //******************************
  657. function HTMLEncode(str) {
  658. var div = document.createElement('div');
  659. var text = document.createTextNode(str);
  660. div.appendChild(text);
  661. return div.innerHTML;
  662. }
  663. String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };