Omnom_Parser.js 34 KB

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