Last active
February 7, 2022 05:24
-
-
Save jlorper/6221b84ba76fec4ccfa4167a9ab38d97 to your computer and use it in GitHub Desktop.
Converts selected tasks in Asana to a list of Markdown links and copies them onto the clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name asana-tasks-to-markdown.user.js | |
// @namespace http://tampermonkey.net/ | |
// @version 0.3.6 | |
// @downloadUrl https://gist.githubusercontent.com/jlorper/6221b84ba76fec4ccfa4167a9ab38d97/raw/asana-tasks-to-markdown.user.js | |
// @updateUrl https://gist.githubusercontent.com/jlorper/6221b84ba76fec4ccfa4167a9ab38d97/raw/asana-tasks-to-markdown.user.js | |
// @description Converts selected tasks into a list of markdown links, puts the result in the clipboard | |
// @author Jose Lorenzo @jlorper | |
// @require https://code.jquery.com/jquery-3.4.0.min.js | |
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js | |
// @match https://app.asana.com/* | |
// @grant none | |
// ==/UserScript== | |
// VERSION | |
// 0.1.0 - Extract paths from textarea id | |
// 0.1.1 - Add suffix user.js to gist name | |
// 0.1.4 - Added updateUrl and downloadUrl | |
// 0.3.x - Adapt to new spreadsheet like view | |
// 0.3.6 - Update class name to match selector | |
//-- Click the More Projects link | |
waitForKeyElements( | |
".SidebarTeamDetailsProjectsList-showMoreProjectsLink", | |
activateClick | |
); | |
// https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f | |
const copyToClipboard = (str) => { | |
const el = document.createElement('textarea'); | |
el.value = str; | |
document.body.appendChild(el); | |
el.select(); | |
document.execCommand('copy'); | |
document.body.removeChild(el); | |
}; | |
function activateClick(jNode) { | |
var actionLink = window.jQuery('<a/>', { | |
id: 'tasksToMarkdown', | |
href: '#', | |
class: 'NavigationLink SidebarItemRow--leftAlign SidebarItemRow', | |
text: 'Selected Tasks to Markdown', | |
click: function (e) { | |
e.preventDefault(); | |
var markdown = ''; | |
var regex = new RegExp(/Pot.(\d+)_\w+_(\d+)/); | |
window.jQuery('.SpreadsheetGridTaskNameCell-taskName--selected').each((i, task) => { | |
// tasks project & id are enconded in id in textarea inside | |
var textarea = task.getElementsByTagName('textarea')[0]; | |
var textareaId = textarea.id; | |
var uri = textareaId.replace(regex, 'https://app.asana.com/0/$1/$2'); | |
var title = textarea.textContent; | |
markdown += "- [" + title + "](" + uri + ")\n"; | |
}); | |
copyToClipboard(markdown) | |
// fallback to console | |
console.info(markdown); | |
} | |
}); | |
window.jQuery('.SidebarTopNavLinks').append(actionLink); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install tampermonkey Chrome extension and then click on the raw contents to install it. Everything should be done automatically.