-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
704 lines (621 loc) · 17.8 KB
/
index.html
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>飘</title>
<link rel="stylesheet" type="text/css" href="inc/all.css">
<script language="javascript" src="inc/jq_1_11_1.js" type="text/javascript"></script>
<script language="javascript" src="inc/underscore.js" type="text/javascript"></script>
<script language="javascript" src="inc/forum.js" type="text/javascript"></script>
<script language="javascript" src="inc/set.js" type="text/javascript"></script>
<script language="javascript" src="inc/msg.js" type="text/javascript"></script>
<script language="javascript" src="inc/md5.js" type="text/javascript"></script>
<script language="javascript" src="inc/ubb.js" type="text/javascript"></script>
</head>
<body>
<script language="javascript">
var PFItem = function( owner, name, title, objpg )
{
var it = this;
this.Owner = owner;
this.Name = name;
this.ObjPg = objpg;
this.Draw = function()
{
var dom = $( '<div class="pfitem" id="' + this.Name + '"><div class="title"><span class="arrow">▷</span>' + title +'<span class="newnum"></span></div><div class="content"></div></div>' );
this.Owner.children( '#' + this.Name ).remove();
this.Owner.append( dom );
dom.data( 'obj', this );
};
this.GetTitle = function()
{
return $( '#' + this.Name ).children( '.title' );
}
this.GetContent = function()
{
return $( '#' + this.Name ).children( '.content' );
}
this.Close = function()
{
var dom = $( '#' + this.Name );
dom.children( '.content' ).hide( 300 );
dom.children( '.title' ).children( '.arrow' ).html( '▷' );
this.ObjPg.hide( 300 );
};
this.Open = function()
{
var dom = $( '#' + this.Name );
dom.children( '.content' ).show( 300 );
dom.children( '.title' ).children( '.arrow' ).html( '◀' );
this.ObjPg.show( 300 );
};
this.Click = function()
{
try
{
$( '.pfitem:contains(◀)' ).data( 'obj' ).Close();
}
catch( e ){}
this.Open();
};
this.Draw();
}
var PeerForum = function()
{
var pf = this;
//this.Info = { warning: [], error: [], info: [] };
this.UserSet = {};
this.LabelSet = {};
this.Forum = new Forum( this );
//this.Setting = new Manager( this );
this.MAXTIME = 9999999999999;
this.Before = this.MAXTIME; //for timeline
this.SearchKWord = '';
this.Init = function()
{
this.PageIdx = {};
this.Height = document.documentElement.clientHeight;
$( 'td#leftarea>div' ).css( 'height', pf.Height - 35 + 'px' );
$( window ).resize( function()
{
pf.Height = document.documentElement.clientHeight;
//console.log( pf.Height );
$( 'td#leftarea>div' ).css( 'height', pf.Height - 35 + 'px' );
} );
var ItemBox = $( '#itembox' );
[
//['message', '消息', 'msgpg', 'InitMsgPg'],
['forum', '论坛', 'forumpg', 'InitForumPg'],
['timeline', '时间线', 'timelinepg', 'InitTimeLinePg'],
['setting', '设置', 'setpg', 'InitSetPg'],
].forEach( function( data )
{
pf.PageIdx[data[0]] = new PFItem( ItemBox, data[0], data[1], $( '#' + data[2] ));
pf[data[3]]();
} );
$( '.pfitem>.title' ).click( function()
{
//alert( $( this ).attr( 'id' ));
$( this ).parent().data( 'obj' ).Click();
} );
$( '.page' ).hide();
$( '.pfitem>.content' ).hide();
$( '#forum>.title' ).click();
this.ChkEnv();
setTimeout( this.Dida, 5000 );
};
this.InitForumPg = function()
{
this.Forum.GetNextPage();
}
this.InitMsgPg = function(){};
this.InitTimeLinePg = function(){};
this.InitSetPg = function(){};
/*this.ShowInfo = function()
{
var dom = $( '#message' );
var content = dom.children( '.content' );
_( ['error', 'warning', 'info'] ).each( function( k )
{
_( pf.Info[k] ).each( function( msg )
{
var MsgItem = $( '<div></div>' );
content.append( MsgItem );
msg.Notice( MsgItem );
} );
} );
dom.children( '.title' ).children( '.newnum' ).html( content.children( 'div' ).length );
};*/
this.ChkLocalNode = function( lcNode )
{
var TBody = $( '<tbody></tbody>' );
TBody.append( '<tr><th>节点公钥</th><td>' + lcNode[0] + '</td></tr>' );
TBody.append( '<tr><th>节点名</th><td><input type="text" maxlength="10"/>不能为空</td></tr>' );
$( ':text:last', TBody ).val( lcNode[1] );
TBody.append( '<tr><th>节点描述</th><td><textarea maxlength="500">' + ( lcNode[2] || '' ) + '</textarea></td></tr>' );
var TR = $( '<tr class="scalable"><th>通信地址</th><td></td></tr>' );
var GetIPsBtn = $( '<button>获取本地 IP</button>' );
TR.children( 'td' ).append( GetIPsBtn ).append( '<span class="query" title="">?</span><div id="iplist"></div>' );
QueryPop( $( '.query', TR ), 'localip' );
lcNode[3].forEach( function( v )
{
var Edit = $( '<input type="text"/>' );
Edit.val( v );
TR.children( 'td' ).append( Edit ).append( '<br>' );
} );
GetIPsBtn.click( function()
{
var ip_dups = {};
var RTCPeerConnection = window.RTCPeerConnection
|| window.mozRTCPeerConnection
|| window.webkitRTCPeerConnection;
var mediaConstraints = { optional: [{ RtpDataChannels: true }] };
var servers = { iceServers: [{ urls: "stun:stun.services.mozilla.com" }] };
var pc = new RTCPeerConnection( servers, mediaConstraints );
$( '#iplist' ).html( '' );
pc.onicecandidate = function( ice )
{
if( ice.candidate )
{
console.log( ice.candidate.candidate );
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/
var ip_addr = ip_regex.exec( ice.candidate.candidate )[1];
if( ip_dups[ip_addr] === undefined )
{
$( '#iplist' ).append( ip_addr ).append( '<br>' );
}
ip_dups[ip_addr] = true;
}
};
pc.createDataChannel( "" );
pc.createOffer( function( result )
{
pc.setLocalDescription( result, function(){}, function(){} );
}, function(){} );
} );
TBody.append( TR );
new SetItem( 'CurNode', TBody, function()
{
var NewName = $( ':text:first', TBody ).val();
if( !NewName )
{
alert( '节点名不能为空。' );
return;
}
var Addresses = []
$( ':text', TR ).each( function()
{
Addresses.push( $( this ).val());
} );
pf.Post( {
cmd: 'EditSelfNode',
PubKey: lcNode[0],
Name: NewName,
Desc: $( 'textarea', TBody ).val(),
Addresses: JSON.stringify( Addresses ),
} );
} );
/*if( !lcNode[1] )
{
this.Info.warning.push( new PFMessage( 'SetNodeName', lcNode ));
}*/
this.CurNode = lcNode;
this.ChkNeighbor();
};
this.ChkNeighbor = function( nbNodes )
{
var TBody = $( '<tbody><tr><th>通信地址</th><td><input type="text"/><br>必填。邻节点的通信地址应包含 ip 和端口,中间用“:”分隔,如:http://202.124.84.98:7000</td></tr></tbody>' );
new SetItem( 'CurNeighbor', TBody, function()
{
var Addr = $( ':text', TBody ).val();
if( !Addr.match( /^https?\:\/\//i ) )
{
alert( '通信地址应以 http:// 或 https:// 开头。' );
return;
}
pf.Post( {
cmd: 'AddNeighbor',
Address: Addr,
} );
} );
};
this.ChkLocalUser = function( lcUser )
{
var TBody = $( '<tbody></tbody>' );
TBody.append( '<tr><th>用户公钥</th><td>' + lcUser[0] + '</td></tr>' );
TBody.append( '<tr><th>用户名</th><td><input type="text" maxlength="10"/>不能为空</td></tr>' );
$( ':text:last', TBody ).val( lcUser[1] );
new SetItem( 'CurUser', TBody, function()
{
var NewName = $( ':text', TBody ).val();
if( !NewName )
{
alert( '用户名不能为空。' );
return;
}
pf.Post( {
cmd: 'SetSelfUserName',
PubKey: lcUser[0],
Name: NewName,
} );
} );
/*if( !lcUser[1] )
{
this.Info.error.push( new PFMessage( 'SetUserName', lcUser ));
}*/
this.CurUser = lcUser;
};
this.ChkAuthStatus = function( authPubK )
{
//console.log( authPubK );
return ( this.UserSet[authPubK] || [0, 0] )[1];
};
this.SetAtclLabels = function( labelObj )
{
//console.log( 'SetAtclLabels' );
var LabelArea = $( '#forum>.content' );
LabelArea.html( '<div id="alllabelidx">所有话题</div>' );
$( '#alllabelidx' ).click( function()
{
pf.Forum.LabelTopic( $( this ));
} );
_( labelObj ).chain().pairs().sortBy( function( p )
{
return -p[1];
} ).forEach( function( p )
{
pf.LabelSet[p[0]] = $( '<div class="atcllabel">' + p[0] + '</div>' );
LabelArea.append( pf.LabelSet[p[0]] );
} );
LabelArea.children( '.atcllabel' ).click( function()
{
pf.Forum.LabelTopic( $( this ));
} );
};
this.ShowNewTopic = function( topic )
{
console.log( topic );
$( '#tpclist>table>tbody>tr:eq(0)' ).after( this.Forum.TopicTR( topic ));
var NewTR = $( '#tpclist>table>tbody>tr.new' );
this.Forum.SetAttr( NewTR );
$( 'span.arrow', NewTR ).click();
setTimeout( function()
{
pf.Forum.ResetNewTpcInput();
var TreeTR = NewTR.next( 'tr.tree' );
$( 'span.arrow', TreeTR ).click();
}, 500 );
};
this.ShowAtclPg = function( treeData )
{
//console.log( treeData );
this.Forum.SetTopicData( treeData );
this.Forum.ShowAtcls( treeData[0], this.Forum.FLOWMODE );
};
this.SetUserAttr = function( dom )
{
console.log( 'SetUserAttr' );
$( '.manageuser>button', dom ).click( function()
{
var UserPubKey = $( this ).parent().data( 'user' );
var NickName = $( this ).parent().siblings( '.nickname' ).text();
var Status = $( this ).data( 'status' );
pf.Post( {
cmd: 'SetUserStatus',
PubKey: UserPubKey,
Name: NickName,
Status: Status,
} );
} );
}
this.SetAllUsers = function( allUserData )
{
var UserArea = $( '#timeline>.content' );
var PrefContent = $( '<div class="content"><div class="atcllabel" style="float:;" data-user="me">我</div><div class="atcllabel" style="float:;" data-user="all">所有关注用户</div><input type="text" placeholder="按帖子 ID 或内容搜索。"/><button>搜索</button></div>' );
PrefContent.hide();
PrefContent.children( 'button' ).click( function()
{
var KWord = $( this ).siblings( 'input' ).val();
if( !KWord )
{
return;
}
$( '#timelinepg' ).html( '' );
$( '#timeline>.content div' ).removeClass( 'sel' );
pf.SearchKWord = KWord;
pf.Search( KWord );
} );
//UserArea.html( '<div id="alluseridx">所有关注用户</div>' );
UserArea.before( PrefContent );
allUserData.forEach( function( user )
{
pf.UserSet[user[0]] = [user[1], user[2]];
if( user[2] > 0 )
{
var UserLabel = $( '<div class="atcllabel" title="' + user[0] + '">' + user[1] + '</div>' );
UserLabel.data( 'user', user[0] );
UserArea.append( UserLabel );
}
} );
$( '#timeline>.content' ).children( '.atcllabel' ).click( function()
{
$( '#timeline>.content div' ).removeClass( 'sel' );
$( this ).addClass( 'sel' );
$( '#timelinepg' ).html( '' );
pf.SearchKWord = '';
pf.Post( {
cmd: 'GetTimeLine',
user: $( this ).data( 'user' ),
before: pf.MAXTIME
} );
return false;
} );
$( '#timeline>.content>div:eq(1)' ).click();
console.log( pf.UserSet );
};
this.ChkPageActive = function( pageId, labelId )
{
var Page = $( '#' + pageId );
if( Page.is( ":visible" ))
{
return Page;
}
Page.show( 300 );
Page.siblings( '.page' ).hide( 200 );
$( '#' + labelId + '>.title' ).click();
return Page;
};
this.Search = function( kw )
{
var TLPage = pf.ChkPageActive( 'timelinepg', 'timeline' );
TLPage.html( '' );
pf.Post( {
cmd: 'Search',
kword: kw,
before: pf.MAXTIME,
} );
};
this.GetTimeLine = function()
{
if( pf.SearchKWord )
{
pf.Post( {
cmd: 'Search',
kword: pf.SearchKWord,
before: pf.Before,
} );
}
else
{
pf.Post( {
cmd: 'GetTimeLine',
user: $( '#timeline>.content>div.sel' ).data( 'user' ),
before: pf.Before
} );
}
};
this.GetUserButtons = function( status )
{
return ( status >= 0 ? '<button data-status=-1>屏蔽</button>' : '<button data-status=0>解除屏蔽</button>' )
+ ( status <= 0 ? '<button data-status=1>关注</button>' : '<button data-status=0>取消关注</button>' );
};
this.SetUserStatus = function( userStatus )
{
console.log( userStatus[0], pf.UserSet[userStatus[0]] );
pf.UserSet[userStatus[0]] = [userStatus[1], userStatus[2]];
if( userStatus[2] > 0 )
{
var UserLabel = $( '<div class="atcllabel" title="' + userStatus[0] + '">' + userStatus[1] + '</div>' );
UserLabel.data( 'user', userStatus[0] );
UserLabel.click( function()
{
$( this ).siblings( 'div' ).removeClass( 'sel' );
$( this ).addClass( 'sel' );
$( '#timelinepg' ).html( '' );
pf.SearchKWord = '';
pf.Post( { cmd: 'GetTimeLine', user: userStatus[0], before: pf.MAXTIME } );
} );
$( '#timeline>.content' ).append( UserLabel );
}
else
{
$( '#timeline>.content>.atcllabel' ).each( function()
{
if( $( this ).data( 'user' ) == userStatus[0] )
{
$( this ).remove();
return false;
}
} );
}
$( '.manageuser' ).each( function()
{
if( $( this ).data( 'user' ) == userStatus[0] )
{
$( this ).addClass( 'update' );
}
} );
var Update = $( '.manageuser.update' );
Update.html( this.GetUserButtons( userStatus[2] ));
this.SetUserAttr( Update.parent());
Update.removeClass( 'update' );
};
this.ShowReply = function( rplData )
{
console.log( rplData );
this.Forum.ReplyOK( rplData );
};
/*this.SetLike = function( likeData )
{
console.log( likeData );
this.Forum.AddLike( likeData );
};*/
this.ExpendTpcTree = function( treeData )
{
//console.log( treeData );
this.Forum.SetTopicData( treeData );
var TreeTR = this.Forum.ShowTree( treeData[0] );
TreeTR.hide();
$( '#Topic_' + treeData[0] ).after( TreeTR );
TreeTR.show( 400 );
}
this.AppendTopics = function( topics )
{
//console.log( topics );
var TBody = $( '#tpclist>table>tbody' );
topics.forEach( function( topic )
{
try { TBody.append( pf.Forum.TopicTR( topic )); } catch( e ) {};
} );
this.Forum.SetAttr( TBody.children( 'tr.new' ));
this.Forum.ChkNextPage();
};
this.AppendTimeLine = function( tls )
{
this.Before = pf.Forum.ShowTimeLine( tls );
};
this.UpdateLabelStr = function( labelData )
{
this.Forum.SetLabelStr( labelData );
};
this.AddNeighbor = function()
{
//$( '#forum>.title' ).click();
};
this.ChkGotNew = function( got )
{
//got = 1;
if( got && $( '#tpclist>.notice' ).length === 0 )
{
$( '#tpclist>table' ).before( '<div class="notice" onclick="javascript:location.reload()">有更新</div>' );
}
}
this.GetResult = function( rslt )
{
console.log( rslt );
var FuncMap = {
'CurNode': [pf.ChkLocalNode, pf],
'NeighborNode': [pf.ChkNeighbor, pf],
'CurUser': [pf.ChkLocalUser, pf],
'AllLabels': [pf.SetAtclLabels, pf],
'AllUsers': [pf.SetAllUsers, pf],
'NewTopic': [pf.ShowNewTopic, pf],
'PageTopics': [pf.AppendTopics, pf],
'AtclTree': [pf.ShowAtclPg, pf],
'UpdateLabel': [pf.UpdateLabelStr, pf],
'Reply': [pf.ShowReply, pf],
'ShowTree': [pf.ExpendTpcTree, pf],
'UserStatus': [pf.SetUserStatus, pf],
'TimeLine': [pf.AppendTimeLine, pf],
'AddNeighbor': [pf.AddNeighbor, pf],
'GotNewAtcl': [pf.ChkGotNew, pf],
};
_( rslt ).chain().pairs().each( function( p )
{
//console.log( p );
if( p[0] in FuncMap )
{
var FuncOwn = FuncMap[p[0]];
FuncOwn[0].bind( FuncOwn[1] )( p[1] );
}
} );
//pf.ShowInfo();
//console.log( pf.CurUser, pf.CurNode );
};
this.Dida = function()
{
pf.Post( { cmd: 'Dida' } );
setTimeout( pf.Dida, 5000 );
};
this.ChkEnv = function()
{
this.Post( { cmd: 'ChkEnv' } );
};
this.GetNode = function()
{
this.Post( { cmd: 'GetNode' } );
};
this.GetUser = function()
{
this.Post( { cmd: 'GetUser' } );
};
this.Post = function( params, dataFunc, errFunc )
{
console.log( 'Post', params );
$.post( '/web', params, function( data )
{
var Result = JSON.parse( data );
if( 'error' in Result )
{
( errFunc || alert )( Result.error );
}
( dataFunc || pf.GetResult )( Result );
} );
};
this.Init();
};
$( function()
{
new PeerForum();
} );
</script>
<div>
<table class='main' align='center'>
<tbody>
<tr>
<td id='leftarea' valign='top'>
<div id='forumpg' class='page'>
<div id='listpg'>
<div id='newtopic'>
<div id='newtpcbtn'>发布新话题</div>
<div id='tpcinput' style='display:none'>
<table>
<tbody>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<br/><br/>
<div id='tpclist'>
<div>话题列表</div>
<table width='100%'>
<tbody>
<tr>
<th>标题</th>
<th width='90px' id="firstth" title='排序'>首发</th>
<th width='50px'>帖数</th>
<th width='150px' id="lastth" title='排序'><span>↓↓↓</span>最新<span class="query" title="">?</span></th>
</tr>
</tbody>
</table>
</div>
</div>
<div id='atclpg' class='page'>
<div id='returntolist'>返回话题列表</div>
<div id='atclarea'></div>
<div id='treearea'></div>
</div>
</div>
<div id='msgpg' class='page'>msgpage</div>
<div id='timelinepg' class='page'>暂无时间线。</div>
<div id='setpg' class='page'></div>
</td>
<td id='rightarea' valign='top'>
<div id='logo'>
<a href="http://www.guideep.com/read?guide=5676982813589504" target="_blank">
<img src="inc/drift.png" title="使用说明"/>
</a>
</div>
<div id='itembox'></div>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>