131131
132132 this . baseUrl = location . protocol + '//' + location . host ;
133133 this . baseApiUrl = this . baseUrl + '/api/v4/' ;
134+ this . baseIconsUrl = this . getBaseIconsUrl ( ) ;
134135 this . userAuthenticated = this . isUserAuthenticated ( ) ;
135136 this . pipelineFeatureEnabled = this . isPipelineFeatureEnabled ( ) ;
136137 this . apiClient = new GitLabApiClient ( this . baseApiUrl , this . getCsrfToken ( ) ) ;
185186 return document . querySelector ( '.navbar-nav .header-user' ) ? true : false ;
186187 }
187188
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+
188210 /**
189211 * Determines if the project do uses the Gitlab "pipeline" feature.
190212 */
298320
299321 if ( this . userAuthenticated && this . preferences . enable_button_to_toggle_wip_status ) {
300322 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' ) +
302324 '</button> ' ;
303325
304326 this . parseHtmlAndPrepend (
320342
321343 break ;
322344 case 'icon' :
323- jiraTicketLinkLabel = '<i class="fa fa-ticket" aria-hidden="true"></i>' ;
345+ jiraTicketLinkLabel = this . buildSpriteIcon ( 'issues' ) ;
324346 jiraTicketLinkToolip = 'Jira ticket ' + mergeRequestNode . dataset . jiraTicketId ;
325347
326348 break ;
347369
348370 if ( this . preferences . enable_button_to_copy_mr_info ) {
349371 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' ) +
351373 '</button> ' ;
352374
353375 this . parseHtmlAndPrepend (
370392 // Copy source branch name button
371393 if ( this . preferences . enable_buttons_to_copy_source_and_target_branches_name ) {
372394 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' ) +
374396 '</button>' ;
375397 }
376398
377399 // Target branch name
378- newInfoLineToInject += ' <i class="fa fa- long-arrow-right" aria-hidden="true"></i> ' +
400+ newInfoLineToInject += ' ' + this . buildSpriteIcon ( ' long-arrow' ) + ' ' +
379401 '<span class="project-ref-path has-tooltip" title="Target branch">' +
380402 '<a class="ref-name" href="' + this . baseProjectUrl + '/-/commits/' + mergeRequest . target_branch + '">' + mergeRequest . target_branch + '</a>' +
381403 '</span>' ;
382404
383405 // Copy target branch name button
384406 if ( this . preferences . enable_buttons_to_copy_source_and_target_branches_name ) {
385407 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' ) +
387409 '</button>' ;
388410 }
389411
522544 */
523545 toggleMergeRequestWipStatus ( mergeRequestNode , toggleButton ) {
524546 toggleButton . disabled = true ;
525- toggleButton . firstChild . classList . remove ( 'fa-wrench' ) ;
526- toggleButton . firstChild . classList . add ( 'fa-spinner' , 'fa-spin' ) ;
527547
528548 let isWip = mergeRequestNode . dataset . isWip == 'true' ;
529549 let newTitle = '' ;
547567 mergeRequestNode . querySelector ( '.merge-request-title-text a' ) . textContent = responseData . title ;
548568 } ) . finally ( function ( ) {
549569 toggleButton . disabled = false ;
550- toggleButton . firstChild . classList . add ( 'fa-wrench' ) ;
551- toggleButton . firstChild . classList . remove ( 'fa-spinner' , 'fa-spin' ) ;
552570 } ) ;
553571 }
554572
575593 return placeholders [ placeholder ] ;
576594 } ) . trim ( ) ;
577595 }
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+ }
578605 }
579606
580607 let cs = new ContentScript ( ) ;
581- } ( this ) ) ;
608+ } ( this ) ) ;
0 commit comments