diff --git a/index.js b/index.js index 1765c7d..b4bc0b3 100644 --- a/index.js +++ b/index.js @@ -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 === '') { @@ -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 = '' + leftText + ' - ' + rightText + ''; var md = '![' + leftText + '](' + badgeUrl + ')'; @@ -32,4 +42,4 @@ function generateBadge() { document.getElementById('result-html').innerHTML = html; document.getElementById('result-md').innerHTML = "[" + md + "](" + url + ")"; } -} \ No newline at end of file +}