]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/xdomain.js
Add cross-domain /SAY.
[irc/quakenet/qwebirc.git] / js / ui / xdomain.js
1 qwebirc.xdomain.Poller = new Class({
2 initialize: function(callback) {
3 this._callback = callback;
4 this._poll.periodical(100, this);
5 this._lastValue = null;
6 this._counter = -1;
7 },
8 _poll: function() {
9 var value = window.location.href;
10 if(value === null || value === undefined || value == this._lastValue)
11 return;
12 this._lastValue = value;
13 var fragment = value.splitMax("#", 2)[1];
14
15 if(fragment === undefined || fragment.substr(0, 6) != "qwmsg:")
16 return;
17
18 var components = fragment.substr(6).split(":", 3);
19 var counter = parseInt(components[0]);
20 if(counter <= this._counter)
21 return;
22
23 this._counter = counter;
24
25 var len = parseInt(components[1]);
26 var message = decodeURIComponent(components[2]);
27 if(len != message.length)
28 return;
29
30 message = message.replaceAll("\000", "").replaceAll("\n", "").replaceAll("\r", "");
31 this._callback(message);
32 }
33 });