131
131
132
132
this . baseUrl = location . protocol + '//' + location . host ;
133
133
this . baseApiUrl = this . baseUrl + '/api/v4/' ;
134
+ this . baseIconsUrl = this . getBaseIconsUrl ( ) ;
134
135
this . userAuthenticated = this . isUserAuthenticated ( ) ;
135
136
this . pipelineFeatureEnabled = this . isPipelineFeatureEnabled ( ) ;
136
137
this . apiClient = new GitLabApiClient ( this . baseApiUrl , this . getCsrfToken ( ) ) ;
185
186
return document . querySelector ( '.navbar-nav .header-user' ) ? true : false ;
186
187
}
187
188
189
+ /**
190
+ * Return the base URL to the SVG icons file.
191
+ */
192
+ getBaseIconsUrl ( ) {
193
+ let svgUse = document . querySelector ( 'svg.s16 > use' ) ;
194
+
195
+ if ( ! svgUse || ! svgUse . href . baseVal ) {
196
+ return null ;
197
+ }
198
+
199
+ let url = svgUse . href . baseVal ;
200
+
201
+ if ( url . startsWith ( '/' ) ) {
202
+ url = this . baseUrl + url ;
203
+ }
204
+
205
+ let parsedUrl = new URL ( url ) ;
206
+
207
+ return parsedUrl . protocol + '//' + parsedUrl . host + '/' + parsedUrl . pathname ;
208
+ }
209
+
188
210
/**
189
211
* Determines if the project do uses the Gitlab "pipeline" feature.
190
212
*/
298
320
299
321
if ( this . userAuthenticated && this . preferences . enable_button_to_toggle_wip_status ) {
300
322
let toggleWipStatusButton = '<button class="btn btn-secondary btn-md btn-default btn-transparent btn-clipboard has-tooltip gmrle-toggle-wip-status" title="Toggle WIP status" style="padding-left: 0">' +
301
- '<i class="fa fa-wrench" aria-hidden="true"></i>' +
323
+ this . buildSpriteIcon ( 'lock' ) +
302
324
'</button> ' ;
303
325
304
326
this . parseHtmlAndPrepend (
320
342
321
343
break ;
322
344
case 'icon' :
323
- jiraTicketLinkLabel = '<i class="fa fa-ticket" aria-hidden="true"></i>' ;
345
+ jiraTicketLinkLabel = this . buildSpriteIcon ( 'issues' ) ;
324
346
jiraTicketLinkToolip = 'Jira ticket ' + mergeRequestNode . dataset . jiraTicketId ;
325
347
326
348
break ;
347
369
348
370
if ( this . preferences . enable_button_to_copy_mr_info ) {
349
371
let copyMrInfoButton = '<button class="btn btn-secondary btn-md btn-default btn-transparent btn-clipboard has-tooltip gmrle-copy-mr-info" title="Copy Merge Request info" style="padding-left: 0">' +
350
- '<i class="fa fa- share-square-o" aria-hidden="true"></i>' +
372
+ this . buildSpriteIcon ( ' share' ) +
351
373
'</button> ' ;
352
374
353
375
this . parseHtmlAndPrepend (
370
392
// Copy source branch name button
371
393
if ( this . preferences . enable_buttons_to_copy_source_and_target_branches_name ) {
372
394
newInfoLineToInject += ' <button class="btn btn-secondary btn-md btn-default btn-transparent btn-clipboard has-tooltip gmrle-copy-branch-name" title="Copy branch name" data-branch-name-to-copy="source">' +
373
- '<i class="fa fa-clipboard" aria-hidden="true"></i>' +
395
+ this . buildSpriteIcon ( 'copy-to-clipboard' ) +
374
396
'</button>' ;
375
397
}
376
398
377
399
// Target branch name
378
- newInfoLineToInject += ' <i class="fa fa- long-arrow-right" aria-hidden="true"></i> ' +
400
+ newInfoLineToInject += ' ' + this . buildSpriteIcon ( ' long-arrow' ) + ' ' +
379
401
'<span class="project-ref-path has-tooltip" title="Target branch">' +
380
402
'<a class="ref-name" href="' + this . baseProjectUrl + '/-/commits/' + mergeRequest . target_branch + '">' + mergeRequest . target_branch + '</a>' +
381
403
'</span>' ;
382
404
383
405
// Copy target branch name button
384
406
if ( this . preferences . enable_buttons_to_copy_source_and_target_branches_name ) {
385
407
newInfoLineToInject += ' <button class="btn btn-secondary btn-md btn-default btn-transparent btn-clipboard has-tooltip gmrle-copy-branch-name" title="Copy branch name" data-branch-name-to-copy="target">' +
386
- '<i class="fa fa-clipboard" aria-hidden="true"></i>' +
408
+ this . buildSpriteIcon ( 'copy-to-clipboard' ) +
387
409
'</button>' ;
388
410
}
389
411
522
544
*/
523
545
toggleMergeRequestWipStatus ( mergeRequestNode , toggleButton ) {
524
546
toggleButton . disabled = true ;
525
- toggleButton . firstChild . classList . remove ( 'fa-wrench' ) ;
526
- toggleButton . firstChild . classList . add ( 'fa-spinner' , 'fa-spin' ) ;
527
547
528
548
let isWip = mergeRequestNode . dataset . isWip == 'true' ;
529
549
let newTitle = '' ;
547
567
mergeRequestNode . querySelector ( '.merge-request-title-text a' ) . textContent = responseData . title ;
548
568
} ) . finally ( function ( ) {
549
569
toggleButton . disabled = false ;
550
- toggleButton . firstChild . classList . add ( 'fa-wrench' ) ;
551
- toggleButton . firstChild . classList . remove ( 'fa-spinner' , 'fa-spin' ) ;
552
570
} ) ;
553
571
}
554
572
575
593
return placeholders [ placeholder ] ;
576
594
} ) . trim ( ) ;
577
595
}
596
+
597
+ /**
598
+ * Generate the HTML code corresponding to an SVG icon.
599
+ */
600
+ buildSpriteIcon ( iconName ) {
601
+ return '<svg class="s16" data-testid="' + iconName + '-icon">' +
602
+ '<use xlink:href="' + this . baseIconsUrl + '#' + iconName + '"></use>' +
603
+ '</svg>' ;
604
+ }
578
605
}
579
606
580
607
let cs = new ContentScript ( ) ;
581
- } ( this ) ) ;
608
+ } ( this ) ) ;
0 commit comments