@@ -12,45 +12,85 @@ idrinth.observer = {
1212 */
1313 handle : function ( mutations , isPrivate ) {
1414 /**
15- *
15+ *
1616 * @param {HTMLElement } element
1717 * @returns {undefined }
1818 */
19- var handleLink = function ( element ) {
20- var href = element . getAttribute ( 'href' ) ;
21- if ( href && href . match ( / a c t i o n _ t y p e = r a i d h e l p / ) ) {
22- var hash = '' ;
23- var id = '' ;
24- href = href . replace ( / ^ .* \? / , '' ) ;
25- var parts = href . split ( "&" ) ;
26- for ( var count = 0 ; count < parts . length ; count ++ ) {
27- if ( parts [ count ] . match ( 'raid_id=' ) ) {
28- id = parts [ count ] . split ( '=' ) [ 1 ] ;
29- } else if ( parts [ count ] . match ( 'hash=' ) ) {
30- hash = parts [ count ] . split ( '=' ) [ 1 ] ;
31- } else if ( parts [ count ] . match ( 'serverid=2' ) && ! idrinth . settings . get ( "world" ) ) {
32- return ;
33- } else if ( ! parts [ count ] . match ( 'server_id=2' ) && idrinth . settings . get ( "world" ) ) {
19+ var checkLinks = function ( node ) {
20+ /**
21+ *
22+ * @param {HTMLElement } element
23+ * @returns {undefined }
24+ */
25+ var handleLink = function ( element ) {
26+ var href = element . getAttribute ( 'href' ) ;
27+ if ( href && href . match ( / a c t i o n _ t y p e = r a i d h e l p / ) ) {
28+ var hash = '' ;
29+ var id = '' ;
30+ href = href . replace ( / ^ .* \? / , '' ) ;
31+ var parts = href . split ( "&" ) ;
32+ for ( var count = 0 ; count < parts . length ; count ++ ) {
33+ if ( parts [ count ] . match ( 'raid_id=' ) ) {
34+ id = parts [ count ] . split ( '=' ) [ 1 ] ;
35+ } else if ( parts [ count ] . match ( 'hash=' ) ) {
36+ hash = parts [ count ] . split ( '=' ) [ 1 ] ;
37+ } else if ( parts [ count ] . match ( 'serverid=2' ) && ! idrinth . settings . get ( "world" ) ) {
38+ return ;
39+ } else if ( ! parts [ count ] . match ( 'server_id=2' ) && idrinth . settings . get ( "world" ) ) {
40+ return ;
41+ }
42+ }
43+ if ( ! id || ! hash ) {
3444 return ;
3545 }
46+ idrinth . raids . private [ id ] = hash ;
47+ idrinth . core . ajax . runHome ( 'get-raid-service/' + id + '/' + hash + '/' ) ;
48+ }
49+ } ;
50+ if ( node . tagName === 'A' || node . tagName === 'a' ) {
51+ handleLink ( node ) ;
52+ } else {
53+ var elements = node . getElementsByTagName ( 'a' ) ;
54+ for ( var count = 0 ; count < elements . length ; count ++ ) {
55+ handleLink ( elements [ count ] ) ;
56+ }
57+ }
58+ } ;
59+ /**
60+ *
61+ * @param {HTMLElement } element
62+ * @returns {undefined }
63+ */
64+ var checkNames = function ( node ) {
65+ /**
66+ *
67+ * @param {HTMLElement } element
68+ * @returns {undefined }
69+ */
70+ var processName = function ( element ) {
71+ var name = '' ;
72+ try {
73+ name = idrinth . names . parse ( element ) ;
74+ } catch ( e ) {
75+ return ;
3676 }
37- if ( ! id || ! hash ) {
77+ if ( ! name ) {
3878 return ;
3979 }
40- idrinth . raids . private [ id ] = hash ;
41- idrinth . core . ajax . runHome ( 'get-raid-service/' + id + '/' + hash + '/' ) ;
80+ if ( ! idrinth . names . users [ name . toLowerCase ( ) ] && name . length > 0 ) {
81+ idrinth . names . users [ name . toLowerCase ( ) ] = { } ;
82+ idrinth . core . ajax . runHome ( 'users-service/add/' + encodeURIComponent ( name ) + '/' ) ;
83+ }
84+ } ;
85+ var elements = node . getElementsByClassName ( 'username' ) ;
86+ for ( var count = elements . length - 1 ; count >= 0 ; count -- ) {
87+ processName ( elements [ count ] ) ;
4288 }
4389 } ;
4490 mutations . forEach ( function ( mutation ) {
4591 mutation . addedNodes . forEach ( function ( node ) {
46- if ( node . tagName === 'A' || node . tagName === 'a' ) {
47- handleLink ( node ) ;
48- } else {
49- var elements = node . getElementsByTagName ( 'a' ) ;
50- for ( var count = 0 ; count < elements . length ; count ++ ) {
51- handleLink ( elements [ count ] ) ;
52- }
53- }
92+ checkLinks ( node ) ;
93+ checkNames ( node ) ;
5494 } ) ;
5595 } ) ;
5696 } ,
@@ -62,12 +102,12 @@ idrinth.observer = {
62102 if ( idrinth . platform !== 'kongregate' ) {
63103 return ;
64104 }
65- if (
66- ! document . getElementById ( "chat_rooms_container" ) ||
67- ! document . getElementById ( "chat_rooms_container" ) . children [ 1 ] ||
68- ! document . getElementById ( "chat_rooms_container" ) . children [ 1 ] . children [ 2 ]
69- ) {
70- idrinth . core . timeouts . add ( 'observer' , idrinth . observer . start , 500 , 1 ) ;
105+ if (
106+ ! document . getElementById ( "chat_rooms_container" ) ||
107+ ! document . getElementById ( "chat_rooms_container" ) . children [ 1 ] ||
108+ ! document . getElementById ( "chat_rooms_container" ) . children [ 1 ] . children [ 2 ]
109+ ) {
110+ idrinth . core . timeouts . add ( 'observer' , idrinth . observer . start , 500 , 1 ) ;
71111 return ;
72112 }
73113 idrinth . observer . list . chat = new MutationObserver ( function ( mutations ) {
0 commit comments