Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
DilemmaGX authored Dec 9, 2023
1 parent 3839564 commit 7a109fc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ function generateBadge() {
var rightText = document.getElementById('input-text-right').value || '';
var textColor = document.getElementById('input-color').value || 'default';
var url = document.getElementById('input-url').value || '';
var logo = document.getElementById('input-logo').value || '';
var logoColor = document.getElementById('input-logo-color').value || '';

// 如果rightText为空,则不执行任何操作
if (rightText === '') {
Expand All @@ -16,6 +18,14 @@ function generateBadge() {
var badgeUrl = 'https://img.shields.io/badge/' + encodeURIComponent(leftText) + '-' + encodeURIComponent(rightText) + '-' + textColor.replace(/[^a-zA-Z0-9]/g, '');
}

if (logo != '') {
if (logoColor === '') {
badgeUrl = badgeUrl + '?logo=' + logo;
} else {
badgeUrl = badgeUrl + '?logo=' + logo + '&logoColor=' + logoColor;
}
}

var html = '<a href="' + url + '"><img src="' + badgeUrl + '" alt="' + leftText + ' - ' + rightText + '"></a>';
var md = '![' + leftText + '](' + badgeUrl + ')';

Expand All @@ -32,4 +42,4 @@ function generateBadge() {
document.getElementById('result-html').innerHTML = html;
document.getElementById('result-md').innerHTML = "[" + md + "](" + url + ")";
}
}
}

0 comments on commit 7a109fc

Please sign in to comment.