omnomirc.old.js 42 KB

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