7
7
'use strict' ;
8
8
9
9
// Zendesk new UI Jul 2021
10
- togglbutton . render (
11
- '.omni-conversation-pane>div>div:first-child:not(.toggl)' ,
12
- { observe : true } ,
13
- ( elem ) => {
14
- const getProject = ( ) => {
15
- const title = document . querySelector ( 'title' ) ;
16
- return title ? title . textContent . trim ( ) : '' ;
17
- } ;
18
-
19
- const getDescription = ( ) => {
20
- const ticketId = document . querySelector ( 'header div[data-selected=true]' ) . attributes [ 'data-entity-id' ] . value || ''
21
-
22
- const input = elem . querySelector ( 'input[aria-label=Subject]' ) ;
23
- const title = ( input ? input . value : '' ) . trim ( ) ;
24
-
25
- return [ `#${ ticketId } ` , title ] . filter ( Boolean ) . join ( ' ' ) ;
26
- } ;
27
-
28
- const link = togglbutton . createTimerLink ( {
29
- buttonType : 'minimal' ,
30
- className : 'zendesk--2021' ,
31
- description : getDescription ,
32
- projectName : getProject
33
- } ) ;
34
-
35
- elem . appendChild ( link ) ;
36
- }
37
- ) ;
10
+ setTimeout ( ( ) => {
11
+ togglbutton . render (
12
+ '.omni-conversation-pane>div>div:first-child:not(.toggl)' ,
13
+ { observe : true } ,
14
+ ( elem ) => {
15
+ const getProject = ( ) => {
16
+ const title = document . querySelector ( 'title' ) ;
17
+ return title ? title . textContent . trim ( ) : '' ;
18
+ } ;
19
+
20
+ const getDescription = ( ) => {
21
+ const ticketId = document . querySelector ( 'header div[data-selected=true]' ) . attributes [ 'data-entity-id' ] . value || ''
22
+
23
+ const input = elem . querySelector ( 'input[aria-label=Subject]' ) ;
24
+ const title = ( input ? input . value : '' ) . trim ( ) ;
25
+
26
+ return [ `#${ ticketId } ` , title ] . filter ( Boolean ) . join ( ' ' ) ;
27
+ } ;
28
+
29
+ const link = togglbutton . createTimerLink ( {
30
+ buttonType : 'minimal' ,
31
+ className : 'zendesk--2021' ,
32
+ description : getDescription ,
33
+ projectName : getProject
34
+ } ) ;
35
+
36
+ elem . appendChild ( link ) ;
37
+ }
38
+ ) ;
39
+ } , 1000 ) ;
38
40
39
41
// Zendesk pre-2021
40
- togglbutton . render (
41
- '.pane_header:not(.toggl)' ,
42
- { observe : true } ,
43
- function ( elem ) {
44
- let description ;
45
- const projectName = $ ( 'title' ) . textContent ;
46
-
47
- const titleFunc = function ( ) {
48
- const titleElem = $ ( '.editable .ember-view input' , elem ) ;
49
- const ticketNum = location . href . match ( / t i c k e t s \/ ( \d + ) / ) ;
50
-
51
- if ( titleElem !== null ) {
52
- description = titleElem . value . trim ( ) ;
42
+ setTimeout ( ( ) => {
43
+ togglbutton . render (
44
+ '.pane_header:not(.toggl)' ,
45
+ { observe : true } ,
46
+ function ( elem ) {
47
+ let description ;
48
+ const projectName = $ ( 'title' ) . textContent ;
49
+
50
+ const titleFunc = function ( ) {
51
+ const titleElem = $ ( '.editable .ember-view input' , elem ) ;
52
+ const ticketNum = location . href . match ( / t i c k e t s \/ ( \d + ) / ) ;
53
+
54
+ if ( titleElem !== null ) {
55
+ description = titleElem . value . trim ( ) ;
56
+ }
57
+
58
+ if ( ticketNum ) {
59
+ description = '#' + ticketNum [ 1 ] . trim ( ) + ' ' + description ;
60
+ }
61
+ return description ;
62
+ } ;
63
+
64
+ const link = togglbutton . createTimerLink ( {
65
+ className : 'zendesk' ,
66
+ description : titleFunc ,
67
+ projectName : projectName && projectName . split ( ' - ' ) . shift ( )
68
+ } ) ;
69
+
70
+ // Check for strange duplicate buttons. Don't know why this happens in Zendesk.
71
+ if ( elem . querySelector ( '.toggl-button' ) ) {
72
+ elem . removeChild ( elem . querySelector ( '.toggl-button' ) ) ;
53
73
}
54
74
55
- if ( ticketNum ) {
56
- description = '#' + ticketNum [ 1 ] . trim ( ) + ' ' + description ;
57
- }
58
- return description ;
59
- } ;
60
-
61
- const link = togglbutton . createTimerLink ( {
62
- className : 'zendesk' ,
63
- description : titleFunc ,
64
- projectName : projectName && projectName . split ( ' - ' ) . shift ( )
65
- } ) ;
66
-
67
- // Check for strange duplicate buttons. Don't know why this happens in Zendesk.
68
- if ( elem . querySelector ( '.toggl-button' ) ) {
69
- elem . removeChild ( elem . querySelector ( '.toggl-button' ) ) ;
75
+ elem . insertBefore ( link , elem . querySelector ( '.btn-group' ) ) ;
70
76
}
71
-
72
- elem . insertBefore ( link , elem . querySelector ( '.btn-group' ) ) ;
73
- }
74
- ) ;
77
+ ) ;
78
+ } , 1000 ) ;
75
79
76
80
const getDescription = ( ) => {
77
81
const ticketNum = location . href . match ( / t i c k e t s \/ ( \d + ) / ) ;
@@ -86,20 +90,22 @@ const getDescription = () => {
86
90
return '#' + id + ' ' + titleElem . value . trim ( ) ;
87
91
} ;
88
92
89
- togglbutton . render (
90
- '[data-test-id="customer-context-tab-navigation"]' ,
91
- { observe : true } ,
92
- function ( elem ) {
93
- // Manual check for existence in this SPA.
94
- if ( elem . querySelector ( '.toggl-button' ) ) return ;
95
- // If we can't get the description on this pass, let's skip and wait for the next one
96
- if ( ! getDescription ( ) ) return ;
97
-
98
- const link = togglbutton . createTimerLink ( {
99
- className : 'zendesk-agent-ws' ,
100
- description : getDescription
101
- } ) ;
102
-
103
- elem . prepend ( link ) ;
104
- }
105
- ) ;
93
+ setTimeout ( ( ) => {
94
+ togglbutton . render (
95
+ '[data-test-id="customer-context-tab-navigation"]' ,
96
+ { observe : true } ,
97
+ function ( elem ) {
98
+ // Manual check for existence in this SPA.
99
+ if ( elem . querySelector ( '.toggl-button' ) ) return ;
100
+ // If we can't get the description on this pass, let's skip and wait for the next one
101
+ if ( ! getDescription ( ) ) return ;
102
+
103
+ const link = togglbutton . createTimerLink ( {
104
+ className : 'zendesk-agent-ws' ,
105
+ description : getDescription
106
+ } ) ;
107
+
108
+ elem . prepend ( link ) ;
109
+ }
110
+ ) ;
111
+ } , 1000 ) ;
0 commit comments