omnomirc.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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-"+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=" + 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. 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. 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 = 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 = parseColors(parts[5]);
  369. if(parts[5].toLowerCase().indexOf(userName.toLowerCase().substr(0,4)) >= 0 && hasLoaded && notifications && parts[4].toLowerCase() != "new"){
  370. 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 = 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. startIndicator();
  391. cancelRequest();
  392. hasLoaded = false;
  393. scrolledDown = true;
  394. curLine = 0;
  395. UserListArr = [];
  396. userListDiv.innerHTML = "";
  397. 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=' + getChannelEn() + "&nick=" + base64.encode(userName) + "&signature=" + base64.encode(Signature) + "&time=" + (new Date).getTime();;
  402. script.onload= function(){
  403. parseUsers();
  404. startLoop();
  405. mBoxCont.scrollTop = mBoxCont.scrollHeight;
  406. hasLoaded = true;
  407. stopIndicator();
  408. };
  409. body.appendChild(script);
  410. displayMessage = false;
  411. break;
  412. case "join":
  413. tdMessage.innerHTML = name + " has joined "+getChannelDe();
  414. addUserJoin(parts[4],online);
  415. if (online == "1"){
  416. return "";
  417. }
  418. break;
  419. case "part":
  420. tdMessage.innerHTML = name + " has left "+getChannelDe()+" (" + parsedMessage + ")";
  421. removeUser(parts[4]);
  422. if (online == "1"){
  423. return "";
  424. }
  425. break;
  426. case "quit":
  427. tdMessage.innerHTML = name + " has quit IRC (" + parsedMessage + ")";
  428. removeUser(parts[4]);
  429. break;
  430. case "kick":
  431. tdMessage.innerHTML = name + " has kicked " + parts[5] + " from "+getChannelDe()+" (" + parts[6] + ")";
  432. 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 "+getChannelDe()+" mode " + parts[5];
  443. break;
  444. case "nick":
  445. tdMessage.innerHTML = name + " has changed his nick to " + parsedMessage;
  446. removeUser(parts[4]);
  447. 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. 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 (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. openPMWindow(parts[4]);
  472. if(notifications){
  473. 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") return "";
  490. //document.getElementById(parts[4]).style.color="#C22"; //This call will fail if they aren't in the chan. Crude, but effective.
  491. if (notifications)
  492. showNotification("(" + parts[4] + ") <" + parts[6] + "> " + parts[7]);
  493. if (highDing)
  494. document.getElementById('ding').play();
  495. return "";
  496. case "default":
  497. return "";
  498. }
  499. var row = document.createElement("tr");
  500. //pretag = '<tr style="width:100%;">';
  501. doHigh = !doHigh;
  502. if (lineHigh && doHigh && displayMessage){
  503. //pretag = '<tr style="width:100%;" class="linehigh">';
  504. row.className = "linehigh";
  505. }
  506. doLineHigh = !doLineHigh;
  507. if (type != "internal"){
  508. d = new Date(parts[3]*1000);
  509. }
  510. if (type == "internal"){
  511. d = new Date();
  512. }
  513. tdTime.innerHTML = '[' + d.toLocaleTimeString() + ']';
  514. tdTime.style.height="1px";
  515. tdName.style.height="1px";
  516. tdMessage.style.height="1px";
  517. if(showTime){
  518. row.appendChild(tdTime);
  519. }
  520. row.appendChild(tdName);
  521. row.appendChild(tdMessage);
  522. row.style.width="100%";
  523. row.style.height="1px";
  524. refreshThis(row);
  525. if(tdName.innerHTML == "*"){
  526. statusTxt = tdName.innerHTML + " ";
  527. }else{
  528. statusTxt = "<" + StripHTML(tdName.innerHTML) + "> ";
  529. }
  530. if (showTime){
  531. statusTxt = "[" + d.toLocaleTimeString() + "] " + statusTxt;
  532. }
  533. statusTxt = statusTxt + StripHTML(tdMessage.innerHTML);
  534. changeStatusBarText(statusTxt);
  535. if(displayMessage){
  536. return row;
  537. }else{
  538. return;
  539. }
  540. },
  541. fixMBoxContHeight: function(){
  542. mBoxCont.scrollTop = mBoxCont.scrollHeight;
  543. },
  544. parseSmileys: function(s){ //smileys
  545. if (showSmileys) {
  546. var addStuff = "";
  547. if (scrolledDown)
  548. addStuff = "onload='fixMBoxContHeight();'";
  549. s = s.replace(/(^| )(::\)|::-\))/g,"$1<img src='smileys/rolleyes.gif' alt='Roll Eyes' "+addStuff+">");
  550. s = s.replace(/(^| )(:\)|:-\))/g,"$1<img src='smileys/smiley.gif' alt='smiley' "+addStuff+">");
  551. s = s.replace(/(^| )(;\)|;-\))/g,"$1<img src='smileys/wink.gif' alt='Wink' "+addStuff+">");
  552. s = s.replace(/(^| )(&gt;:D|&gt;:-D)/g,"$1<img src='smileys/evil.gif' alt='Evil' "+addStuff+">");
  553. s = s.replace(/(^| )(:D|:-D)/g,"$1<img src='smileys/cheesy.gif' alt='Cheesy' "+addStuff+">");
  554. s = s.replace(/(^| )(;D|;-D)/g,"$1<img src='smileys/grin.gif' alt='Grin' "+addStuff+">");
  555. s = s.replace(/(^| )(&gt;:\(|&gt;:-\()/g,"$1<img src='smileys/angry.gif' alt='Angry' "+addStuff+">");
  556. s = s.replace(/(^| )(:\(|:-\()/g,"$1<img src='smileys/sad.gif' alt='Sad' "+addStuff+">");
  557. s = s.replace(/(^| )(:o|:O|:-o|:-O)/g,"$1<img src='smileys/shocked.gif' alt='Shocked' "+addStuff+">");
  558. s = s.replace(/(^| )(8\))/g,"$1<img src='smileys/cool.gif' alt='Cool' "+addStuff+">");
  559. s = s.replace(/(^| )\?\?\?/g,"$1<img src='smileys/huh.gif' alt='Huh' "+addStuff+">");
  560. s = s.replace(/(^| )(:P|:-P|:p|:-p)/g,"$1<img src='smileys/tongue.gif' alt='Tongue' "+addStuff+">");
  561. s = s.replace(/(^| )(:\[|:-\[)/g,"$1<img src='smileys/embarrassed.gif' alt='Embarrassed' "+addStuff+">");
  562. s = s.replace(/(^| )(:x|:-x|:X|:-X)/g,"$1<img src='smileys/lipsrsealed.gif' alt='Lips Sealed' "+addStuff+">");
  563. s = s.replace(/(^| )(:\\|:-\\)/g,"$1<img src='smileys/undecided.gif' alt='Undecided' "+addStuff+">");
  564. s = s.replace(/(^| ):-\*/g,"$1<img src='smileys/kiss.gif' alt='Kiss' "+addStuff+">");
  565. s = s.replace(/(^| )(:'\(|:'-\()/g,"$1<img src='smileys/cry.gif' alt='Cry' "+addStuff+">");
  566. s = s.replace(/:thumbsup:/g,"<img src='smileys/thumbsupsmiley.gif' alt='Thumbs Up' "+addStuff+">");
  567. s = s.replace(/(^| )O\.O/g,"$1<img src='smileys/shocked2.gif' alt='Shocked' "+addStuff+">");
  568. s = s.replace(/(^| )\^-\^/g,"$1<img src='smileys/azn.gif' alt='Azn' "+addStuff+">");
  569. s = s.replace(/(^| )&gt;B\)/g,"$1<img src='smileys/alien2.gif' alt='Alien' "+addStuff+">");
  570. s = s.replace(/(:banghead:|:headbang:)/g,"<img src='smileys/banghead.gif' alt='Bandhead' "+addStuff+">");
  571. s = s.replace(/:angel:/g,"<img src='smileys/ange.gif' alt='Angel' "+addStuff+">");
  572. s = s.replace(/(^| )\._\./g,"$1<img src='smileys/blah.gif' alt='Blah' "+addStuff+">");
  573. s = s.replace(/:devil:/g,"<img src='smileys/devil.gif' alt='Devil' "+addStuff+">");
  574. s = s.replace(/(^| )&lt;_&lt;/g,"$1<img src='smileys/dry.gif' alt='Dry' "+addStuff+">");
  575. s = s.replace(/:evillaugh:/g,"<img src='smileys/evillaugh.gif' alt='Evil Laugh' "+addStuff+">");
  576. s = s.replace(/:crazy:/g,"<img src='smileys/fou.gif' alt='Crazy' "+addStuff+">");
  577. s = s.replace(/:hyper:/g,"<img src='smileys/happy0075.gif' alt='Hyper' "+addStuff+">");
  578. s = s.replace(/:love:/g,"<img src='smileys/love.gif' alt='Love' "+addStuff+">");
  579. s = s.replace(/:mad:/g,"<img src='smileys/mad.gif' alt='Mad' "+addStuff+">");
  580. s = s.replace(/:w00t:/g,"<img src='smileys/smiley_woot.gif' alt='w00t' "+addStuff+">");
  581. s = s.replace(/(^| )\*\.\*/g,"$1<img src='smileys/psychedelicO_O.gif' alt='O.O.O' "+addStuff+">");
  582. s = s.replace(/(^| )D:/g,"$1<img src='smileys/bigfrown.gif' alt='Big Frown' "+addStuff+">");
  583. s = s.replace(/(^| )(XD|xD)/g,"$1<img src='smileys/XD.gif' alt='XD' "+addStuff+">");
  584. s = s.replace(/(^| )x\.x/g,"$1<img src='smileys/X_X.gif' alt='x.x' "+addStuff+">");
  585. s = s.replace(/:ninja:/g,"<img src='smileys/ninja.gif' alt='Ninja' "+addStuff+">");
  586. }
  587. return s;
  588. },
  589. parseColors: function(colorStr){ //colors
  590. if (!colorStr || colorStr === null || colorStr === undefined){
  591. return;
  592. }
  593. colorStr = clickable_links(colorStr);
  594. colorStr = parseSmileys(colorStr);
  595. //lcount = 0;
  596. //a = colorStr;
  597. var arrayResults = [],
  598. isBool = false,
  599. numSpan = 0,
  600. isItalic = false,
  601. isUnderline = false,
  602. s,
  603. colorStrTemp = "1,0";
  604. colorStr+="\x0f";
  605. arrayResults = colorStr.split(RegExp("([\x02\x03\x0f\x16\x1d\x1f])"));
  606. colorStr="";
  607. for(var i=0;i<arrayResults.length;i++){
  608. switch (arrayResults[i]){
  609. case "\x03":
  610. for(var j=0;j<numSpan;j++){
  611. colorStr+="</span>";
  612. }
  613. numSpan=1;
  614. i++;
  615. colorStrTemp = arrayResults[i];
  616. s=arrayResults[i].replace(/^([0-9]{1,2}),([0-9]{1,2})/g,"<span class=\"fg-$1\"><span class=\"bg-$2\">");
  617. if(s==arrayResults[i]){
  618. s=arrayResults[i].replace(/^([0-9]{1,2})/g,"<span class=\"fg-$1\">");
  619. }else{
  620. numSpan++;
  621. }
  622. colorStr+=s;
  623. break;
  624. case "\x02":
  625. isBool = !isBool;
  626. if(isBool){
  627. colorStr+="<b>";
  628. }else{
  629. colorStr+="</b>";
  630. }
  631. break;
  632. case "\x1d":
  633. isItalic = !isItalic;
  634. if(isItalic){
  635. colorStr+="<i>";
  636. }else{
  637. colorStr+="</i>";
  638. }
  639. break;
  640. case "\x16":
  641. for(j=0;j<numSpan;j++){
  642. colorStr+="</span>";
  643. }
  644. numSpan=2;
  645. var stemp;
  646. s=colorStrTemp.replace(/^([0-9]{1,2}),([0-9]{1,2}).+/g,"<span class=\"fg-$2\"><span class=\"bg-$1\">");
  647. stemp=colorStrTemp.replace(/^([0-9]{1,2}),([0-9]{1,2}).+/g,"$2,$1");
  648. if(s==colorStrTemp){
  649. s=colorStrTemp.replace(/^([0-9]{1,2}).+/g,"<span class=\"fg-0\"><span class=\"bg-$1\">");
  650. stemp=colorStrTemp.replace(/^([0-9]{1,2}).+/g,"0,$1");
  651. }
  652. colorStrTemp = stemp;
  653. colorStr+=s;
  654. break;
  655. case "\x1f":
  656. isUnderline = !isUnderline;
  657. if(isUnderline){
  658. colorStr+="<u>";
  659. }else{
  660. colorStr+="</u>";
  661. }
  662. break;
  663. case "\x0f":
  664. if(isUnderline){
  665. colorStr+="</u>";
  666. isUnderline=false;
  667. }
  668. if(isItalic){
  669. colorStr+="</i>";
  670. isItalic=false;
  671. }
  672. if(isBool){
  673. colorStr+="</b>";
  674. isBool = false;
  675. }
  676. for(j=0;j<numSpan;j++){
  677. colorStr+="</span>";
  678. }
  679. numSpan=0;
  680. break;
  681. default:
  682. colorStr+=arrayResults[i];
  683. }
  684. }
  685. /*Strip codes*/
  686. colorStr = colorStr.replace(/(\x03|\x02|\x1F|\x09|\x0F)/g,"");
  687. return(colorStr);
  688. },
  689. parseHighlight: function(text){ //highlight
  690. if (text.toLowerCase().indexOf(userName.toLowerCase().substr(0,4)) >= 0){
  691. var style = "";
  692. if(highRed){
  693. style = style + "color:#C73232;";
  694. }
  695. if(highBold){
  696. style = style + "font-weight:bold;";
  697. }
  698. return '<span class="highlight" style="' + style + '">' + text + "</span>";
  699. }
  700. return text;
  701. },
  702. clickable_links: function(text){ //urls
  703. if (!text || text === null || text === undefined){
  704. return;
  705. }
  706. //text = text.replace(/http:\/\/www\.omnimaga\.org\//g,"h111://www.omnimaga.org/");
  707. //text = text.replace(/http:\/\/ourl\.ca\//g,"h111://ourl.ca/");
  708. //text = text.replace(/((h111:\/\/(www\.omnimaga\.org\/|ourl\.ca))[-a-zA-Z0-9@:;%_+.~#?&//=]+)/, '<a target="_top" href="$1">$1</a>');
  709. text = text.replace(RegExp("(^|.)(((f|ht)(tp|tps):\/\/)[^\\s\x02\x03\x0f\x16\x1d\x1f]*)","g"),'$1<a target="_blank" href="$2">$2</a>');
  710. text = text.replace(RegExp("(^|\\s)(www\.[^\\s\x02\x03\x0f\x16\x1d\x1f]*)","g"),'$1<a target="_blank" href="http://$2">$2</a>');
  711. //text = text.replace(/h111/g,"http");
  712. return text;
  713. },
  714. clickable_names: function(name,isOnline){ //omnomirc names
  715. if (isOnline == "1"){
  716. return '<a target="_top" href="http://www.omnimaga.org/index.php?action=ezportal;sa=page;p=13&userSearch=' + name + '">' + colored_names(name) + '</a>';
  717. }
  718. return colored_names(name);
  719. },
  720. colored_names: function(name){ //colored neames (duh)
  721. if (!coloredNames){
  722. return name;
  723. }
  724. if (!name || name === null || name === undefined){
  725. return;
  726. }
  727. var rcolors = Array(19, 20, 22, 24, 25, 26, 27, 28, 29),
  728. sum = 0,
  729. i = 0;
  730. while (name[i]){
  731. sum += name.charCodeAt(i++);
  732. }
  733. sum %= 9;
  734. return '<span class="uName-'+rcolors[sum]+'">'+name+'</span>';
  735. },
  736. refreshThis: function(elementOnShow){
  737. var msie = 'Microsoft Internet Explorer';
  738. var tmp = 0;
  739. if (navigator.appName == msie){
  740. tmp = elementOnShow.offsetTop + 'px';
  741. }else{
  742. tmp = elementOnShow.offsetTop;
  743. }
  744. },
  745. addUser: function(user){
  746. UserListArr.push(user);
  747. },
  748. addUserJoin: function(user,online){
  749. if(!hasLoaded) return;
  750. var userp = base64.encode(user) + ":" + online;
  751. UserListArr.push(userp);
  752. parseUsers();
  753. },
  754. parseUsers: function(){
  755. if (!userListDiv || userListDiv == null){
  756. userListDiv = document.getElementById("UserList");
  757. }
  758. userText = "";
  759. i = 0;
  760. UserListArr.sort(
  761. function(a,b){
  762. var al = base64.decode(a).toLowerCase(),
  763. bl = base64.decode(b).toLowerCase();
  764. return al==bl?(a==b?0:a<b?-1:1):al<bl?-1:1;
  765. }
  766. );
  767. for (i=0;i<UserListArr.length;i++){
  768. parts = UserListArr[i].split(":");
  769. if (parts[1] == "0"){
  770. userText = userText + "#" + base64.decode(parts[0]) + "<br/>";
  771. }
  772. if(parts[1] == "1"){
  773. userText = userText + '<a target="_top" href="http://www.omnimaga.org/index.php?action=ezportal;sa=page;p=13&userSearch=' +base64.decode(parts[0]) +
  774. '"><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/>';
  775. }
  776. if(parts[1] == "2"){
  777. userText = userText + "!" + base64.decode(parts[0]) + "<br/>";
  778. }
  779. }
  780. userText = userText + "<br/><br/>";
  781. userListDiv.innerHTML = userText;
  782. },
  783. removeUser: function(user){
  784. if(!hasLoaded) return;
  785. for (var i in UserListArr){
  786. var parts = UserListArr[i].split(":");
  787. if (base64.decode(parts[0]) == user){
  788. UserListArr.splice(i,1);
  789. }
  790. }
  791. parseUsers();
  792. },
  793. load: function(){
  794. cookieLoad();
  795. lineHigh = getOption(6,"T") == "T";
  796. doHigh = false;
  797. coloredNames = getOption(3,"F") == "T";
  798. highRed = getOption(2,"T") == "T";
  799. highBold = getOption(1,"T") == "T";
  800. enabled = getOption(5,"T") == "T";
  801. notifications = getOption(7,"F") == "T";
  802. highDing = getOption(8,"F") == "T";
  803. showExChans = getOption(9,"F") == "T";
  804. showTime = getOption(10,"F") == "T";
  805. doStatusUpdates = getOption(11,"T") == "T";
  806. showSmileys = getOption(12,"T") == "T";
  807. hasLoaded = false;
  808. if (!showSmileys){
  809. document.getElementById('smileyMenuButton').src='smileys/smiley_grey.png';
  810. document.getElementById('smileyMenuButton').style.cursor='default';
  811. }
  812. if (!enabled){
  813. mboxCont.appendChild(messageBox);
  814. messageBox.innerHTML = '<a href="#" onclick="toggleEnable();">OmnomIRC is disabled. Click here to enable.</a>';
  815. return false;
  816. }
  817. doLineHigh=true;
  818. var body= document.getElementsByTagName('body')[0];
  819. var chanScr= document.createElement('script');
  820. chanScr.type= 'text/javascript';
  821. chanScr.src= 'Channels.php';
  822. chanScr.onload= function(){
  823. channelSelectorCallback();
  824. readOldMessagesCookies();
  825. };
  826. body.appendChild(chanScr);
  827. chanList = document.getElementById('chanList');
  828. isBlurred();
  829. if (userName == "Guest"){
  830. var message = document.getElementById("message");
  831. message.disabled = "true";
  832. message.value = "You need to login if you want to chat!";
  833. }
  834. },
  835. toggleEnable: function(){
  836. setOption(5,!(getOption(5,'T') == 'T')?'T':'F');
  837. window.location.reload(true);
  838. },
  839. sendAJAXMessage: function(name,signature,message,chan){ //'chan' kept for legacy purposes.
  840. if (message[0] == "/"){
  841. if (parseCommand(message.substr(1)))
  842. return;
  843. }
  844. if (getChannelDe()[0] == "*"){
  845. var d = new Date(),
  846. str="0:pm:0:" + d.getTime()/1000 + ":" + base64.encode(name) + ":" + base64.encode(HTMLEncode(message)); //Print PMs locally.
  847. //addLine(str);
  848. }
  849. var xmlhttp2=new XMLHttpRequest();
  850. xmlhttp2.onreadyStateChange = function(){
  851. console.log(xmlhttp2.readyState,xmlhttp2.responseText);
  852. };
  853. xmlhttp2.open(
  854. "GET",
  855. "message.php?nick=" + base64.encode(name) + "&signature="+base64.encode(signature)+"&message=" + base64.encode(message) +"&channel=" + getChannelEn(),
  856. false
  857. );
  858. xmlhttp2.send(null);
  859. },
  860. },
  861. message = document.getElementById("message"),
  862. isInTab = false,
  863. tabWord = "",
  864. tabCount = 0,
  865. startPos = 0,
  866. endPos = 0,
  867. endPosO = 0,
  868. indicatorTimer = false,
  869. oldMessages = [],
  870. messageCounter = 1,
  871. currentMessage,
  872. messageList = [],
  873. UserListArr = [],
  874. curLine = 0,
  875. messageBox = window.messageBox = document.createElement("table"),
  876. mBoxCont = window.mBoxCont = document.getElementById("mboxCont"),
  877. Userlist = [],
  878. scrolledDown = true,
  879. statusTxt = "",
  880. statusStarted = false,
  881. focusHandlerRegistered = false,
  882. userListContainer = document.getElementById("UserListArrContainer"),
  883. userListDiv = document.getElementById("UserList"),
  884. xmlhttp,
  885. inRequest = false,
  886. errorCount = 0;
  887. messageBox.style.width="100%";
  888. messageBox.style.height="100%";
  889. messageBox.className='MessageBox';
  890. window.addEventListener('keydown',function(e){
  891. if(document.activeElement.id=="message"){
  892. var messageBoxElement = document.getElementById("message");
  893. if(messageCounter==oldMessages.length){
  894. currentMessage=messageBoxElement.value;
  895. }
  896. if(oldMessages.length!==0) {
  897. if (e.keyCode==38) { //up
  898. if(messageCounter!==0){
  899. messageCounter--;
  900. }
  901. messageBoxElement.value = oldMessages[messageCounter];
  902. }else if(e.keyCode==40){ //down
  903. if (messageCounter!=oldMessages.length){
  904. messageCounter++;
  905. }
  906. if (messageCounter==oldMessages.length){
  907. messageBoxElement.value = currentMessage;
  908. }else{
  909. messageBoxElement.value = oldMessages[messageCounter];
  910. }
  911. }
  912. }
  913. }
  914. }, false);
  915. })(window);