@@ -12,7 +12,7 @@ idrinth.chat = {
12
12
refreshChats : function ( ) {
13
13
idrinth . chat . oldMessages = JSON . parse ( JSON . stringify ( idrinth . chat . messages ) ) ;
14
14
idrinth . chat . messages = [ ] ;
15
- idrinth . runAjax (
15
+ idrinth . core . ajax . run (
16
16
'https://dotd.idrinth.de/' + idrinth . platform + '/chat-service/update/' ,
17
17
idrinth . chat . applyMessages ,
18
18
idrinth . chat . returnMessages ,
@@ -28,7 +28,7 @@ idrinth.chat = {
28
28
idrinth . chat . refreshCount ++ ;
29
29
} ,
30
30
refreshMembers : function ( ) {
31
- idrinth . runAjax (
31
+ idrinth . core . ajax . run (
32
32
'https://dotd.idrinth.de/' + idrinth . platform + '/chat-service/accounts/' ,
33
33
idrinth . chat . applyMembers ,
34
34
function ( ) {
@@ -144,21 +144,21 @@ idrinth.chat = {
144
144
} ) ) ;
145
145
} ,
146
146
useroptions : function ( chat , user , rank ) {
147
- idrinth . runAjax (
147
+ idrinth . core . ajax . run (
148
148
'https://dotd.idrinth.de/' + idrinth . platform + '/chat-service/rank/' ,
149
149
function ( reply ) {
150
150
try {
151
151
reply = JSON . parse ( reply ) ;
152
- idrinth . alert ( reply . message ) ;
152
+ idrinth . core . alert ( reply . message ) ;
153
153
} catch ( e ) {
154
- idrinth . log ( e ) ;
154
+ idrinth . core . log ( e ) ;
155
155
}
156
156
} ,
157
157
function ( reply ) {
158
- idrinth . alert ( this . getMsg ( 'modify.fail' ) ) ;
158
+ idrinth . core . alert ( this . getMsg ( 'modify.fail' ) ) ;
159
159
} ,
160
160
function ( reply ) {
161
- idrinth . alert ( this . getMsg ( 'modify.fail' ) ) ;
161
+ idrinth . core . alert ( this . getMsg ( 'modify.fail' ) ) ;
162
162
} ,
163
163
JSON . stringify ( {
164
164
chat : chat ,
@@ -224,7 +224,10 @@ idrinth.chat = {
224
224
if ( ! idrinth . chat . emotes . lookup ) {
225
225
return message ;
226
226
}
227
- var part = idrinth . escapeRegExp ( Object . keys ( idrinth . chat . emotes . lookup ) . join ( 'TTTT' ) ) ;
227
+ var escapeRegExp = function ( str ) {
228
+ return str . replace ( / [ \- \[ \] \/ \{ \} \( \) \* \+ \? \. \\ \^ \$ \| ] / g, "\\$&" ) ;
229
+ } ;
230
+ var part = escapeRegExp ( Object . keys ( idrinth . chat . emotes . lookup ) . join ( 'TTTT' ) ) ;
228
231
var reg = new RegExp ( '(^| )(' + part . replace ( / T T T T / g, '|' ) + ')($| )' , 'g' ) ;
229
232
return idrinth . chat . replaceInText ( message , reg , [ function ( match ) {
230
233
var el = idrinth . chat . emotes . positions [ idrinth . chat . emotes . lookup [ match . replace ( / / g, '' ) ] ] ;
@@ -281,10 +284,26 @@ idrinth.chat = {
281
284
var processMessages = function ( messages ) {
282
285
var addMessages = function ( chatMessages , chatId , chatElement ) {
283
286
var buildMessage = function ( message , chat , chatId , messageId ) {
287
+ var getfullDateInt = function ( ) {
288
+ function addZero ( x , n ) {
289
+ while ( x . toString ( ) . length < n ) {
290
+ x = "0" + x ;
291
+ }
292
+ return x ;
293
+ }
294
+ var d = new Date ( ) ;
295
+ return addZero ( d . getFullYear ( ) , 2 ) +
296
+ addZero ( d . getMonth ( ) , 2 ) +
297
+ addZero ( d . getDate ( ) , 2 ) +
298
+ addZero ( d . getHours ( ) , 2 ) +
299
+ addZero ( d . getMinutes ( ) , 2 ) +
300
+ addZero ( d . getSeconds ( ) , 2 ) +
301
+ addZero ( d . getMilliseconds ( ) , 3 ) ;
302
+ } ;
284
303
chat . appendChild ( idrinth . ui . buildElement (
285
304
{
286
305
type : 'li' ,
287
- id : 'idrinth-single-chat-message-' + messageId + ( parseInt ( messageId , 10 ) < 1 ? '-' + idrinth . getfullDateInt ( ) : '' ) ,
306
+ id : 'idrinth-single-chat-message-' + messageId + ( parseInt ( messageId , 10 ) < 1 ? '-' + getfullDateInt ( ) : '' ) ,
288
307
css : ( parseInt ( message . user , 10 ) === parseInt ( idrinth . chat . self , 10 ) ? 'self-written ' : '' ) ,
289
308
children : [
290
309
{
@@ -352,7 +371,7 @@ idrinth.chat = {
352
371
try {
353
372
chat . lastChild . scrollIntoView ( false ) ;
354
373
} catch ( e ) {
355
- idrinth . log ( e ) ;
374
+ idrinth . core . log ( e ) ;
356
375
}
357
376
chat . lastChild . scrollTop = chat . lastChild . scrollHeight ;
358
377
}
@@ -448,7 +467,7 @@ idrinth.chat = {
448
467
window . setTimeout ( idrinth . chat . start , 1000 ) ;
449
468
}
450
469
window . setTimeout ( function ( ) {
451
- idrinth . runAjax (
470
+ idrinth . core . ajax . run (
452
471
'https://dotd.idrinth.de/' + idrinth . platform + '/chat-service/login/' ,
453
472
idrinth . chat . startLoginCallback ,
454
473
function ( reply ) {
@@ -463,7 +482,7 @@ idrinth.chat = {
463
482
) ;
464
483
} , 2500 ) ;
465
484
window . setTimeout ( function ( ) {
466
- idrinth . runAjax (
485
+ idrinth . core . ajax . run (
467
486
'https://dotd.idrinth.de/static/emoticons/data/' ,
468
487
function ( reply ) {
469
488
idrinth . chat . emotes = JSON . parse ( reply ) ;
@@ -477,33 +496,33 @@ idrinth.chat = {
477
496
} , 1 ) ;
478
497
} ,
479
498
create : function ( ) {
480
- idrinth . runAjax (
499
+ idrinth . core . ajax . run (
481
500
'https://dotd.idrinth.de/' + idrinth . platform + '/chat-service/create/' ,
482
501
idrinth . chat . joinCallback ,
483
502
function ( reply ) {
484
- idrinth . alert ( this . getMsg ( 'create.fail' ) ) ;
503
+ idrinth . core . alert ( this . getMsg ( 'create.fail' ) ) ;
485
504
} ,
486
505
function ( reply ) {
487
- idrinth . alert ( this . getMsg ( 'create.fail' ) ) ;
506
+ idrinth . core . alert ( this . getMsg ( 'create.fail' ) ) ;
488
507
} ,
489
508
document . getElementById ( 'idrinth-make-chat' ) . getElementsByTagName ( 'input' ) [ 0 ] . value
490
509
) ;
491
510
} ,
492
511
joinCallback : function ( reply ) {
493
512
if ( ! reply ) {
494
- idrinth . alert ( this . getMsg ( 'join.fail' ) ) ;
513
+ idrinth . core . alert ( this . getMsg ( 'join.fail' ) ) ;
495
514
return ;
496
515
}
497
516
reply = JSON . parse ( reply ) ;
498
517
if ( ! reply ) {
499
- idrinth . alert ( this . getMsg ( 'join.fail' ) ) ;
518
+ idrinth . core . alert ( this . getMsg ( 'join.fail' ) ) ;
500
519
return ;
501
520
}
502
521
if ( ! reply . success ) {
503
522
if ( reply . message ) {
504
- idrinth . alert ( reply . message ) ;
523
+ idrinth . core . alert ( reply . message ) ;
505
524
} else {
506
- idrinth . alert ( this . getMsg ( 'join.notwork' ) ) ;
525
+ idrinth . core . alert ( this . getMsg ( 'join.notwork' ) ) ;
507
526
}
508
527
return ;
509
528
}
@@ -515,14 +534,14 @@ idrinth.chat = {
515
534
users : { } ,
516
535
updateTimeout : null ,
517
536
add : function ( ) {
518
- idrinth . runAjax (
537
+ idrinth . core . ajax . run (
519
538
'https://dotd.idrinth.de/' + idrinth . platform + '/chat-service/join/' ,
520
539
idrinth . chat . joinCallback ,
521
540
function ( reply ) {
522
- idrinth . alert ( this . getMsg ( 'join.fail' ) ) ;
541
+ idrinth . core . alert ( this . getMsg ( 'join.fail' ) ) ;
523
542
} ,
524
543
function ( reply ) {
525
- idrinth . alert ( this . getMsg ( 'join.fail' ) ) ;
544
+ idrinth . core . alert ( this . getMsg ( 'join.fail' ) ) ;
526
545
} ,
527
546
JSON . stringify ( {
528
547
id : document . getElementById ( 'idrinth-add-chat' ) . getElementsByTagName ( 'input' ) [ 0 ] . value ,
@@ -562,20 +581,20 @@ idrinth.chat = {
562
581
} ,
563
582
loginCallback : function ( data ) {
564
583
if ( ! data ) {
565
- idrinth . alert ( this . getMsg ( 'login.fail' ) ) ;
584
+ idrinth . core . alert ( this . getMsg ( 'login.fail' ) ) ;
566
585
return ;
567
586
}
568
587
data = JSON . parse ( data ) ;
569
588
if ( ! data ) {
570
- idrinth . alert ( this . getMsg ( 'login.fail' ) ) ;
589
+ idrinth . core . alert ( this . getMsg ( 'login.fail' ) ) ;
571
590
return ;
572
591
}
573
592
if ( ! data . success && data . message && data [ 'allow-reg' ] ) {
574
- idrinth . confirm ( this . getMsg ( 'user.unknown' ) , 'idrinth.chat.register();' ) ;
593
+ idrinth . core . confirm ( this . getMsg ( 'user.unknown' ) , 'idrinth.chat.register();' ) ;
575
594
return ;
576
595
}
577
596
if ( ! data . success && data . message ) {
578
- idrinth . alert ( data . message ) ;
597
+ idrinth . core . alert ( data . message ) ;
579
598
return ;
580
599
}
581
600
if ( data . success ) {
@@ -586,7 +605,7 @@ idrinth.chat = {
586
605
idrinth . chat . join ( data . data ) ;
587
606
return ;
588
607
}
589
- idrinth . alert ( this . getMsg ( 'login.fail' ) ) ;
608
+ idrinth . core . alert ( this . getMsg ( 'login.fail' ) ) ;
590
609
} ,
591
610
register : function ( ) {
592
611
this . loginActions ( 'register' ) ;
@@ -622,7 +641,7 @@ idrinth.chat = {
622
641
type : 'li' ,
623
642
attributes : [ {
624
643
name : 'onclick' ,
625
- value : 'idrinth.runAjax (\'https://dotd.idrinth.de/' + idrinth . platform + '/chat-service/delete/' + element . getAttribute ( 'data-id' ) + '/\',idrinth.alert,idrinth.alert,idrinth.alert);this.parentNode.parentNode.removeChild(this.parentNode);'
644
+ value : 'idrinth.core.ajax.run (\'https://dotd.idrinth.de/' + idrinth . platform + '/chat-service/delete/' + element . getAttribute ( 'data-id' ) + '/\',idrinth.core. alert,idrinth.core. alert,idrinth.core .alert);this.parentNode.parentNode.removeChild(this.parentNode);'
626
645
} ]
627
646
} , {
628
647
type : 'li' ,
@@ -690,7 +709,7 @@ idrinth.chat = {
690
709
'relogin' : 'https://dotd.idrinth.de/' + idrinth . platform + '/chat-service/login/'
691
710
} ,
692
711
fail = function ( ) {
693
- idrinth . alert ( this . getMsg ( 'login.fail' ) ) ;
712
+ idrinth . core . alert ( this . getMsg ( 'login.fail' ) ) ;
694
713
} ,
695
714
timeout = function ( ) {
696
715
window . setTimeout ( idrinth . chat . login , 1 ) ;
@@ -716,6 +735,6 @@ idrinth.chat = {
716
735
headers . pass = chatLogin [ 1 ] . value ;
717
736
success = idrinth . chat . loginCallback ;
718
737
}
719
- idrinth . runAjax ( urls [ key ] , success , fail , timeout , JSON . stringify ( headers ) ) ;
738
+ idrinth . core . ajax . run ( urls [ key ] , success , fail , timeout , JSON . stringify ( headers ) ) ;
720
739
}
721
740
} ;
0 commit comments