Omnom_Parser.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  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. (function(window,undefined){
  16. document.domain=HOSTNAME;
  17. var messageList = [],
  18. UserListArr = [],
  19. curLine = 0,
  20. //messageBox = document.getElementById("MessageBox");
  21. messageBox = window.messageBox = document.createElement("table"),
  22. mBoxCont = window.mBoxCont = document.getElementById("mboxCont"),
  23. Userlist = [],
  24. scrolledDown = true,
  25. statusTxt = "",
  26. statusStarted = false,
  27. focusHandlerRegistered = false,
  28. userListContainer = document.getElementById("UserListArrContainer"),
  29. userListDiv = document.getElementById("UserList"),
  30. xmlhttp,
  31. inRequest = false,
  32. errorCount = 0;
  33. messageBox.style.width="100%";
  34. messageBox.style.height="100%";
  35. messageBox.className='MessageBox';
  36. //******************************
  37. // Start Request Loop functions*
  38. //******************************
  39. function startLoop(){
  40. xmlhttp=getAjaxObject();
  41. if (xmlhttp===null) {
  42. alert ("Your browser does not support AJAX! Please update for OmnomIRC compatibility.");
  43. return;
  44. }
  45. xmlhttp.onreadystatechange=getIncomingLine;
  46. sendRequest();
  47. }
  48. function cancelRequest(){
  49. xmlhttp.abort();
  50. inRequest = false;
  51. }
  52. function sendRequest(){
  53. if(inRequest){
  54. return;
  55. }
  56. var url = "Update.php?lineNum=" + curLine + "&channel=" + getChannelEn() + "&nick=" + base64.encode(userName) + "&signature=" + base64.encode(Signature);
  57. xmlhttp.open("GET",url,true);
  58. if(isBlurred()){
  59. setTimeout(function(){
  60. xmlhttp.send(null);
  61. },2500); //Only query every 2.5 seconds maximum if not foregrounded.
  62. }else{
  63. setTimeout(function(){
  64. xmlhttp.send(null);
  65. },75); //Wait for everything to get parsed before requesting again.
  66. }
  67. inRequest = true;
  68. }
  69. function getIncomingLine(){
  70. if(xmlhttp.readyState==4 || xmlhttp.readyState=="complete"){
  71. inRequest = false;
  72. if(xmlhttp.responseText == "Could not connect to SQL DB." || xmlhttp.status != 200){
  73. errorCount++;
  74. if(errorCount == 10){
  75. OmnomIRC_Error("OmnomIRC has lost connection to server. Please refresh to reconnect.");
  76. return;
  77. }else{
  78. sendRequest();
  79. return;
  80. }
  81. }
  82. if(xmlhttp.status == 200){
  83. addLines(xmlhttp.responseText); //Filter out 500s from timeouts
  84. }
  85. errorCount = 0;
  86. sendRequest();
  87. }
  88. }
  89. function getAjaxObject(){
  90. xmlhttp=new XMLHttpRequest(); //Decent Browsers
  91. if(!xmlhttp || xmlhttp === undefined || xmlhttp === null){
  92. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); //IE7+
  93. }
  94. if(!xmlhttp || xmlhttp === undefined || xmlhttp === null){
  95. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE6-
  96. }
  97. return xmlhttp;
  98. }
  99. //******************************
  100. // End Request Loop functions *
  101. //******************************
  102. //******************************
  103. // Start Parser *
  104. //******************************
  105. function addLines(message){
  106. var parts = message.split("\n");
  107. for (var i=0;i<parts.length;i++){
  108. if (parts[i].length > 2){
  109. addLine(parts[i]);
  110. }
  111. }
  112. }
  113. var addLine = window.addLine = function(message){
  114. if(!message || message === null || message === undefined){
  115. return;
  116. }
  117. var lnNum = parseInt(message.split(":")[0]);
  118. curLine = parseInt(curLine);
  119. if (lnNum > curLine){
  120. curLine = lnNum;
  121. }
  122. var doScroll = false;
  123. if(mBoxCont.clientHeight + mBoxCont.scrollTop > mBoxCont.scrollHeight - 50){
  124. doScroll = true;
  125. }
  126. //messageBox = document.getElementById("MessageBox");
  127. /*
  128. 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.)
  129. mBoxCont.innerHTML = '<table style="width:100%" class="messageBox" id="MessageBox">' + messageBox.innerHTML + parseMessage(message) + '</table>';
  130. else //If not IE, yay!
  131. messageBox.innerHTML = messageBox.innerHTML + parseMessage(message);*/
  132. var row = parseMessage(message);
  133. if(row){
  134. messageBox.appendChild(row);
  135. }
  136. if(doScroll){
  137. mBoxCont.scrollTop = mBoxCont.scrollHeight + 50;
  138. }
  139. };
  140. function parseMessage(message){ //type of message
  141. var //a = message,
  142. parts = message.split(":"),
  143. //lnumber = parts[0],
  144. type = parts[1],
  145. online = parts[2],
  146. parsedMessage = "",
  147. i;
  148. for(i = 4;i < parts.length;i++){
  149. parts[i] = base64.decode(parts[i]);
  150. }
  151. name = clickable_names(parts[4],online);
  152. var undefined;
  153. if(parts[5] === undefined || parts[5] === ""){
  154. parts[5] = " ";
  155. }
  156. if(parts[5] !== undefined && parts[5] !== null){
  157. parsedMessage = parseColors(parts[5]);
  158. if(parts[5].toLowerCase().indexOf(userName.toLowerCase().substr(0,4)) >= 0 && hasLoaded && notifications && parts[4].toLowerCase() != "new"){
  159. showNotification("<" + parts[4] + "> " + parts[5]);
  160. if(highDing){
  161. document.getElementById('ding').play();
  162. }
  163. }
  164. }
  165. if((type == "message" || type == "action") && parts[4].toLowerCase() != "new"){
  166. parsedMessage = parseHighlight(parsedMessage);
  167. }
  168. retval = "";
  169. displayMessage = true;
  170. var tdTime = document.createElement('td');
  171. tdTime.className="irc-date";
  172. var tdName = document.createElement('td');
  173. tdName.className="name";
  174. tdName.innerHTML = '*';
  175. var tdMessage = document.createElement('td');
  176. tdMessage.className=type;
  177. switch(type){
  178. case "reload":
  179. startIndicator();
  180. cancelRequest();
  181. hasLoaded = false;
  182. scrolledDown = true;
  183. curLine = 0;
  184. UserListArr = [];
  185. userListDiv.innerHTML = "";
  186. drawChannels();
  187. var body= document.getElementsByTagName('body')[0],
  188. script= document.createElement('script');
  189. script.type= 'text/javascript';
  190. script.src= 'Load.php?count=125&channel=' + getChannelEn() + "&nick=" + base64.encode(userName) + "&signature=" + base64.encode(Signature) + "&time=" + (new Date).getTime();;
  191. script.onload= function(){
  192. parseUsers();
  193. startLoop();
  194. mBoxCont.scrollTop = mBoxCont.scrollHeight;
  195. hasLoaded = true;
  196. stopIndicator();
  197. };
  198. body.appendChild(script);
  199. displayMessage = false;
  200. break;
  201. case "join":
  202. tdMessage.innerHTML = name + " has joined "+getChannelDe();
  203. addUserJoin(parts[4],online);
  204. if (online == "1"){
  205. return "";
  206. }
  207. break;
  208. case "part":
  209. tdMessage.innerHTML = name + " has left "+getChannelDe()+" (" + parsedMessage + ")";
  210. removeUser(parts[4]);
  211. if (online == "1"){
  212. return "";
  213. }
  214. break;
  215. case "quit":
  216. tdMessage.innerHTML = name + " has quit IRC (" + parsedMessage + ")";
  217. removeUser(parts[4]);
  218. break;
  219. case "kick":
  220. tdMessage.innerHTML = name + " has kicked " + parts[5] + " from "+getChannelDe()+" (" + parts[6] + ")";
  221. removeUser(parts[4]);
  222. break;
  223. case "message":
  224. tdName.innerHTML = name;
  225. tdMessage.innerHTML = parsedMessage;
  226. break;
  227. case "action":
  228. tdMessage.innerHTML = name + " " + parsedMessage;
  229. break;
  230. case "mode":
  231. tdMessage.innerHTML = name + " set "+getChannelDe()+" mode " + parts[5];
  232. break;
  233. case "nick":
  234. tdMessage.innerHTML = name + " has changed his nick to " + parsedMessage;
  235. removeUser(parts[4]);
  236. addUserJoin(parts[5],online);
  237. break;
  238. case "topic":
  239. if(name!=="" && name!="undefined" && name!=" " && (typeof name != 'undefined')){
  240. tdMessage.innerHTML = name + " has changed the topic to " + parsedMessage;
  241. }else{
  242. displayMessage = false;
  243. }
  244. setTopic(parsedMessage);
  245. break;
  246. case "internal":
  247. tdMessage.innerHTML = parts[4];
  248. break;
  249. case "server":
  250. tdMessage.innerHTML = parsedMessage;
  251. break;
  252. case "pm":
  253. if (getChannelDe().toLowerCase() != ("*" + parts[4]).toLowerCase() && parts[4] != userName){//Not in the PM window
  254. if (!hasLoaded){
  255. return "";
  256. }
  257. tdMessage.innerHTML = parsedMessage;
  258. tdName.innerHTML = "(PM)" + name;
  259. if (hasLoaded){
  260. openPMWindow(parts[4]);
  261. if(notifications){
  262. showNotification("(PM) <" + parts[4] + "> " + parts[5]);
  263. }
  264. if(highDing){
  265. document.getElementById('ding').play();
  266. }
  267. document.getElementById("*" + parts[4]).style.color="#C22";
  268. }
  269. }else{
  270. tdMessage.className="message";
  271. tdMessage.innerHTML = parsedMessage; //In the PM window
  272. tdName.innerHTML = name;
  273. }
  274. break;
  275. case "curline":
  276. return "";
  277. case "highlight":
  278. if (parts[6].toLowerCase() == "new") return "";
  279. //document.getElementById(parts[4]).style.color="#C22"; //This call will fail if they aren't in the chan. Crude, but effective.
  280. if (notifications)
  281. showNotification("(" + parts[4] + ") <" + parts[6] + "> " + parts[7]);
  282. if (highDing)
  283. document.getElementById('ding').play();
  284. return "";
  285. case "default":
  286. return "";
  287. }
  288. var row = document.createElement("tr");
  289. //pretag = '<tr style="width:100%;">';
  290. doHigh = !doHigh;
  291. if (lineHigh && doHigh && displayMessage){
  292. //pretag = '<tr style="width:100%;" class="linehigh">';
  293. row.className = "linehigh";
  294. }
  295. doLineHigh = !doLineHigh;
  296. if (type != "internal"){
  297. d = new Date(parts[3]*1000);
  298. }
  299. if (type == "internal"){
  300. d = new Date();
  301. }
  302. tdTime.innerHTML = '[' + d.toLocaleTimeString() + ']';
  303. tdTime.style.height="1px";
  304. tdName.style.height="1px";
  305. tdMessage.style.height="1px";
  306. if(showTime){
  307. row.appendChild(tdTime);
  308. }
  309. row.appendChild(tdName);
  310. row.appendChild(tdMessage);
  311. row.style.width="100%";
  312. row.style.height="1px";
  313. refreshThis(row);
  314. if(tdName.innerHTML == "*"){
  315. statusTxt = tdName.innerHTML + " ";
  316. }else{
  317. statusTxt = "<" + StripHTML(tdName.innerHTML) + "> ";
  318. }
  319. if (showTime){
  320. statusTxt = "[" + d.toLocaleTimeString() + "] " + statusTxt;
  321. }
  322. statusTxt = statusTxt + StripHTML(tdMessage.innerHTML);
  323. changeStatusBarText(statusTxt);
  324. if(displayMessage){
  325. return row;
  326. }else{
  327. return;
  328. }
  329. }
  330. function fixMBoxContHeight(){
  331. mBoxCont.scrollTop = mBoxCont.scrollHeight;
  332. }
  333. function parseSmileys(s){ //smileys
  334. if (showSmileys) {
  335. var addStuff = "";
  336. if (scrolledDown)
  337. addStuff = "onload='fixMBoxContHeight();'";
  338. s = s.replace(/(^| )(::\)|::-\))/g,"$1<img src='smileys/rolleyes.gif' alt='Roll Eyes' "+addStuff+">");
  339. s = s.replace(/(^| )(:\)|:-\))/g,"$1<img src='smileys/smiley.gif' alt='smiley' "+addStuff+">");
  340. s = s.replace(/(^| )(;\)|;-\))/g,"$1<img src='smileys/wink.gif' alt='Wink' "+addStuff+">");
  341. s = s.replace(/(^| )(&gt;:D|&gt;:-D)/g,"$1<img src='smileys/evil.gif' alt='Evil' "+addStuff+">");
  342. s = s.replace(/(^| )(:D|:-D)/g,"$1<img src='smileys/cheesy.gif' alt='Cheesy' "+addStuff+">");
  343. s = s.replace(/(^| )(;D|;-D)/g,"$1<img src='smileys/grin.gif' alt='Grin' "+addStuff+">");
  344. s = s.replace(/(^| )(&gt;:\(|&gt;:-\()/g,"$1<img src='smileys/angry.gif' alt='Angry' "+addStuff+">");
  345. s = s.replace(/(^| )(:\(|:-\()/g,"$1<img src='smileys/sad.gif' alt='Sad' "+addStuff+">");
  346. s = s.replace(/(^| )(:o|:O|:-o|:-O)/g,"$1<img src='smileys/shocked.gif' alt='Shocked' "+addStuff+">");
  347. s = s.replace(/(^| )(8\))/g,"$1<img src='smileys/cool.gif' alt='Cool' "+addStuff+">");
  348. s = s.replace(/(^| )\?\?\?/g,"$1<img src='smileys/huh.gif' alt='Huh' "+addStuff+">");
  349. s = s.replace(/(^| )(:P|:-P|:p|:-p)/g,"$1<img src='smileys/tongue.gif' alt='Tongue' "+addStuff+">");
  350. s = s.replace(/(^| )(:\[|:-\[)/g,"$1<img src='smileys/embarrassed.gif' alt='Embarrassed' "+addStuff+">");
  351. s = s.replace(/(^| )(:x|:-x|:X|:-X)/g,"$1<img src='smileys/lipsrsealed.gif' alt='Lips Sealed' "+addStuff+">");
  352. s = s.replace(/(^| )(:\\|:-\\)/g,"$1<img src='smileys/undecided.gif' alt='Undecided' "+addStuff+">");
  353. s = s.replace(/(^| ):-\*/g,"$1<img src='smileys/kiss.gif' alt='Kiss' "+addStuff+">");
  354. s = s.replace(/(^| )(:'\(|:'-\()/g,"$1<img src='smileys/cry.gif' alt='Cry' "+addStuff+">");
  355. s = s.replace(/:thumbsup:/g,"<img src='smileys/thumbsupsmiley.gif' alt='Thumbs Up' "+addStuff+">");
  356. s = s.replace(/(^| )O\.O/g,"$1<img src='smileys/shocked2.gif' alt='Shocked' "+addStuff+">");
  357. s = s.replace(/(^| )\^-\^/g,"$1<img src='smileys/azn.gif' alt='Azn' "+addStuff+">");
  358. s = s.replace(/(^| )&gt;B\)/g,"$1<img src='smileys/alien2.gif' alt='Alien' "+addStuff+">");
  359. s = s.replace(/(:banghead:|:headbang:)/g,"<img src='smileys/banghead.gif' alt='Bandhead' "+addStuff+">");
  360. s = s.replace(/:angel:/g,"<img src='smileys/ange.gif' alt='Angel' "+addStuff+">");
  361. s = s.replace(/(^| )\._\./g,"$1<img src='smileys/blah.gif' alt='Blah' "+addStuff+">");
  362. s = s.replace(/:devil:/g,"<img src='smileys/devil.gif' alt='Devil' "+addStuff+">");
  363. s = s.replace(/(^| )&lt;_&lt;/g,"$1<img src='smileys/dry.gif' alt='Dry' "+addStuff+">");
  364. s = s.replace(/:evillaugh:/g,"<img src='smileys/evillaugh.gif' alt='Evil Laugh' "+addStuff+">");
  365. s = s.replace(/:crazy:/g,"<img src='smileys/fou.gif' alt='Crazy' "+addStuff+">");
  366. s = s.replace(/:hyper:/g,"<img src='smileys/happy0075.gif' alt='Hyper' "+addStuff+">");
  367. s = s.replace(/:love:/g,"<img src='smileys/love.gif' alt='Love' "+addStuff+">");
  368. s = s.replace(/:mad:/g,"<img src='smileys/mad.gif' alt='Mad' "+addStuff+">");
  369. s = s.replace(/:w00t:/g,"<img src='smileys/smiley_woot.gif' alt='w00t' "+addStuff+">");
  370. s = s.replace(/(^| )\*\.\*/g,"$1<img src='smileys/psychedelicO_O.gif' alt='O.O.O' "+addStuff+">");
  371. s = s.replace(/(^| )D:/g,"$1<img src='smileys/bigfrown.gif' alt='Big Frown' "+addStuff+">");
  372. s = s.replace(/(^| )(XD|xD)/g,"$1<img src='smileys/XD.gif' alt='XD' "+addStuff+">");
  373. s = s.replace(/(^| )x\.x/g,"$1<img src='smileys/X_X.gif' alt='x.x' "+addStuff+">");
  374. s = s.replace(/:ninja:/g,"<img src='smileys/ninja.gif' alt='Ninja' "+addStuff+">");
  375. }
  376. return s;
  377. }
  378. function parseColors(colorStr){ //colors
  379. if (!colorStr || colorStr === null || colorStr === undefined){
  380. return;
  381. }
  382. colorStr = clickable_links(colorStr);
  383. colorStr = parseSmileys(colorStr);
  384. //lcount = 0;
  385. //a = colorStr;
  386. var arrayResults = [],
  387. isBool = false,
  388. numSpan = 0,
  389. isItalic = false,
  390. isUnderline = false,
  391. s,
  392. colorStrTemp = "1,0";
  393. colorStr+="\x0f";
  394. arrayResults = colorStr.split(RegExp("([\x02\x03\x0f\x16\x1d\x1f])"));
  395. colorStr="";
  396. for(var i=0;i<arrayResults.length;i++){
  397. switch (arrayResults[i]){
  398. case "\x03":
  399. for(var j=0;j<numSpan;j++){
  400. colorStr+="</span>";
  401. }
  402. numSpan=1;
  403. i++;
  404. colorStrTemp = arrayResults[i];
  405. s=arrayResults[i].replace(/^([0-9]{1,2}),([0-9]{1,2})/g,"<span class=\"fg-$1\"><span class=\"bg-$2\">");
  406. if(s==arrayResults[i]){
  407. s=arrayResults[i].replace(/^([0-9]{1,2})/g,"<span class=\"fg-$1\">");
  408. }else{
  409. numSpan++;
  410. }
  411. colorStr+=s;
  412. break;
  413. case "\x02":
  414. isBool = !isBool;
  415. if(isBool){
  416. colorStr+="<b>";
  417. }else{
  418. colorStr+="</b>";
  419. }
  420. break;
  421. case "\x1d":
  422. isItalic = !isItalic;
  423. if(isItalic){
  424. colorStr+="<i>";
  425. }else{
  426. colorStr+="</i>";
  427. }
  428. break;
  429. case "\x16":
  430. for(j=0;j<numSpan;j++){
  431. colorStr+="</span>";
  432. }
  433. numSpan=2;
  434. var stemp;
  435. s=colorStrTemp.replace(/^([0-9]{1,2}),([0-9]{1,2}).+/g,"<span class=\"fg-$2\"><span class=\"bg-$1\">");
  436. stemp=colorStrTemp.replace(/^([0-9]{1,2}),([0-9]{1,2}).+/g,"$2,$1");
  437. if(s==colorStrTemp){
  438. s=colorStrTemp.replace(/^([0-9]{1,2}).+/g,"<span class=\"fg-0\"><span class=\"bg-$1\">");
  439. stemp=colorStrTemp.replace(/^([0-9]{1,2}).+/g,"0,$1");
  440. }
  441. colorStrTemp = stemp;
  442. colorStr+=s;
  443. break;
  444. case "\x1f":
  445. isUnderline = !isUnderline;
  446. if(isUnderline){
  447. colorStr+="<u>";
  448. }else{
  449. colorStr+="</u>";
  450. }
  451. break;
  452. case "\x0f":
  453. if(isUnderline){
  454. colorStr+="</u>";
  455. isUnderline=false;
  456. }
  457. if(isItalic){
  458. colorStr+="</i>";
  459. isItalic=false;
  460. }
  461. if(isBool){
  462. colorStr+="</b>";
  463. isBool = false;
  464. }
  465. for(j=0;j<numSpan;j++){
  466. colorStr+="</span>";
  467. }
  468. numSpan=0;
  469. break;
  470. default:
  471. colorStr+=arrayResults[i];
  472. }
  473. }
  474. /*Strip codes*/
  475. colorStr = colorStr.replace(/(\x03|\x02|\x1F|\x09|\x0F)/g,"");
  476. return(colorStr);
  477. }
  478. function parseHighlight(text){ //highlight
  479. if (text.toLowerCase().indexOf(userName.toLowerCase().substr(0,4)) >= 0){
  480. var style = "";
  481. if(highRed){
  482. style = style + "color:#C73232;";
  483. }
  484. if(highBold){
  485. style = style + "font-weight:bold;";
  486. }
  487. return '<span class="highlight" style="' + style + '">' + text + "</span>";
  488. }
  489. return text;
  490. }
  491. function clickable_links(text){ //urls
  492. if (!text || text === null || text === undefined){
  493. return;
  494. }
  495. //text = text.replace(/http:\/\/www\.omnimaga\.org\//g,"h111://www.omnimaga.org/");
  496. //text = text.replace(/http:\/\/ourl\.ca\//g,"h111://ourl.ca/");
  497. //text = text.replace(/((h111:\/\/(www\.omnimaga\.org\/|ourl\.ca))[-a-zA-Z0-9@:;%_+.~#?&//=]+)/, '<a target="_top" href="$1">$1</a>');
  498. text = text.replace(RegExp("(^|.)(((f|ht)(tp|tps):\/\/)[^\\s\x02\x03\x0f\x16\x1d\x1f]*)","g"),'$1<a target="_blank" href="$2">$2</a>');
  499. text = text.replace(RegExp("(^|\\s)(www\.[^\\s\x02\x03\x0f\x16\x1d\x1f]*)","g"),'$1<a target="_blank" href="http://$2">$2</a>');
  500. //text = text.replace(/h111/g,"http");
  501. return text;
  502. }
  503. function clickable_names(name,isOnline){ //omnomirc names
  504. if (isOnline == "1"){
  505. return '<a target="_top" href="http://www.omnimaga.org/index.php?action=ezportal;sa=page;p=13&userSearch=' + name + '">' + colored_names(name) + '</a>';
  506. }
  507. return colored_names(name);
  508. }
  509. function colored_names(name){ //colored neames (duh)
  510. if (!coloredNames){
  511. return name;
  512. }
  513. if (!name || name === null || name === undefined){
  514. return;
  515. }
  516. var rcolors = Array(19, 20, 22, 24, 25, 26, 27, 28, 29),
  517. sum = 0,
  518. i = 0;
  519. while (name[i]){
  520. sum += name.charCodeAt(i++);
  521. }
  522. sum %= 9;
  523. return '<span class="uName-'+rcolors[sum]+'">'+name+'</span>';
  524. }
  525. function refreshThis(elementOnShow){
  526. var msie = 'Microsoft Internet Explorer';
  527. var tmp = 0;
  528. if (navigator.appName == msie){
  529. tmp = elementOnShow.offsetTop + 'px';
  530. }else{
  531. tmp = elementOnShow.offsetTop;
  532. }
  533. }
  534. //******************************
  535. // End Parser *
  536. //******************************
  537. //******************************
  538. // Userlist Start *
  539. //******************************
  540. function addUser(user){
  541. UserListArr.push(user);
  542. }
  543. function addUserJoin(user,online){
  544. if(!hasLoaded) return;
  545. var userp = base64.encode(user) + ":" + online;
  546. UserListArr.push(userp);
  547. parseUsers();
  548. }
  549. function parseUsers(){
  550. if (!userListDiv || userListDiv == null){
  551. userListDiv = document.getElementById("UserList");
  552. }
  553. userText = "";
  554. i = 0;
  555. UserListArr.sort(
  556. function(a,b){
  557. var al = base64.decode(a).toLowerCase(),
  558. bl = base64.decode(b).toLowerCase();
  559. return al==bl?(a==b?0:a<b?-1:1):al<bl?-1:1;
  560. }
  561. );
  562. for (i=0;i<UserListArr.length;i++){
  563. parts = UserListArr[i].split(":");
  564. if (parts[1] == "0"){
  565. userText = userText + "#" + base64.decode(parts[0]) + "<br/>";
  566. }
  567. if(parts[1] == "1"){
  568. userText = userText + '<a target="_top" href="http://www.omnimaga.org/index.php?action=ezportal;sa=page;p=13&userSearch=' +base64.decode(parts[0]) +
  569. '"><img src="http://omnomirc.www.omnimaga.org/omni.png" alt="Omnimaga User" title="Omnimaga User" border=0 width=8 height=8 />' + base64.decode(parts[0]) + '</a><br/>';
  570. }
  571. if(parts[1] == "2"){
  572. userText = userText + "!" + base64.decode(parts[0]) + "<br/>";
  573. }
  574. }
  575. userText = userText + "<br/><br/>";
  576. userListDiv.innerHTML = userText;
  577. }
  578. function removeUser(user){
  579. if(!hasLoaded) return;
  580. for (var i in UserListArr){
  581. var parts = UserListArr[i].split(":");
  582. if (base64.decode(parts[0]) == user){
  583. UserListArr.splice(i,1);
  584. }
  585. }
  586. parseUsers();
  587. }
  588. //******************************
  589. // Userlist End *
  590. //******************************
  591. //******************************
  592. // Load Start *
  593. //******************************
  594. var load = window.load = function(){
  595. cookieLoad();
  596. lineHigh = getOption(6,"T") == "T";
  597. doHigh = false;
  598. coloredNames = getOption(3,"F") == "T";
  599. highRed = getOption(2,"T") == "T";
  600. highBold = getOption(1,"T") == "T";
  601. enabled = getOption(5,"T") == "T";
  602. notifications = getOption(7,"F") == "T";
  603. highDing = getOption(8,"F") == "T";
  604. showExChans = getOption(9,"F") == "T";
  605. showTime = getOption(10,"F") == "T";
  606. doStatusUpdates = getOption(11,"T") == "T";
  607. showSmileys = getOption(12,"T") == "T";
  608. hasLoaded = false;
  609. if (!showSmileys){
  610. document.getElementById('smileyMenuButton').src='smileys/smiley_grey.png';
  611. document.getElementById('smileyMenuButton').style.cursor='default';
  612. }
  613. if (!enabled){
  614. mboxCont.appendChild(messageBox);
  615. messageBox.innerHTML = '<a href="#" onclick="toggleEnable();">OmnomIRC is disabled. Click here to enable.</a>';
  616. return false;
  617. }
  618. doLineHigh=true;
  619. var body= document.getElementsByTagName('body')[0];
  620. var chanScr= document.createElement('script');
  621. chanScr.type= 'text/javascript';
  622. chanScr.src= 'Channels.php';
  623. chanScr.onload= function(){
  624. channelSelectorCallback();
  625. readOldMessagesCookies();
  626. };
  627. body.appendChild(chanScr);
  628. chanList = document.getElementById('chanList');
  629. isBlurred();
  630. if (userName == "Guest"){
  631. var message = document.getElementById("message");
  632. message.disabled = "true";
  633. message.value = "You need to login if you want to chat!";
  634. }
  635. };
  636. //window.onLoad = load();
  637. //******************************
  638. // Load End *
  639. //******************************
  640. //******************************
  641. // Links Start *
  642. //******************************
  643. function toggleEnable(){
  644. setOption(5,!(getOption(5,'T') == 'T')?'T':'F');
  645. window.location.reload(true);
  646. }
  647. //******************************
  648. // Links End *
  649. //******************************
  650. //******************************
  651. // Message Send Start *
  652. //******************************
  653. var sendAJAXMessage = window.sendAJAXMessage = function(name,signature,message,chan){ //'chan' kept for legacy purposes.
  654. if (message[0] == "/"){
  655. if (parseCommand(message.substr(1)))
  656. return;
  657. }
  658. if (getChannelDe()[0] == "*"){
  659. var d = new Date(),
  660. str="0:pm:0:" + d.getTime()/1000 + ":" + base64.encode(name) + ":" + base64.encode(HTMLEncode(message)); //Print PMs locally.
  661. //addLine(str);
  662. }
  663. var xmlhttp2=new XMLHttpRequest();
  664. xmlhttp2.onreadyStateChange = function(){
  665. console.log(xmlhttp2.readyState,xmlhttp2.responseText);
  666. };
  667. xmlhttp2.open(
  668. "GET",
  669. "message.php?nick=" + base64.encode(name) + "&signature="+base64.encode(signature)+"&message=" + base64.encode(message) +"&channel=" + getChannelEn(),
  670. false
  671. );
  672. xmlhttp2.send(null);
  673. };
  674. //******************************
  675. // Message Send End *
  676. //******************************
  677. //******************************
  678. // Channel Selector Start *
  679. //******************************
  680. function channelSelectorCallback(){
  681. messageBox.cellPadding = "0px";
  682. messageBox.cellSpacing = "0px";
  683. if (showExChans){
  684. for (var i in exChannels){
  685. channels.push(exChannels[i]);
  686. }
  687. }
  688. /*if (moreChans)
  689. for(i in moreChans)
  690. channels.push(base64.encode(moreChans[i]));*/
  691. loadChannels(); //From cookies
  692. drawChannels();
  693. scrolledDown = true;
  694. var body= document.getElementsByTagName('body')[0];
  695. var script= document.createElement('script');
  696. script.type= 'text/javascript';
  697. script.src= 'Load.php?count=125&channel=' + getChannelEn() + "&nick=" + base64.encode(userName) + "&signature=" + base64.encode(Signature) + "&time=" + (new Date).getTime();
  698. script.onload= function(){
  699. mBoxCont.appendChild(messageBox);
  700. parseUsers();
  701. startLoop();
  702. mBoxCont.scrollTop = mBoxCont.scrollHeight;
  703. hasLoaded = true;stopIndicator();
  704. };
  705. body.appendChild(script);
  706. }
  707. function changeChannel(){
  708. //Empty out dirty holders
  709. cancelRequest();
  710. startIndicator();
  711. mBoxCont.innerHTML = '';
  712. messageBox = document.createElement("table");
  713. messageBox.className='MessageBox';
  714. messageBox.style.width="100%";
  715. messageBox.style.height="100%";
  716. messageBox.cellPadding = "0px";
  717. messageBox.cellSpacing = "0px";
  718. hasLoaded = false;
  719. scrolledDown = true;
  720. curLine = 0;
  721. UserListArr = [];
  722. userListDiv.innerHTML = "";
  723. drawChannels();
  724. var body= document.getElementsByTagName('body')[0],
  725. script= document.createElement('script');
  726. script.type= 'text/javascript';
  727. script.src= 'Load.php?count=125&channel=' + getChannelEn() + "&nick=" + base64.encode(userName) + "&signature=" + base64.encode(Signature) + "&time=" + (new Date).getTime();;
  728. script.onload= function(){mBoxCont.appendChild(messageBox);parseUsers();startLoop();mBoxCont.scrollTop = mBoxCont.scrollHeight;hasLoaded = true;stopIndicator();};
  729. body.appendChild(script);
  730. }
  731. function drawChannels(){
  732. "use strict";
  733. var table,
  734. td,
  735. span,
  736. span2,
  737. chanName,
  738. docfrag = document.createDocumentFragment(),
  739. chanList = document.getElementById("ChanList");
  740. for (var i in channels){
  741. // build elements/variables
  742. table = document.createElement('table');
  743. td = document.createElement('td');
  744. span = document.createElement('span');
  745. span2 = document.createElement('span');
  746. table.className = 'chanList';
  747. chanName = base64.decode(channels[i]);
  748. // Set properties/events
  749. td.id = chanName;
  750. td.className = (getChannelIndex()==i)?"curchan" :"chan";
  751. if (chanName.substr(0,1) != "#"){
  752. span.onclick = (function(name){
  753. return function(){
  754. partChannel(name);
  755. };
  756. })(chanName);
  757. span.onmouseover = function(){
  758. this.style.color = '#C73232';
  759. this.style.fontWeight = 'bolder';
  760. };
  761. span.onmouseout = (function(color){
  762. return function(){
  763. this.style.color = color;
  764. this.style.fontWeight = 'normal';
  765. };
  766. })((getChannelIndex()==i)?'#FFF':'#22C');
  767. span.innerHTML = 'x';
  768. td.appendChild(span);
  769. }
  770. span2.onclick = (function(i){
  771. return function(){
  772. selectChannel(i);
  773. };
  774. })(i);
  775. span2.innerHTML = chanName;
  776. // Append to DOM
  777. td.appendChild(span2);
  778. table.appendChild(td);
  779. docfrag.appendChild(table);
  780. }
  781. chanList.innerHTML = '';
  782. chanList.appendChild(docfrag);
  783. }
  784. function selectChannel(index){
  785. setOption(4,String.fromCharCode(index + 32),true);
  786. changeChannel();
  787. readOldMessagesCookies();
  788. }
  789. var getChannelEn = window.getChannelEn = function(){
  790. return channels[getChannelIndex()];
  791. };
  792. function getChannelDe(){
  793. return base64.decode(channels[getChannelIndex()]);
  794. }
  795. function getChannelIndex(){
  796. var index = getOption(4,String.fromCharCode(32)).charCodeAt(0) - 32;
  797. if (index > (channels.length - 1))
  798. index = 0;
  799. return index;
  800. }
  801. //******************************
  802. // Channel Selector End *
  803. //******************************
  804. //******************************
  805. // Tab Completion Start *
  806. //******************************
  807. var searchUser = window.searchUser = function(start,startAt){
  808. if(!startAt){
  809. startAt = 0;
  810. }
  811. for (var i=0;i<UserListArr.length;i++){
  812. var parts = UserListArr[i].split(":"),
  813. name = base64.decode(parts[0]).toLowerCase();
  814. if (name.indexOf(start.toLowerCase()) == 0 && startAt-- <= 0){
  815. return base64.decode(parts[0]);
  816. }
  817. }
  818. return start;
  819. };
  820. //******************************
  821. // Tab Completion End *
  822. //******************************
  823. //******************************
  824. // Commands Start *
  825. //******************************
  826. function setTopic(message){
  827. document.getElementById('topic').innerHTML = message;
  828. }
  829. function sendInternalMessage(message){
  830. var d = new Date(),
  831. str="0:internal:0:" + parseInt(d.getTime()*1000) + ":" + base64.encode(message);
  832. addLine(str);
  833. }
  834. function OmnomIRC_Error(message){
  835. sendInternalMessage('<span style="color:#C73232;">'+message+"</span>");
  836. }
  837. function joinChannel(paramaters){
  838. if (paramaters.substr(0,1) != "@" && paramaters.substr(0,1) != "#"){
  839. paramaters = "@" + paramaters;
  840. }
  841. //Check if it already exists or not. If so, try to join it.
  842. var count = 0;
  843. for (i in channels){
  844. if (base64.decode(channels[i]).toLowerCase() == paramaters.toLowerCase()){
  845. selectChannel(count);
  846. return;
  847. }
  848. count++;
  849. }
  850. //Channel not in existance.
  851. if (paramaters.substr(0,1) == "#"){
  852. sendInternalMessage('<span style="color:#C73232;"> Join Error: Cannot join new channels starting with #.</span>');
  853. return;
  854. }
  855. //Valid chan, add to list.
  856. channels.push(base64.encode(paramaters));
  857. saveChannels();
  858. selectChannel(channels.length-1);
  859. }
  860. function openPMWindow(paramaters){
  861. if (paramaters.substr(0,1) == "@" && paramaters.substr(0,1) == "#"){
  862. sendInternalMessage('<span style="color:#C73232;"> Query Error: Cannot query a channel. Use /join instead.</span>');
  863. }
  864. if (paramaters.substr(0,1) != "*"){
  865. paramaters = "*" + paramaters;
  866. }
  867. for (var i in channels){
  868. if (base64.decode(channels[i]).toLowerCase() == paramaters.toLowerCase()){
  869. return; //PM already opened, don't open another.
  870. }
  871. }
  872. channels.push(base64.encode(paramaters));
  873. saveChannels();
  874. drawChannels();
  875. }
  876. function partChannel(paramaters){
  877. if (paramaters === ""){
  878. partChannel(getChannelDe());
  879. return;
  880. }
  881. if (paramaters.substr(0,1) != "#"){
  882. for (var i in channels){
  883. if (base64.decode(channels[i]) == paramaters){
  884. if (getChannelDe() == paramaters){
  885. channels.splice(i,1);
  886. selectChannel(i-1);
  887. }else{
  888. channels.splice(i,1);
  889. drawChannels();
  890. }
  891. saveChannels();
  892. return;
  893. }
  894. }
  895. if (paramaters.substr(0,1) != "@" && paramaters.substr(0,1) != "#"){
  896. paramaters = "@" + paramaters;
  897. partChannel(paramaters);
  898. }else{
  899. sendInternalMessage('<span style="color:#C73232;"> Part Error: I cannot part ' + paramaters + '. (You are not in it.)</span>');
  900. }
  901. }else{
  902. sendInternalMessage('<span style="color:#C73232;"> Part Error: I cannot part ' + paramaters + '. (That is not an OmnomIRC channel.)</span>');
  903. }
  904. }
  905. function parseCommand(message){
  906. var command = message.split(" ")[0];
  907. var paramaters = message.substr(command.length+1).toLowerCase();
  908. switch(command){
  909. case "j": case "join":
  910. joinChannel(paramaters);
  911. return true;
  912. case "q": case "query":
  913. openPMWindow(paramaters);
  914. return true;
  915. case "win": case "w": case "window":
  916. if (parseInt(paramaters) > channels.length || parseInt(paramaters) <= 0)
  917. sendInternalMessage('<span style="color:#C73232;"> Invalid window selection. Valid options: 1-'+channels.length+'</span>');
  918. else
  919. selectChannel(parseInt(paramaters)-1);
  920. return true;
  921. case "p": case "part":
  922. partChannel(paramaters);
  923. return true;
  924. case "test":
  925. sendInternalMessage(Signature);
  926. return true;
  927. default:
  928. return false;
  929. }
  930. }
  931. //******************************
  932. // Commands End *
  933. //******************************
  934. //******************************
  935. // Dynamic Channels Start *
  936. //******************************
  937. function loadChannels(){
  938. if (document.cookie.indexOf("OmnomChannels") >= 0){
  939. var moreChans = document.cookie.split(";")[0].replace(/^.*OmnomChannels=(.+?)|.*/, "\$1").split("%");
  940. for (var i in moreChans){
  941. if (moreChans[i][0] != "#" && moreChans[i] !== ""){
  942. if (moreChans[i][0] == "^"){
  943. moreChans[i][0] = "#";
  944. }
  945. channels.push(moreChans[i]);
  946. }
  947. }
  948. }
  949. }
  950. function saveChannels(){
  951. var chanList = "";
  952. for(var i in channels){
  953. if (base64.decode(channels[i]).substr(0,1) != "#"){
  954. chanList = chanList + channels[i] + "%";
  955. }
  956. }
  957. chanList = chanList.substr(0,chanList.length-1);
  958. document.cookie = "OmnomChannels=" + chanList + ";expires=Sat, 20 Nov 2286 17:46:39 GMT;";
  959. }
  960. //******************************
  961. // Dynamic Channels End *
  962. //******************************
  963. //******************************
  964. // Focus Handler Start *
  965. //******************************
  966. function isBlurred() {
  967. if(focusHandlerRegistered === undefined){
  968. focusHandlerRegistered = false;
  969. }
  970. if(!focusHandlerRegistered){
  971. registerFocusHandler();
  972. }
  973. if(parent !== undefined){
  974. return parent.window.bIsBlurred;
  975. }else{
  976. return bIsBlurred;
  977. }
  978. }
  979. function registerFocusHandler() {
  980. focusHandlerRegistered = true;
  981. if (parent !== undefined){//Child(iframe)
  982. parent.window.bIsBlurred = false;
  983. parent.window.onblur = function(){
  984. parent.window.bIsBlurred = true;
  985. return true;
  986. };
  987. parent.window.onfocus= function(){
  988. parent.window.bIsBlurred=false;
  989. resize();
  990. return true;
  991. };
  992. }else{ //Not a child
  993. window.onblur = function(){
  994. bIsBlurred=true;
  995. if(console.log){
  996. console.log("Blur");
  997. }
  998. return true;
  999. };
  1000. window.onfocus= function(){
  1001. bIsBlurred=false;
  1002. resize();
  1003. if(console.log){
  1004. console.log("Focus");
  1005. }
  1006. return true;
  1007. };
  1008. }
  1009. }
  1010. //******************************
  1011. // Focus Handler End *
  1012. //******************************
  1013. //******************************
  1014. // Status Bar Updater Start *
  1015. //******************************
  1016. function startStatusBarUpdate(){
  1017. if (!doStatusUpdates) return;
  1018. if (!statusStarted)
  1019. setInterval(doStatusBarUpdate,500);
  1020. statusStarted = true;
  1021. }
  1022. function doStatusBarUpdate()
  1023. {
  1024. window.status=statusTxt;
  1025. if (parent)
  1026. parent.window.status=statusTxt;
  1027. }
  1028. function changeStatusBarText(msg){
  1029. statusTxt = msg;
  1030. if (!statusStarted){
  1031. startStatusBarUpdate();
  1032. }
  1033. }
  1034. //******************************
  1035. // Status Bar Updater End *
  1036. //******************************
  1037. //******************************
  1038. // HTML Tools Start *
  1039. //******************************
  1040. function HTMLEncode(str){
  1041. var div = document.createElement('div'),
  1042. text = document.createTextNode(str);
  1043. div.appendChild(text);
  1044. return div.innerHTML;
  1045. }
  1046. function StripHTML(str){
  1047. var tmp = document.createElement("div");
  1048. tmp.innerHTML = str;
  1049. return tmp.textContent||tmp.innerText;
  1050. }
  1051. String.prototype.trim = function(){
  1052. return this.replace(/^\s+|\s+$/g, "");
  1053. };
  1054. //******************************
  1055. // HTML Tools End *
  1056. //******************************
  1057. })(window);