Skip to content

Commit

Permalink
Functionality works in full task view now as well
Browse files Browse the repository at this point in the history
  • Loading branch information
spaceo committed Sep 24, 2020
1 parent ba11bae commit 61c09d5
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,41 @@ function copyToClipboard(text) {
document.body.removeChild(dummy);
}

function statusMessage(jiraTaskId) {
return `Jira task Id: <span class="what-was-copied">"${jiraTaskId}"</span> has been copied to your clipboard`;
}

document.addEventListener('DOMContentLoaded', function() {
const status = document.getElementById('status');
status.innerHTML = 'No project or task id was found';

chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
const tabUrl = tabs[0].url;
const jiraTaskIdMatch = tabUrl.match(/selectedIssue=([A-Z][A-Z0-9]*-[0-9]+)/);
const projectAndTaskIdMatch = tabUrl.match(/browse\/([A-Z][A-Z0-9]*-[0-9]+)|selectedIssue=([A-Z][A-Z0-9]*-[0-9]+)/);

if (!jiraTaskIdMatch || jiraTaskIdMatch[1] === undefined) {
if (!projectAndTaskIdMatch) {
status.innerHTML = 'No jira task id was found';
return;
}

const jiraTaskId = jiraTaskIdMatch[1];
copyToClipboard(jiraTaskId);
if (
projectAndTaskIdMatch
&& projectAndTaskIdMatch[1] !== undefined
&& projectAndTaskIdMatch[2] === undefined
) {
copyToClipboard(projectAndTaskIdMatch[1]);
status.innerHTML = statusMessage(projectAndTaskIdMatch[1])
}

if (
projectAndTaskIdMatch
&& projectAndTaskIdMatch[1] === undefined
&& projectAndTaskIdMatch[2] !== undefined
) {
copyToClipboard(projectAndTaskIdMatch[2]);
status.innerHTML = statusMessage(projectAndTaskIdMatch[2])
}

status.innerHTML = `Jira task Id: <span class="what-was-copied">"${jiraTaskId}"</span> has been copied to your clipboard`;
return true;
});
}, false);

0 comments on commit 61c09d5

Please sign in to comment.