Skip to content

Instantly share code, notes, and snippets.

@nerdinand
Created September 21, 2016 16:14
Show Gist options
  • Save nerdinand/2b6c982c26a65b903aefcc2a002fcb4e to your computer and use it in GitHub Desktop.
Save nerdinand/2b6c982c26a65b903aefcc2a002fcb4e to your computer and use it in GitHub Desktop.
javascript:
function isJiraPage() {
return window.location.href.indexOf("jira") > -1;
};
function isJiraSprintPage() {
return window.location.href.indexOf("selectedIssue") > -1;
};
function isBasecampPage() {
return window.location.href.indexOf("basecamp.com") > -1;
};
function isTrelloPage() {
return window.location.href.indexOf("trello.com") > -1;
};
function jiraTag() {
return isJiraSprintPage() ? document.querySelector('[data-field-id="issuekey"]').textContent : document.getElementById('key-val').textContent;
};
function jiraTitle() {
return isJiraSprintPage() ? document.querySelector('[data-field-id="summary"]').textContent : document.getElementById('summary-val').textContent;
};
function basecampTitle() {
return document.getElementsByClassName('todo show')[0].getElementsByClassName('content_for_perma')[0].textContent;
};
function basecampTag() {
hrefParts = window.location.href.split('/');
return hrefParts[hrefParts.length - 1];
};
function trelloTitle() {
return document.getElementsByClassName('mod-card-back-title')[0].value;
};
function trelloTag() {
var idRegex = /c\/(.*)\/.*/;
var location = window.location.pathname;
var match = idRegex.exec(location);
return match[1];
};
function showPrompt(tag, title) {
prompt("Copy to clipboard: Ctrl+C, Enter", "#" + tag + " " + title);
};
if (isJiraPage()) {
showPrompt(jiraTag(), jiraTitle());
} else if (isBasecampPage()) {
showPrompt(basecampTag(), basecampTitle());
} else if (isTrelloPage()) {
showPrompt(trelloTag(), trelloTitle());
} else {
alert("This bookmarklet only supports Jira, Basecamp and Trello so far.");
}
void(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment