@@ -16,65 +16,81 @@ idrinth.observer = {
1616 * @param {HTMLElement } element
1717 * @returns {undefined }
1818 */
19- var processName = function ( element ) {
20- var name = '' ;
21- try {
22- name = idrinth . names . parse ( element ) ;
23- } catch ( e ) {
24- return ;
25- }
26- if ( ! name ) {
27- return ;
28- }
29- if ( ! idrinth . names . users [ name . toLowerCase ( ) ] && name . length > 0 ) {
30- idrinth . names . users [ name . toLowerCase ( ) ] = { } ;
31- idrinth . core . ajax . runHome ( 'users-service/add/' + encodeURIComponent ( name ) + '/' ) ;
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 ) {
44+ return ;
45+ }
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+ }
3257 }
3358 } ;
3459 /**
35- *
60+ *
3661 * @param {HTMLElement } element
3762 * @returns {undefined }
3863 */
39- var handleLink = function ( element ) {
40- var href = element . getAttribute ( 'href' ) ;
41- if ( href && href . match ( / a c t i o n _ t y p e = r a i d h e l p / ) ) {
42- var hash = '' ;
43- var id = '' ;
44- href = href . replace ( / ^ .* \? / , '' ) ;
45- var parts = href . split ( "&" ) ;
46- for ( var count = 0 ; count < parts . length ; count ++ ) {
47- if ( parts [ count ] . match ( 'raid_id=' ) ) {
48- id = parts [ count ] . split ( '=' ) [ 1 ] ;
49- } else if ( parts [ count ] . match ( 'hash=' ) ) {
50- hash = parts [ count ] . split ( '=' ) [ 1 ] ;
51- } else if ( parts [ count ] . match ( 'serverid=2' ) && ! idrinth . settings . get ( "world" ) ) {
52- return ;
53- } else if ( ! parts [ count ] . match ( 'server_id=2' ) && idrinth . settings . get ( "world" ) ) {
54- return ;
55- }
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 ;
5676 }
57- if ( ! id || ! hash ) {
77+ if ( ! name ) {
5878 return ;
5979 }
60- idrinth . raids . private [ id ] = hash ;
61- 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 ] ) ;
6288 }
6389 } ;
6490 mutations . forEach ( function ( mutation ) {
6591 mutation . addedNodes . forEach ( function ( node ) {
66- if ( node . tagName === 'A' || node . tagName === 'a' ) {
67- handleLink ( node ) ;
68- } else {
69- var elements = node . getElementsByTagName ( 'a' ) ;
70- for ( var count = 0 ; count < elements . length ; count ++ ) {
71- handleLink ( elements [ count ] ) ;
72- }
73- }
74- var el = node . getElementsByClassName ( 'username' ) ;
75- for ( var count = el . length - 1 ; count >= 0 ; count -- ) {
76- processName ( el [ count ] ) ;
77- }
92+ checkLinks ( node ) ;
93+ checkNames ( node ) ;
7894 } ) ;
7995 } ) ;
8096 } ,
0 commit comments