@@ -13,92 +13,84 @@ const getProject = () => {
13
13
return project ? project . textContent . trim ( ) : ''
14
14
}
15
15
16
- const cardContainerSelector = '.window-wrapper'
17
-
18
- togglbutton . render (
19
- '#card-back-name:not(.toggl)' ,
20
- { observe : true , debounceInterval : 1000 } ,
21
- ( elem ) => {
22
- const actionsWrapper = $ (
23
- '#layer-manager-card-back section:nth-child(4) > ul' ,
24
- )
25
-
26
- if ( ! actionsWrapper ) {
27
- return
28
- }
29
-
30
- const getDescription = ( ) => {
31
- const description = $ ( '#card-back-name' )
32
- return description ? description . textContent . trim ( ) : ''
33
- }
34
-
35
- const container = createTag ( 'div' , 'button-link trello-tb-wrapper' )
36
-
37
- const link = togglbutton . createTimerLink ( {
38
- className : 'trello' ,
39
- description : getDescription ,
40
- projectName : getProject ,
41
- container : '[data-testid="card-back-name"]' ,
42
- autoTrackable : true ,
43
- } )
44
-
45
- // Pass through click on Trello button to the timer link
46
- container . addEventListener ( 'click' , ( e ) => {
47
- link . click ( )
48
- } )
49
-
50
- container . appendChild ( link )
16
+ const getCardName = ( ) => {
17
+ return document . querySelector ( '#card-back-name' ) ?. textContent . trim ( )
18
+ }
51
19
52
- actionsWrapper . prepend ( container )
20
+ togglbutton . inject (
21
+ {
22
+ node : '[data-testid="card-back-move-card-button"]:not(.toggl)' ,
23
+ renderer : ( element ) => {
24
+ const container = createTag ( 'li' , 'button-link trello-tb-wrapper' )
25
+
26
+ const link = togglbutton . createTimerLink ( {
27
+ className : 'trello' ,
28
+ description : getCardName ,
29
+ projectName : getProject ,
30
+ container : '[data-testid="card-back-name"]' ,
31
+ autoTrackable : true ,
32
+ } )
33
+
34
+ // Pass through click on Trello button to the timer link
35
+ container . addEventListener ( 'click' , ( e ) => {
36
+ link . click ( )
37
+ } )
38
+
39
+ container . appendChild ( link )
40
+
41
+ element . parentNode . parentNode . prepend ( container , element )
42
+ } ,
53
43
} ,
54
- cardContainerSelector ,
44
+ { observe : true } ,
55
45
)
56
46
57
47
/* Checklist buttons */
58
- togglbutton . render (
59
- '[data-testid="check-item-container"]:not(.toggl)' ,
60
- { observe : true , debounceInterval : 1000 } ,
61
- ( elem ) => {
62
- const getTitleText = ( ) => {
63
- const description = $ ( '#card-back-name' )
64
- return description ? description . textContent . trim ( ) : ''
65
- }
66
-
67
- const getTaskText = ( ) => {
68
- const task = $ ( '.ak-renderer-wrapper' , elem )
69
- return task ? task . textContent . trim ( ) : ''
70
- }
71
-
72
- const getDescription = ( ) => {
73
- return `${ getTitleText ( ) } - ${ getTaskText ( ) } `
74
- }
75
-
76
- const link = togglbutton . createTimerLink ( {
77
- className : 'trello-list' ,
78
- buttonType : 'minimal' ,
79
- projectName : getProject ,
80
- description : getDescription ,
81
- container : '[data-testid="card-back-name"]' ,
82
- } )
83
- const wrapper = document . createElement ( 'span' )
84
- wrapper . classList . add ( 'checklist-item-menu' )
85
- wrapper . style . display = 'flex'
86
- wrapper . style . alignItems = 'center'
87
- wrapper . style . marginLeft = '4px'
88
- wrapper . appendChild ( link )
89
-
90
- // Add StopPropagation to prevent the card from closing.
91
- wrapper . addEventListener ( 'click' , ( e ) => {
92
- e . preventDefault ( )
93
- e . stopPropagation ( )
94
-
95
- // Click on the Toggl button
96
- link . querySelector ( 'button' ) . click ( )
97
- } )
98
48
99
- elem
100
- . querySelector ( '[data-testid="check-item-hover-buttons"]' )
101
- . appendChild ( wrapper )
49
+ togglbutton . injectMany (
50
+ {
51
+ node : '[data-testid="check-item-hover-buttons"]:not(.toggl)' ,
52
+ renderer : ( elements ) => {
53
+ // Loop through all the checklist items.
54
+ for ( const element of elements ) {
55
+ const getTaskText = ( ) => {
56
+ return (
57
+ element . parentNode
58
+ . querySelector ( '.ak-renderer-wrapper' )
59
+ ?. textContent . trim ( ) ?? ''
60
+ )
61
+ }
62
+
63
+ const getDescription = ( ) => {
64
+ return `${ getCardName ( ) } - ${ getTaskText ( ) } `
65
+ }
66
+
67
+ const link = togglbutton . createTimerLink ( {
68
+ className : 'trello-list' ,
69
+ buttonType : 'minimal' ,
70
+ projectName : getProject ,
71
+ description : getDescription ,
72
+ container : '[data-testid="card-back-name"]' ,
73
+ } )
74
+
75
+ const wrapper = document . createElement ( 'span' )
76
+ wrapper . classList . add ( 'checklist-item-menu' )
77
+ wrapper . style . display = 'flex'
78
+ wrapper . style . alignItems = 'center'
79
+ wrapper . style . marginLeft = '4px'
80
+ wrapper . appendChild ( link )
81
+
82
+ // Add StopPropagation to prevent the card from closing.
83
+ wrapper . addEventListener ( 'click' , ( e ) => {
84
+ e . preventDefault ( )
85
+ e . stopPropagation ( )
86
+
87
+ // Click on the Toggl button
88
+ link . querySelector ( 'button' ) . click ( )
89
+ } )
90
+
91
+ element . appendChild ( wrapper )
92
+ }
93
+ } ,
102
94
} ,
103
- cardContainerSelector ,
95
+ { observe : true } ,
104
96
)
0 commit comments