@@ -61,7 +61,10 @@ TicketConsume = {
6161 if ( TicketConsume . user . role == 'agent' ) {
6262 try {
6363 chrome . runtime . sendMessage ( { name : 'openTicketConsumeTab' } ) ;
64- } catch ( error ) { }
64+ } catch ( error ) {
65+ console . log ( error ) ;
66+
67+ }
6568 }
6669 } ) ;
6770 }
@@ -78,23 +81,28 @@ TicketConsume = {
7881 console . log ( data ) ;
7982 $ . extend ( true , TicketConsume . data , data )
8083
81- $ ( '[data-test-id="customercontext-userinfo-organization"] [href*="organizations"]' ) . each ( function ( index , ticketOrg ) {
82- let $ticketOrg = $ ( ticketOrg ) ;
83- if ( typeof $ticketOrg . data ( 'ovserved-org' ) === 'undefined' ) {
84-
85- $ticketOrg . data ( 'ovserved-org' , true ) ;
86- let findOrgId = $ticketOrg . attr ( 'href' ) . match ( / \d { 1 , } / ) ;
87-
88- if ( findOrgId ) {
89- let orgId = findOrgId [ 0 ] , orgName = $ticketOrg . text ( ) . trim ( ) . toLowerCase ( ) ;
90-
91- TicketConsume . observerInit ( orgId , orgName , $ticketOrg ) ;
92- }
84+ $ ( document ) . off ( 'DOMSubtreeModified' ) . on ( 'DOMSubtreeModified' , function ( event ) {
85+ if ( $ ( event . target ) . find ( '[href*="organizations"]' ) . length ) {
86+ $ ( '[data-test-id="customercontext-userinfo-organization"] [href*="organizations"]' ) . each ( function ( index , ticketOrg ) {
87+ let $ticketOrg = $ ( ticketOrg ) ;
88+ if ( typeof $ticketOrg . data ( 'ovserved-org' ) === 'undefined' ) {
89+
90+ $ticketOrg . data ( 'ovserved-org' , true ) ;
91+ let findOrgId = $ticketOrg . attr ( 'href' ) . match ( / \d { 1 , } / ) ;
92+
93+ if ( findOrgId ) {
94+ let orgId = findOrgId [ 0 ] , orgName = $ticketOrg . text ( ) . trim ( ) . toLowerCase ( ) ;
95+
96+ TicketConsume . observerInit ( orgId , orgName , $ticketOrg ) ;
97+ }
98+ }
99+ } )
100+ TicketConsume . initIntervals ( ) ;
93101 }
94- } )
95- TicketConsume . initIntervals ( ) ;
102+ } ) ;
96103 } catch ( error ) {
97104 log ( 'TicketConsume invalid data' , 'danger' ) ;
105+ console . log ( message . data ) ;
98106 }
99107 } ) ;
100108 } ,
@@ -133,7 +141,7 @@ TicketConsume = {
133141
134142 ZendeskApi_showOrganization ( TicketConsume . data [ orgName ] . id ) . then ( ( responseData ) => {
135143 let newData = TicketConsume . getNotesText ( responseData . organization . notes ) ;
136- newData += TicketConsume . splitVal + '\n' + JSON . stringify ( TicketConsume . data [ orgName ] . customData ) ;
144+ newData += `\n\n ${ TicketConsume . splitVal } \n ${ JSON . stringify ( TicketConsume . data [ orgName ] . customData ) } ` ;
137145
138146 ZendeskApi_updateOrganization ( TicketConsume . data [ orgName ] . id , {
139147 "organization" : { "notes" : newData }
@@ -344,7 +352,7 @@ TicketConsume = {
344352 let json = [ ] ,
345353 valueSplitted = value . trim ( ) . split ( TicketConsume . splitVal ) ;
346354
347- if ( value . trim ( ) . length && valueSplitted ) {
355+ if ( value . trim ( ) . length && valueSplitted && value . trim ( ) . match ( TicketConsume . splitVal ) ) {
348356 json = valueSplitted [ valueSplitted . length - 1 ] ;
349357 try {
350358 json = JSON . parse ( json ) ;
@@ -372,6 +380,7 @@ TicketConsume = {
372380 if ( typeof TicketConsume . user !== 'undefined' && TicketConsume . user . role == 'agent' ) {
373381 ZendeskApi_showOrganization ( orgId ) . then ( ( responseData ) => {
374382 let customData = TicketConsume . parseOrganizationNotes ( responseData . organization . notes ) ;
383+
375384 if ( TicketConsume . data [ orgName ] ) {
376385 TicketConsume . data [ orgName ] . id = orgId ;
377386 TicketConsume . data [ orgName ] . customData = customData ;
0 commit comments