var _poll; var _init = true; var _open = true; var _onli = 0; var _path; var _list; var _head; var _text; var _icon; var _user; var _xss_host; var _xss_channel = ''; var _xss_cookie = ''; function start(res, host, channel) { _path = res; _list = document.createElement('div'); _list.setAttribute('id', 'list'); _list.style.overflow = 'hidden'; _head = document.createElement('div'); _head.setAttribute('id', 'head'); _head.setAttribute('style', 'white-space: nowrap'); _head.style.overflow = 'hidden'; _text = document.createElement('input'); _text.setAttribute('id', 'text'); _text.setAttribute('type', 'text'); _text.setAttribute('maxlength', '160'); _text.onkeypress = function (event) { return enter(event); }; _text.style.width = '214px'; _icon = document.createElement('img'); _icon.setAttribute('src', _path + 'hide.gif'); _icon.setAttribute('height', '9'); _icon.setAttribute('width', '14'); _icon.onclick = function () { return toggle(); }; _icon.style.cursor = 'pointer'; _user = document.createElement('div'); _user.setAttribute('id', 'user'); _user.onclick = function () { return toggle(); }; _user.style.cursor = 'pointer'; _xss_host = host; if(channel) { _xss_channel = channel; } try { _xss_cookie = session(); } catch(e) { // if passive/old html } _poll = create(); do_poll(true); } function stop() { if(_poll) { _poll.abort(); } return disconnect(); } function toggle() { fix = document.getElementById('blob'); tog = document.getElementById('toggle'); if(_init) { _head.appendChild(_text); _head.appendChild(_icon); _init = false; } if(_open) { fix.style.width = '230px'; fix.style.height = '200px'; clear(tog); tog.appendChild(_head); tog.appendChild(_list); setTimeout(function() { _text.focus(); }, 10); _open = false; } else { fix.style.width = '40px'; fix.style.height = '30px'; clear(tog); tog.appendChild(_user); _open = true; } } function clear(element) { while(element.hasChildNodes()) { element.removeChild(element.firstChild); } } function update_user(users) { clear(_user); count = users.toString(10); //_user.appendChild(count); for(i = 0; i < count.length; i++) { _pict = document.createElement('img'); _pict.setAttribute('src', _path + count.charAt(i) + '.png'); _pict.style.styleFloat = 'left'; _pict.style.cssFloat = 'left'; _user.appendChild(_pict); } if(_open) { tog = document.getElementById('toggle'); tog.appendChild(_user); } if(_onli != users) { play('beep'); } _onli = users; } function enter(e) { var keycode; if(window.event) { keycode = window.event.keyCode; } else if (e) { keycode = e.which; } else { return true; } if(keycode == 13) { broadcast(); return false; } else { return true; } } var _poll_scri; var _broa_scri; function broadcast() { url = '/broadcast?cookie=' + _xss_cookie + '&time=' + new Date().getTime(); var element = document.getElementById('text'); var host = false; if(element.value != '') { url = url + '&text=' + encodeURIComponent(element.value); if(_xss_host) { _broa_scri = document.createElement("script"); _broa_scri.async = true; _broa_scri.src = 'http://' + _xss_host + url + '&xss=true'; document.getElementsByTagName("head")[0].appendChild(_broa_scri); } else { var req = create(); req.open('GET', url, true); req.onreadystatechange = function() { if(this.readyState == 4 && this.status != 200) alert(this.status + ' 1 ' + this.responseText); else element.value = ''; } req.send(''); } } } function message(message) { url = '/broadcast?cookie=' + _xss_cookie + '&time=' + new Date().getTime() + '&text=' + encodeURIComponent(message); if(_xss_host) { _broa_scri = document.createElement("script"); _broa_scri.async = true; _broa_scri.src = 'http://' + _xss_host + url + '&xss=true'; document.getElementsByTagName("head")[0].appendChild(_broa_scri); } else { var req = create(); req.open('GET', url, true); req.onreadystatechange = function() { if(this.readyState == 4 && this.status != 200) alert(this.status + ' 1 ' + this.responseText); } req.send(''); } } function disconnect() { var url = '/broadcast?cookie=' + _xss_cookie + '&time=' + new Date().getTime() + '&type=disconnect'; if(_xss_host) { var script = document.createElement("script"); script.async = true; script.src = 'http://' + _xss_host + url + '&xss=true'; document.getElementsByTagName("head")[0].appendChild(script); } else { var req = create(); req.open('GET', url, false); req.send(''); if(req.status != 200) { alert(url + ' ' + this.status + ' 2 ' + req.responseText); } } } function do_poll(page) { url = '/poll?cookie=' + _xss_cookie + '&time=' + new Date().getTime() + '&page=' + page + '&channel=' + _xss_channel + '&version=8'; if(_xss_host) { _poll_scri = document.createElement("script"); _poll_scri.async = true; _poll_scri.src = 'http://' + _xss_host + url + '&xss=true'; document.getElementsByTagName("head")[0].appendChild(_poll_scri); } else { _poll.abort(); _poll.open('GET', url, true); _poll.onreadystatechange = talkCallback; _poll.send(''); } } function finish_broadcast() { try { document.getElementsByTagName("head")[0].removeChild(_broa_scri); document.getElementById('text').value = ''; } catch(e) { // happens when spam filter is catching, dunno why! } } function handle_xss_reply(answer) { document.getElementsByTagName("head")[0].removeChild(_poll_scri); if(answer) { handle_reply(answer); } else { do_poll(false); } } function handle_reply(answer) { try { var list = document.getElementById('list'); var _play = false; if(answer.online) { update_user(answer.online); } if(answer.message && answer.message.length > 0) { for(i = 0; i < answer.message.length; i++) { if(!filter(answer.message[i])) { add('
 ' + answer.message[i].text + '
'); if(_list.childNodes.length > 20) { _list.removeChild(_list.lastChild); } if(answer.message[i].host) { _xss_host = answer.message[i].host; _xss_channel = answer.message[i].channel; } _play = true; } } if(!_open && _play) { play('select'); } } if(!list && _init && !answer.page && answer.message && answer.message.length > 0 && _play) { toggle(); } if(answer.cookie) { try { if(!_xss_cookie && !session()) { session(answer.cookie); } } catch(e) { // if passive/old html } _xss_cookie = answer.cookie; } } catch(e) { //alert(e + ' 3 ' + e.message); } if(answer.exit) { return; } do_poll(false); } function play(file) { try { sound = document.player; if(sound) { sound.SetVariable('/' + file + ':loopCount', 1); sound.TCallLabel('/' + file, 'start'); } } catch(e) { //alert(e); } } function add(message) { var html = _list.innerHTML; html = message + html; _list.innerHTML = html; } function talkCallback() { try { if(_poll.readyState == 4) { if(_poll.status == 200) { handle_reply(eval('(' + _poll.responseText + ')')); } else if(_poll.status == 500) { alert(_poll.responseText); } else if(_poll.status == 504) { do_poll(false); } } } catch(e) { //alert(_poll.responseText + ' 4 ' + e.message); } } function create() { try { return new XMLHttpRequest(); } catch (e) { try { return new ActiveXObject('microsoft.xmlhttp'); } catch (e) { try { return new ActiveXObject('msxml2.xmlhttp'); } catch (e) {} } } return null; }