/
make-js-interfaces.pl
969 lines (858 loc) · 24.9 KB
/
make-js-interfaces.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
for my $browser(qw/ie mozilla/) {
close(STDOUT);
open(STDOUT, ">$browser.pm");
print "package $browser;\n";
print q`
# NOTE -- This file is generated by running make-js-interfaces.pl
#
# PLEASE REMEMBER TO EDIT THAT NOT (ie|mozilla).pm FILE
# OK!
use strict;
use vars qw/@ISA $standardheader/;
$standardheader = <<EOF;
<!-- This is part of CGI:IRC 0.5
== http://cgiirc.sourceforge.net/
== Copyright (C) 2000-2002 David Leadbeater <cgiirc\@dgl.cx>
== Released under the GNU GPL
-->
EOF
use default;
@ISA = qw/default/;
my %colours = (
'00' => '#FFFFFF', '01' => '#000000', '02' => '#0000FF',
'03' => '#008000', '04' => '#FF0000', '05' => '#800000',
'06' => '#800080', '07' => '#FF6600', '08' => '#FFFF00',
'09' => '#00FF00', '10' => '#008080', '11' => '#00FFFF',
'12' => '#0000FF', '13' => '#FF00FF', '14' => '#808080',
'15' => '#C0C0C0');
sub new {
my($class,$event, $timer, $config, $icookies) = @_;
my $self = bless {}, $class;
my $tmp='';
for(keys %$icookies) {
$tmp .= "$_: " . _escapejs($icookies->{$_}) . ', ';
}
$tmp =~ s/, $//;
_out('parent.options = { ' . $tmp . '};');
$event->add('user add', code => \&useradd);
$event->add('user del', code => \&userdel);
$event->add('user change nick', code => \&usernick);
$event->add('user change', code => \&usermode);
$event->add('user self', code => \&mynick);
_out('parent.connected = 1;');
$self->add('Status', 0);
return $self;
}
sub end {
_out('parent.connected = 0;');
}
sub _out {
print "<script>$_[0]</script>\r\n";
}
sub _func_out {
my($func,@rest) = @_;
@rest = map(ref $_ eq 'ARRAY' ? _outputarray($_) : _escapejs($_), @rest);
_out('parent.' . $func . '(' . _jsp(@rest) . ');');
}
sub _escapejs {
my $in = shift;
return "''" unless defined $in;
$in =~ s/\\\\/\\\\\\\\/g;
$in =~ s/'/\\\\'/g;
return '\'' . $in . '\'';
}
sub _jsp {
return join(', ', @_);
}
sub _outputarray {
my $array = shift;
return '[' . _jsp(map(_escapejs($_), @$array)) . ']';
}
sub useradd {
my($event, $nicks, $channel) = @_;
_func_out('channeladdusers', $channel, $nicks);
}
sub userdel {
my($event, $nick, $channels) = @_;
_func_out('channelsdeluser', $channels, $nick);
}
sub usernick {
my($event,$old,$new,$channels) = @_;
_func_out('channelsusernick', $old, $new);
}
sub usermode {
my($event,$nick, $channel, $action, $type) = @_;
_func_out('channelusermode', $channel, $nick, $action, $type);
}
sub mynick {
my($event, $nick) = @_;
_func_out('mynick', $nick);
}
sub exists {
return 1 if defined &{__PACKAGE__ . '::' . $_[1]};
}
sub query {
return 1;
}
sub style {
open(STYLE, '<interfaces/style.css') or die("Error opening stylesheet: $!");
print <STYLE>;
close(STYLE);
}
sub line {
my($self, $info, $html) = @_;
my $target = defined $info->{target} ? $info->{target} : 'Status';
if(ref $target eq 'ARRAY') {
my %tmp = %$info;
for(@$target) {
$tmp{target} = $_;
$self->line(\%tmp, $html);
}
return;
}
if(not exists $self->{lc $target}) {
if(defined $info && ref $info && exists $info->{create} && $info->{create}) {
$self->add($target, $info->{type} eq 'join' ? 1 : 0);
}elsif($target ne '-all') {
$target = 'Status';
}
}
_func_out('witemaddtext', $target, $html . '<br>', $info->{activity} || 0);
`;
print " print \"<!-- padding for mozilla -->\\n\";\n" if $browser eq 'mozilla';
print q`
}
sub error {
my($self,$message) = @_;
$self->line({ target => 'Status'}, $message);
_func_out('disconnected');
}
sub add {
my($self,$add,$channel) = @_;
return if not defined $add;
$self->{lc $add}++;
_func_out('witemadd', $add, $channel);
_func_out('witemchg', $add) if $channel;
}
sub del {
my($self, $del) = @_;
return if not defined $del;
return if not exists $self->{lc $del};
_func_out('witemdel', $del);
delete($self->{$del});
}
sub clear {
my($self, $window) = @_;
_func_out('witemclear', $window);
}
sub active {
my($self, $window) = @_;
_func_out('witemchg', $window);
}
sub frameset {
my($self, $scriptname, $config, $random, $out, $interface) = @_;
print <<EOF;
$standardheader
<html>
<head>
<title>CGI:IRC</title>
<script language="JavaScript"><!--
function form_focus() {
if(document.frames && document.frames.fform)
document.frames.fform.fns();
}
//-->
</script>
</head>
<frameset rows="40,*,25,0" framespacing="0" border="0" frameborder="0"
onfocus="form_focus()" onload="form_focus()">
<frame name="fwindowlist" src="$scriptname?$out&item=fwindowlist" scrolling="no">
<frameset cols="*,120" framespacing="0" border="0" frameborder="0">
<frame name="fmain" src="$scriptname?item=fmain&interface=$interface" scrolling="yes">
<frame name="fuserlist" src="$scriptname?item=fuserlist&interface=$interface" scrolling="yes">
</frameset>
<frame name="fform" src="$scriptname?item=fform&interface=$interface" scrolling="no">
<frame name="hiddenframe" src="$scriptname?item=blank" scrolling="no">
<noframes>
This interface requires a browser that supports frames and javascript.
</noframes>
</frameset>
</html>
EOF
}
sub blank {
return '';
}
sub help {
my($self,$config) = @_;
_out("window.open('$config->{script_login}?item=uhelp&interface=`;print $browser;print q`');");
}
sub uhelp {
print <<EOF;
`;
open(HELP, "../docs/help.html") or die($!);
print <HELP>;
close(HELP);
print q`
EOF
}
sub fuserlist {
my($self, $cgi, $config) = @_;
print <<EOF;
$standardheader
<html>
<head>
<script language="JavaScript">
<!--
var selected;
function fsubmit(form) {
var action = form.action.options[form.action.selectedIndex].value;
var user = form.user.value;
if(!user || !action) {
alert("No user or action selected");
return false;
}
user = user.replace(/^[@%+ ]/, '');
parent.fwindowlist.sendcmd_userlist(action, user);
return false;
}
function deselect() {
if(!selected) return;
selected.className = 'userlist-item';
}
function userlist(users) {
var tmp = '<table class="userlist-table">';
for(var i = 0;i < users.length; i++) {
var status = users[i].substr(0, 1);
var user = users[i].substr(1);
tmp += '<tr><td class="userlist-status"> ' + statushtml(status) + ' </td>'
+ '<td class="userlist-item" ' +
(user != 'No channel' ?
' onmouseout="this.className=(this == selected ?'
+ '\\\'userlist-selected\\\':\\\'userlist-item\\\')"'
+ ' onmouseover="this.className=\\\'userlist-hover\\\'"'
+ ' onclick="' + 'this.className=\\\'userlist-selected\\\';'
+ 'deselect();selected = this;document.mform.user.value = \\\''
+ user + '\\\';return false;" ondblclick="fsubmit(document.mform);"'
: '') + '>' + user + '</td></tr>';
}
tmp += '</table>';
document.getElementById('usertable').innerHTML = tmp;
document.mform.user.value = '';
}
function statushtml(status) {
if(status == "@") {
return '<div class="userlist-op">@</div>';
}else if(status == "+") {
return '<div class="userlist-voice">+</div>';
}else if(status == "%") {
return '<div class="userlist-halfop">%</div>';
}else{
return '';
}
}
`;
if($browser eq 'ie') {
print q`
document.onselectstart = function() { return false; }
`;
}
print q`
// -->
</script>
<link rel="stylesheet" href="$config->{script_login}?interface=`;print $browser;print q`&item=style" />
</head>
<body class="userlist-body">
<div class="userlist-div" id="usertable">
<table class="userlist-table">
<tr><td class="userlist-status"></td>
<td class="userlist-item">No channel</td></tr>
</table>
</div>
<form name="mform" onsubmit="return fsubmit(this)" class="userlist-form">
<input type="hidden" name="user">
<select name="action" class="userlist-select">
<option value="query">Query</option>
<option value="whois">Whois</option>
<option value="kick">Kick</option>
</select>
<input type="submit" class="userlist-btn" value=">>">
</form>
</body>
</html>
EOF
}
sub fmain {
my($self, $cgi, $config) = @_;
print <<EOF;
$standardheader
<html><head>
<link rel="stylesheet" href="$config->{script_login}?interface=`;print $browser;print q`&item=style" />
</head>
<body class="main-body"
onkeydown="if(parent.fform.location) parent.fform.fns();">
<span class="main-span" id="text"></span>
</body></html>
EOF
}
sub say {
my($self) = @_;
return 'ok';
}
sub fform {
my($self,$config) = @_;
print <<EOF;
$standardheader
<html>
<head>
<html><head>
<script language="JavaScript"><!--
var history = [ ];
var hispos;
var tabtmp = [ ];
var tabpos;
var tablen;
var tabinc;
function fns(){
if(!document.myform["say"]) return;
document.myform["say"].focus();
}
function t(item,text) {
if(item.style.display == 'none') {
item.style.display = 'inline';
text.value = '>';
document.myform.say.style.width='60%'
}else{
item.style.display = 'none';
text.value = '<';
document.myform.say.style.width='90%'
}
fns();
}
function load() {
fns();
`;
if($browser eq 'mozilla') {
print q`
if(document.captureEvents) {
document.captureEvents(Event.KEYPRESS);
document.onkeypress = enter_key_trap;
}
`;
}else{
print "document.getElementById('extra').style.display = 'none';\n";
}
print q`
}
function append(a) {
document.myform["say"].value += a;
fns();
}
function cmd() {
if(document.myform["say"].value.length < 1) return false;
hisadd();
tabpos = 0;
tabtmp = [];
parent.fwindowlist.sendcmd(document.myform["say"].value);
document.myform["say"].value = ''
return false;
}
function nickchange(nick) {
if(document.getElementById('nickname'))
document.getElementById('nickname').innerHTML = nick;
}
function hisadd() {
history[history.length] = document.myform["say"].value;
hispos = history.length;
}
function hisdo() {
if(history[hispos]) {
document.myform["say"].value = history[hispos];
}else{
document.myform["say"].value = '';
}
}
`;
if($browser eq 'ie') {
print q`
document.onkeydown = function() {
return keypress(event.srcElement, event.keyCode, event);
}
`;
}else {
print q`
function enter_key_trap(e) {
return keypress(e.target, e.keyCode, e);
}
`;
}
print q`
function keypress(srcEl, keyCode, event) {
if (srcEl.tagName != 'INPUT' || srcEl.name.toLowerCase() != 'say')
return true;
if(keyCode == 66 && event.ctrlKey) {
append('\%B');
}else if(keyCode == 67 && event.ctrlKey) {
append('\%C');
}else if(keyCode == 9) { // TAB
var tabIndex = srcEl.value.lastIndexOf(' ');
var tabStr = srcEl.value.substr(tabIndex+1 || tabIndex).toLowerCase();
if(tabpos == tabIndex && !tabStr && tabtmp.length) {
if(tabinc >= tabtmp.length) tabinc = 0;
for(var i = (tabinc > 0 ? tabinc : 0); i < tabtmp.length;i++) {
srcEl.value = srcEl.value.substr(0, tabIndex - tablen) +
tabtmp[i] + (tabIndex == tablen ? ': ' : ' ');
tabpos = (tabIndex == -1 ? 0 : tabIndex) + tabtmp[i].length - tablen + (tabIndex == tablen ? 1 : 0);
tablen = tabtmp[i].length + (tabIndex == tablen ? 1 : 0);
tabinc++;
break;
}
}else{
tabtmp = [];
var list = parent.frames.fwindowlist.channellist(parent.frames.fwindowlist.currentwindow);
for(var i = 0;i < list.length; i++) {
var item = list[i].replace(/^[+%@ ]/,'');
if(item.substr(0, tabStr.length).toLowerCase() == tabStr) {
tabtmp[tabtmp.length] = item;
}
}
if(!tabtmp[0]) {
for(var i in parent.frames.fwindowlist.Witems) {
if(i.substr(0, tabStr.length).toLowerCase() == tabStr) {
tabtmp[tabtmp.length] = i;
}
}
}
if(!tabtmp[0]) return false;
srcEl.value = srcEl.value.substr(0, tabIndex) +
(tabIndex > 0 ? ' ' : '') + tabtmp[0] + (tabIndex == -1 ? ': ' : ' ');
tablen = tabtmp[0].length + (tabIndex == -1 ? 1 : 0);
tabpos = (tabIndex == -1 ? 0 : tabIndex + 1) + tablen;
tabinc = 1;
}
}else if(keyCode == 38) { // UP
if(!history[hispos]) {
if(document.myform["say"].value) hisadd();
hispos = history.length;
}
hispos--;
hisdo();
}else if(keyCode == 40) { // DOWN
if(!history[hispos]) {
if(document.myform["say"].value) hisadd();
document.myform["say"].value = '';
return false;
}
hispos++;
hisdo();
}else if(event.altKey && keyCode > 47 && keyCode < 58) {
var num = keyCode - 48;
if(num == 0) num = 10;
var name = parent.fwindowlist.witemchgnum(num);
if(!name) return false;
parent.fwindowlist.witemchg(name);
}else{
return true;
}
return false;
}
//-->
</script>
<link rel="stylesheet" href="$config->{script_login}?interface=`;print $browser;print q`&item=style" />
</head>
<body onload="load()" onfocus="fns()" class="form-body">
<form name="myform" onSubmit="return cmd();" class="form-form">
<span id="nickname" class="form-nickname"></span>
<input type="text" class="form-say" name="say" autocomplete="off">
</form>
`;
if($browser eq 'ie') {
print q`
<span class="form-econtain">
<input type="button" class="form-expand" onclick="t(document.getElementById('extra'),this);" value="<">
<span id="extra" class="form-extra">
<input type="button" class="form-boldbutton" value="B" onclick="append('\%B')">
<input type="button" class="form-boldbutton" value="_" onclick="append('\%U')">
EOF
for(sort {$a <=> $b} keys %colours) {
print "<input type=\"button\" style=\"background: $colours{$_}\" value=\" \" onclick=\"append('\%C$_')\">\n";
}
print <<EOF;
</span>
</span>
`;
}
print q`
</body>
</html>
EOF
}
sub fwindowlist {
my($self, $cgi, $config) = @_;
my $string;
for(keys %$cgi) {
next if $_ eq 'item';
$string .= main::cgi_encode($_) . '=' . main::cgi_encode($cgi->{$_}).'&';
}
$string =~ s/\&$//;
print $standardheader;
print q~
<html>
<head>
<script language="JavaScript">
<!--
// This javascript code is released under the same terms as CGI:IRC itself
// http://cgiirc.sourceforge.net/
// Copyright (C) 2000-2002 David Leadbeater <cgiirc\\@dgl.cx>
// none joins talk directed talk
var activity = ['#000000','#000099','#990000', '#009999'];
var Witems = {};
var options = {};
var currentwindow = '';
var lastwindow = '';
var connected = 0;
var mynickname = '';
`;
if($browser eq 'ie') {
print q`
document.onselectstart = function() { return false; }
//document.onmouseup = function() {
// if(event.button != 2) return true;
// event.returnVal = false;
// return false;
//}
//document.oncontextmenu = function() {
// return false;
//}
`;
}
print q`
function witemadd(name, channel) {
if(Witems[name] || findwin(name)) return;
name = name.replace(/\"/g, '"');
Witems[ name ] = { activity: 0, text: new Array, channel: channel };
if(channel) {
Witems[name].users = {};
Witems[name].topic = '';
}
if(!currentwindow) currentwindow = name;
wlistredraw();
}
function witemdel(name) {
if(!Witems[name] && !(name = findwin(name))) return;
if(name == 'Status') return;
delete Witems[name];
if(currentwindow == name) witemchg(lastwindow ? lastwindow : 'Status');
}
function witemclear(name) {
if(!Witems[name] && !(name = findwin(name))) return;
Witems[name].text.length = 0;
witemredraw();
}
function channeladdusers(channel, users) {
for(var i = 0;i < users.length;i++) {
channeladduser(channel, users[i]);
}
userlist();
}
function channeladduser(channel, user) {
var o = user.substr(0,1);
if(o == '@' || o == '+' || o == '%')
user = user.substr(1);
if(!Witems[channel] && !(channel = findwin(channel))) return;
Witems[channel].users[user] = { };
if(o == '@') Witems[channel].users[user].op = 1;
if(o == '%') Witems[channel].users[user].halfop = 1;
if(o == '+') Witems[channel].users[user].voice = 1;
}
function channelsdeluser(channels, user) {
for(var i = 0;i < channels.length; i++) {
channeldeluser(channels[i], user);
}
userlist();
}
function channeldeluser(channel, user) {
if(!Witems[channel] && !(channel = findwin(channel))) return;
delete Witems[channel].users[user];
userlist();
}
function channelsusernick(olduser, newuser) {
for(var channel in Witems) {
if(!Witems[channel].channel) continue;
for(var nick in Witems[channel].users) {
if(nick == olduser) {
Witems[channel].users[newuser] = Witems[channel].users[olduser];
delete Witems[channel].users[olduser];
}
}
}
userlist();
}
function channelusermode(channel, user, action, type) {
if(!Witems[channel] && !(channel = findwin(channel))) return;
if(!Witems[channel].users[user]) return;
if(type == 'op') {
Witems[channel].users[user].op = (action == '+' ? 1 : 0);
}else if(type == 'voice') {
Witems[channel].users[user].voice = (action == '+' ? 1 : 0);
}else if(type == 'halfop') {
Witems[channel].users[user].halfop = (action == '+' ? 1 : 0);
}
userlist();
}
function channellist(channel) {
if(!Witems[channel] && !(channel = findwin(channel))) return;
var users = new Array();
for (var i in Witems[channel].users) {
var user = Witems[channel].users[i];
if(user.op) i = '@' + i
else if(user.halfop) i = '%' + i;
else if(user.voice) i = '+' + i;
else i = ' ' + i;
users[users.length] = i;
}
users = users.sort(usersort);
return users;
}
function usersort(user1,user2) {
var m1 = user1.substr(0,1);
var m2 = user2.substr(0,1);
if(m1 == m2) {
if(user1.toUpperCase() < user2.toUpperCase()) return -1;
if(user2.toUpperCase() < user1.toUpperCase()) return 1;
return 0; // shouldn't happen :-)
}else if(m1 == '@') {
return -1;
}else if(m2 == '@') {
return 1;
}else if(m1 == '%') {
return -1;
}else if(m2 == '%') {
return 1;
}else if(m1 == '+') {
return -1;
}else if(m2 == '+') {
return 1;
}else{
if(user1.toUpperCase() < user2.toUpperCase()) return -1;
if(user2.toUpperCase() < user1.toUpperCase()) return 1;
return 0;
}
}
function witemchg(name) {
if(!Witems[name] && !(name = findwin(name))) return;
if(Witems[name].activity > 0) Witems[name].activity = 0;
lastwindow = currentwindow;
currentwindow = name;
wlistredraw();
witemredraw();
formfocus();
userlist();
retitle();
}
function retitle() {
parent.document.title = 'CGI:IRC - ' + currentwindow + (Witems[currentwindow].channel == 1 ? ' [' + countit(Witems[currentwindow].users) + '] ' : '');
}
function mynick(mynick) {
mynickname = mynick;
if(options.shownick != 1) return;
if(parent.fform && parent.fform.nickchange) parent.fform.nickchange(mynick);
}
function witemchgnum(num) {
var count = 1;
for(var name in Witems) {
if(count++ == num) return name;
}
return false;
}
function countit(obj) {
var i = 0;
for(var foo in obj) i++;
return i;
}
function witemaddtext(name, text, activity) {
if(name == '-all') {
for(var window in Witems) {
witemaddtext(window, text, activity);
}
return;
}
if(!Witems[name] && !(name = findwin(name))) {
if(!Witems["Status"]) return;
name = "Status";
}
if(options["timestamp"]) {
var D = new Date();
text = '[' + (D.getHours() < 10 ? '0' + D.getHours() : D.getHours()) + ':' + (D.getMinutes() < 10 ? '0' + D.getMinutes() : D.getMinutes()) + '] ' + text;
}
Witems[name].text[Witems[name].text.length] = text;
if(currentwindow != name && activity > Witems[name].activity)
witemact(name, activity);
if(currentwindow == name) witemredraw();
}
function witemact(name, activity) {
if(!Witems[name] && !(name = findwin(name))) return;
Witems[name].activity = activity;
wlistredraw();
}
function witemredraw() {
if(!parent.fmain.document) {
setTimeout("witemredraw()", 1000);
return;
}
if(!currentwindow) currentwindow = 'Status';
parent.fmain.document.getElementById('text').innerHTML = Witems[currentwindow].text.join('');
`;
if($browser eq 'ie') {
print q`
var count = 0;
var doc = parent.fmain.document.body;
while(doc.scrollTop < doc.scrollHeight && count < 20) {
doc.scrollTop = doc.scrollHeight;
count++;
}
`;
}else{
print q`
var doc = parent.frames.fmain.window;
var scroll = -1;
while(doc.scrollY > scroll) {
scroll = doc.scrollY;
doc.scrollBy(0, 500);
}
`;
}
print q`
}
function wlistredraw() {
var output='';
for (var i in Witems) {
output += '<span class="' + (i == currentwindow ? 'wlist-active' : 'wlist-chooser') + '" style="color: ' + activity[Witems[i].activity] + ';" onclick="witemchg(\'' + (i == currentwindow ? escapejs(lastwindow) : escapejs(i)) + '\')" onmouseover="this.className = \'wlist-mouseover\'" onmouseout="this.className = \'' + (i == currentwindow ? 'wlist-active' : 'wlist-chooser') + '\'">' + escapehtml(i) + '</span>\r\n';
}
document.getElementById('windowlist').innerHTML = output;
}
function findwin(name) {
var wname = new String(name);
wname = wname.replace(/\"/g, '"');
for (var i in Witems) {
if (i.toUpperCase() == wname.toUpperCase())
return i;
}
return false;
}
function escapejs(string) {
var out = string; // perl needs some slashes here.
// quite mad.
out = out.replace(/\\\\\\\\/g,'\\\\\\\\\\\\\\\\');
out = out.replace(/\\\\'/g, '\\\\\\\\\\\\'');
out = out.replace(/\"/g, '"');
return out;
}
function escapehtml(string) {
var out = string;
out = out.replace(/</g, '<');
out = out.replace(/>/g, '>');
out = out.replace(/\"/g, '"');
return out;
}
function sendcmd(cmd) {
if(currentwindow == 'Status' && cmd.substr(0,1) != '/') return;
if(!connected) {
alert('Not connected to IRC!');
return;
}
sendcmd_real('say', cmd, currentwindow);
}
function sendcmd_userlist(action, user) {
if(currentwindow == 'Status') return;
if(!connected) {
alert('Not connected to IRC!');
return;
}
sendcmd_real('say', '/' + action + ' ' + user, currentwindow);
}
function sendcmd_real(type, say, target) {
document.hsubmit.cmd.value = type;
document.hsubmit.say.value = say;
document.hsubmit.target.value = target;
document.hsubmit.submit();
}
function userlist() {
if(Witems[currentwindow] && Witems[currentwindow].channel == 1) {
userlistupdate(channellist(currentwindow));
}else{
userlistupdate([' No channel']);
}
retitle();
}
function userlistupdate(list) {
if(!parent.fuserlist.userlist) return;
parent.fuserlist.userlist(list);
}
function formfocus() {
if(parent.fform.location) parent.fform.fns();
}
function disconnected() {
if(connected == 1) {
connected = 0;
do_quit();
witemaddtext('-all', '<b>Disconnected</b>', 1);
}
}
~;
print qq~
imghelpdn = new Image();
imghelpdn.src = "$config->{image_path}/helpdn.gif";
imghelpup = new Image();
imghelpup.src = "$config->{image_path}/helpup.gif";
imgoptionsdn = new Image();
imgoptionsdn.src = "$config->{image_path}/optionsdn.gif";
imgoptionsup = new Image();
imgoptionsup.src = "$config->{image_path}/optionsup.gif";
imgclosedn = new Image();
imgclosedn.src = "$config->{image_path}/closedn.gif";
imgcloseup = new Image();
imgcloseup.src = "$config->{image_path}/closeup.gif";
function do_quit() {
var i = new Image();
i.src = "$config->{script_form}?R=$cgi->{R}&cmd=quit";
}
// -->
</script>
<link rel="stylesheet" href="$config->{script_login}?interface=`;print $browser;print q`&item=style" />
</head>
<body onload="wlistredraw()" onkeydown="formfocus()" onbeforeunload="do_quit()" onunload="do_quit()" class="wlist-body">
<noscript>Scripting is required for this interface</noscript>
<table class="wlist-table">
<tr><td width="1">
`;
if($browser eq 'ie'){
print q`
<iframe src="$config->{script_nph}?$string" width="1" height="1" style="display:none;" onreadystatechange="if(this.readyState=='complete')disconnected()"></iframe>
`;
}else{
print q`
<iframe src="$config->{script_nph}?$string" width="1" height="1"></iframe>
`;
}
print q`
</td>
<td id="windowlist" class="wlist-container">
</td><td class="wlist-buttons">
<img src="$config->{image_path}/helpup.gif" onclick="sendcmd('/help');" class="wlist-button" onmousedown="this.src=imghelpdn.src" onmouseup="this.src=imghelpup.src;" onmouseout="this.src=imghelpup.src;">
<img src="$config->{image_path}/optionsup.gif" onclick="alert('Not yet done');" class="wlist-button" onmousedown="this.src=imgoptionsdn.src" onmouseup="this.src=imgoptionsup.src;" onmouseout="this.src=imgoptionsup.src;">
<img src="$config->{image_path}/closeup.gif" onclick="if(currentwindow != 'Status'){sendcmd('/winclose')}else if(confirm('Are you sure you want to quit?')){do_quit()}" class="wlist-button" onmousedown="this.src=imgclosedn.src" onmouseup="this.src=imgcloseup.src;" onmouseout="this.src=imgcloseup.src;">
</td></tr></table>
<form name="hsubmit" method="post" action="$config->{script_form}" target="hiddenframe">
<input type="hidden" name="R" value="$cgi->{R}">
<input type="hidden" name="cmd" value="say">
<input type="hidden" name="item" value="say">
<input type="hidden" name="say" value="">
<input type="hidden" name="target" value="">
</form>
</body></html>
~;
}
1;
`;
}