Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Commit 24f0060

Browse files
authored
Merge pull request #13 from EpocDotFr/replace-fa-icons
Replace Font Awesome icons
2 parents f6c7282 + eb63137 commit 24f0060

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ A browser extension that enhance all Merge Requests lists on any instance of Git
2727

2828
## Prerequisites
2929

30-
- **GitLab**: 9.0 or above or GitLab.com (this addon requires GitLab API v4)
30+
- **GitLab**: the latest available version of GitLab or GitLab.com
3131
- **Firefox**: >= 63 (because this extension uses the `clipboard.writeText` API)
3232
- **Chrome**: >= 66 (because this extension uses the `clipboard.writeText` API)
3333

@@ -56,6 +56,10 @@ It would be great, however the extension has no reliable way to do that due to a
5656

5757
That was the initial idea for the 1.6 release, however it's not possible due to a technical GitLab limitation.
5858

59+
- Some feature looks broken on GitLab version [old version of GitLab]. Can you please fix that?
60+
61+
Nope. I don't want to deal with old versions of GitLab. Too much work.
62+
5963
## Changelog
6064

6165
See [here](https://github.com/EpocDotFr/gitlab-merge-requests-lists-enhancer/releases).

js/content.js

+38-11
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
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());
@@ -185,6 +186,27 @@
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
*/
@@ -298,7 +320,7 @@
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(
@@ -320,7 +342,7 @@
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;
@@ -347,7 +369,7 @@
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(
@@ -370,20 +392,20 @@
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

@@ -522,8 +544,6 @@
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 = '';
@@ -547,8 +567,6 @@
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

@@ -575,7 +593,16 @@
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));

screenshot.png

2.93 KB
Loading

scripts/settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MANIFEST_FILE = {
22
'manifest_version': 2,
33
'name': 'GitLab Merge Requests lists enhancer',
4-
'version': '1.5.0',
4+
'version': '1.5.1',
55
'description': 'An extension that enhance all Merge Requests lists on any instance of Gitlab and GitLab.com.',
66
'homepage_url': 'https://github.com/EpocDotFr/gitlab-merge-requests-lists-enhancer',
77
'author': 'Maxime \'Epoc\' G.',

0 commit comments

Comments
 (0)