@@ -35,10 +35,10 @@ function onInputValueChange(e) {
35
35
function initInputArea ( ) {
36
36
const textArea = document . getElementById ( 'new_comment_field' ) ;
37
37
if ( textArea ) {
38
- textArea . addEventListener ( 'change' , e => {
38
+ textArea . addEventListener ( 'change' , ( e ) => {
39
39
onInputValueChange ( e ) ;
40
40
} ) ;
41
- textArea . addEventListener ( 'input' , e => {
41
+ textArea . addEventListener ( 'input' , ( e ) => {
42
42
onInputValueChange ( e ) ;
43
43
} ) ;
44
44
}
@@ -58,7 +58,7 @@ async function deleteNote(noteId) {
58
58
59
59
// Remove deleted note from dom
60
60
const commentBoxes = document . querySelectorAll ( '.private-note' ) ;
61
- commentBoxes . forEach ( commentBox => {
61
+ commentBoxes . forEach ( ( commentBox ) => {
62
62
const commentBoxPrivateId = commentBox . getAttribute ( 'private-id' ) ;
63
63
if ( commentBoxPrivateId === noteId ) {
64
64
commentBox . remove ( ) ;
@@ -111,13 +111,27 @@ function createPrivateNoteAddButton() {
111
111
button . disabled = textArea && ! textArea . value ;
112
112
button . onclick = async ( ) => {
113
113
button . disabled = true ;
114
- const commentBoxes = document . querySelectorAll (
114
+ let commentBoxes = document . querySelectorAll (
115
115
'[data-gid]:not([id]):not(.merge-status-list-wrapper).js-timeline-item' ,
116
116
) ;
117
+ let extraClass = '' ;
118
+ let isDiscussionBox = false ;
119
+ if ( commentBoxes . length === 0 ) {
120
+ commentBoxes = document . querySelectorAll ( '.js-discussion' ) ;
121
+ if ( commentBoxes . length ) {
122
+ extraClass = 'ml-0 pl-0 ml-md-6 pl-md-3' ;
123
+ isDiscussionBox = true ;
124
+ }
125
+ }
117
126
const commentBoxCount = commentBoxes . length ;
118
127
// Find nearest comment id
119
128
let nearestBox = commentBoxes [ commentBoxCount - 1 ] ;
120
- nearestCommentId = nearestBox . getAttribute ( 'data-gid' ) ;
129
+ if ( isDiscussionBox ) {
130
+ const box = nearestBox . firstElementChild ;
131
+ nearestCommentId = box . getAttribute ( 'data-gid' ) ;
132
+ } else {
133
+ nearestCommentId = nearestBox . getAttribute ( 'data-gid' ) ;
134
+ }
121
135
122
136
try {
123
137
const { issueId, noteType, projectName, repoOwner } = urlAttributes ;
@@ -139,7 +153,7 @@ function createPrivateNoteAddButton() {
139
153
) {
140
154
nearestBox = nearestBox . nextSibling ;
141
155
}
142
- nearestBox . after ( createNoteBox ( allNotes [ allNotes . length - 1 ] ) ) ;
156
+ nearestBox . after ( createNoteBox ( allNotes [ allNotes . length - 1 ] , extraClass ) ) ;
143
157
bindDeleteEventToNote ( newlyCreatedNote ) ;
144
158
bindToggleVisibilityToNote ( newlyCreatedNote ) ;
145
159
@@ -161,7 +175,7 @@ async function injectContent(apiCall) {
161
175
const actionBtns = document . querySelector ( '#partial-new-comment-form-actions > div' ) ;
162
176
let commentBtn = { } ;
163
177
if ( actionBtns ) {
164
- [ ] . forEach . call ( actionBtns . children , btn => {
178
+ [ ] . forEach . call ( actionBtns . children , ( btn ) => {
165
179
if ( btn . children . length && btn . children [ 0 ] && btn . children [ 0 ] . innerText === 'Comment' ) {
166
180
commentBtn = btn ;
167
181
}
@@ -186,7 +200,7 @@ async function injectContent(apiCall) {
186
200
const positionMarker = document . getElementById ( 'partial-new-comment-form-actions' ) ;
187
201
// similar comments hide the gitex comments so opening the collapsible similar comments
188
202
const collapsed = document . querySelectorAll ( '.Details-element.details-reset' ) ;
189
- collapsed . forEach ( el => {
203
+ collapsed . forEach ( ( el ) => {
190
204
el . setAttribute ( 'open' , true ) ;
191
205
} ) ;
192
206
if ( positionMarker ) {
@@ -209,23 +223,29 @@ async function injectContent(apiCall) {
209
223
} ) ;
210
224
if ( allNotes . length ) {
211
225
// Iterate all the comments and append notes
212
- const commentBoxes = document . querySelectorAll (
226
+ let commentBoxes = document . querySelectorAll (
213
227
'[data-gid]:not([id]):not(.merge-status-list-wrapper)' ,
214
228
) ;
215
-
216
- commentBoxes . forEach ( commentBox => {
229
+ let extraClass = '' ;
230
+ if ( commentBoxes . length === 0 ) {
231
+ commentBoxes = document . querySelectorAll ( '.js-discussion' ) ;
232
+ if ( commentBoxes . length ) {
233
+ extraClass = 'ml-0 pl-0 ml-md-6 pl-md-3' ;
234
+ }
235
+ }
236
+ commentBoxes . forEach ( ( commentBox ) => {
217
237
const commentId = commentBox . getAttribute ( 'data-gid' ) ;
218
238
219
- const findNotesNearestToComment = obj => obj . nearestCommentId === commentId ;
239
+ const findNotesNearestToComment = ( obj ) => obj . nearestCommentId === commentId ;
220
240
const notesNearestToCommentBox = allNotes . filter ( findNotesNearestToComment ) ;
221
241
const sortedNotes = notesNearestToCommentBox . sort (
222
242
( a , b ) => new Date ( b . createdAt ) - new Date ( a . createdAt ) ,
223
243
) ;
224
- sortedNotes . forEach ( element => {
244
+ sortedNotes . forEach ( ( element ) => {
225
245
const { _id : noteId } = element ;
226
246
if ( ! addedNoteIds . includes ( noteId ) ) {
227
247
addedNoteIds . push ( noteId ) ;
228
- commentBox . after ( createNoteBox ( element ) ) ;
248
+ commentBox . after ( createNoteBox ( element , extraClass ) ) ;
229
249
if ( commentBox ) {
230
250
bindDeleteEventToNote ( element ) ;
231
251
bindToggleVisibilityToNote ( element ) ;
@@ -244,7 +264,7 @@ function init() {
244
264
const {
245
265
location : { href : URL } ,
246
266
} = document ;
247
- window . chrome . storage . sync . get ( [ 'githubPrivateCommentToken' ] , result => {
267
+ window . chrome . storage . sync . get ( [ 'githubPrivateCommentToken' ] , ( result ) => {
248
268
const authToken = result . githubPrivateCommentToken ;
249
269
250
270
if ( ! authToken ) {
@@ -261,7 +281,7 @@ window.onload = () => {
261
281
init ( ) ;
262
282
} ;
263
283
264
- window . addEventListener ( 'message' , e => {
284
+ window . addEventListener ( 'message' , ( e ) => {
265
285
if ( e . data && e . data . type === 'githubPrivateCommentToken' ) {
266
286
window . chrome . storage . sync . set ( { githubPrivateCommentToken : e . data . value } ) ;
267
287
}
@@ -283,8 +303,8 @@ window.addEventListener('message', e => {
283
303
) ;
284
304
function addSignoutListener ( ) {
285
305
const logoutBtns = document . querySelectorAll ( 'form[action="/logout"] [type="submit"]' ) ;
286
- const handler = e => {
306
+ const handler = ( e ) => {
287
307
chrome . runtime . sendMessage ( { logout : true } ) ;
288
308
} ;
289
- logoutBtns . forEach ( btn => btn . addEventListener ( 'click' , handler ) ) ;
309
+ logoutBtns . forEach ( ( btn ) => btn . addEventListener ( 'click' , handler ) ) ;
290
310
}
0 commit comments