Skip to content

Instantly share code, notes, and snippets.

@mikhuang
Last active September 15, 2017 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikhuang/35b5ab17df3ec19e098f45f5fda643f5 to your computer and use it in GitHub Desktop.
Save mikhuang/35b5ab17df3ec19e098f45f5fda643f5 to your computer and use it in GitHub Desktop.
Asana task title formatted for Github bookmarklet

This bookmarklet is probably overkill and doesn't work with subtasks. Instead, just copy and paste the Asana task's link into your commit message and the relevant task will show up in Asana.

To quickly copy and paste your browser's current link: command-L then command-C. Works on any page ;-)


old stuff:

  1. Install Github Services Asana integration

  2. Easily copy task titles for Github. Drag this link into your bookmarks to copy task title #123456 (the task id) to your clipboard while in Asana.

Can't see the link? Go to http://bl.ocks.org/mikhuang/35b5ab17df3ec19e098f45f5fda643f5

javascript:(function()%7Bfunction%20isValid(a)%7Breturn%20Number.isInteger(Number(a))%7Dvar%20target%3Ddocument.querySelector(%22.SingleTaskTitleRow-taskName%20textarea%22)%3Btarget%7C%7C(target%3Ddocument.getElementById(%22details_property_sheet_title%22))%3Bfor(var%20title%3Dtarget%3Ftarget.value%3Awindow.document.title%2Cparts%3Dlocation.href.trim(%22%2F%22).split(%22%2F%22)%2Cid%3Dnull%2Ci%3Dparts.length-1%3Bi%3E0%3Bi--)if(isValid(parts%5Bi%5D))%7Bid%3Dparts%5Bi%5D%3Bbreak%7Dif(id)%7Bvar%20text%3Dtitle%2B%22%20%23%22%2Bid%2Ctextarea%3Ddocument.createElement(%22textarea%22)%3Btextarea.textContent%3Dtext%2Ctextarea.style.position%3D%22fixed%22%2Cdocument.body.appendChild(textarea)%2Ctextarea.select()%3Btry%7Bdocument.execCommand(%22copy%22)%7Dcatch(a)%7Bwindow.prompt(%22Copy%20to%20clipboard%3A%20Ctrl%2BC%2C%20Enter%22%2Ctext)%7Dfinally%7Bdocument.body.removeChild(textarea)%7D%7D%7D)()
// copies to clipboard "task title #taskid"
// as used by Github services Asana integration
// https://github.com/github/github-services/blob/master/docs/asana
// To build:
// 1) process with https://jscompress.com
// 2) process with http://mrcoles.com/bookmarklet/
var target = document.querySelector('.SingleTaskTitleRow-taskName textarea')
if (!target) {
target = document.getElementById('details_property_sheet_title')
}
function isValid(x) {
return Number.isInteger(Number(x))
}
var title = target ? target.value : window.document.title;
var parts = location.href.trim('/').split('/')
var id = null
for (var i = parts.length - 1; i > 0; i--) {
if (isValid(parts[i])) {
id = parts[i]
break
}
}
if (id) {
var text = title + ' #' + id
// http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
var textarea = document.createElement("textarea");
textarea.textContent = text;
textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in MS Edge.
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand("copy"); // Security exception may be thrown by some browsers.
} catch (ex) {
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
} finally {
document.body.removeChild(textarea);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment