forked from marionm/jira-pr-tag-parser-chrome-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
27 lines (21 loc) · 753 Bytes
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(() => {
const $title = document.querySelector('.js-issue-title');
if (!$title) {
return;
}
chrome.storage.local.get(['jiraUrl', 'inlineLinks'], (options) => {
const jiraUrl = !!options.jiraUrl ?
options.jiraUrl :
'https://jira.nextcapital.com';
let title = $title.innerHTML.replace(/(<a[^>]+>|⬆︎|<\/a>)/g, '');
title.match(/[a-zA-Z0-9-]+(?=[\],\s\d#]*\])/g).forEach((tag) => {
const url = `${jiraUrl}/browse/${tag}`;
const attrs = `href="${url}" target="_blank"`;
const replacement = options.inlineLinks === false ?
`${tag}<a ${attrs}>⬆︎</a>` :
`<a ${attrs}>${tag}</a>`;
title = title.replace(tag, replacement);
});
$title.innerHTML = title;
});
})();