Last active
March 3, 2016 13:34
-
-
Save jbgo/fc32504795330949c0ff to your computer and use it in GitHub Desktop.
Trello Card Links User Script https://opensolitude.com/2016/03/01/trello-card-links.html
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 Trello Card Links | |
// @namespace https://opensolitude.com/ | |
// @version 0.2 | |
// @description Adds support for markdown hyperlink syntax in your Trello card titles. | |
// @author Jordan Bach | |
// @match https://trello.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
if (!NodeList.prototype.forEach) NodeList.prototype.forEach = Array.prototype.forEach; | |
if (!NodeList.prototype.indexOf) NodeList.prototype.indexOf = Array.prototype.indexOf; | |
var dirty = false; | |
function renderCardLinks() { | |
var cardTitleSel = 'a.list-card-title, h2.window-title-text'; | |
var markdownUrlPattern = /\[([^\]]+)\]\(([^\)]+)\)/g; | |
document.querySelectorAll(cardTitleSel).forEach(function(el) { | |
el.innerHTML = el.innerHTML.replace(markdownUrlPattern, function(match, linkText, url) { | |
return '<u href="' + url + '">' + linkText + '</u>'; | |
}); | |
}); | |
} | |
function needsRender() { | |
dirty = true; | |
} | |
document.addEventListener('blur', function() { | |
window.setTimeout(needsRender, 0); | |
}, true); | |
document.addEventListener('click', function(e) { | |
var href = e.target.getAttribute('href'); | |
if (e.target.nodeName === 'U' && href && href.indexOf('/') !== 0 && e.metaKey) { | |
e.preventDefault(); | |
window.open(href, '_blank'); | |
e.stopPropagation(); | |
} else if (e.target.nodeName === 'A' && href.indexOf('/c/') !== -1) { | |
window.setTimeout(needsRender, 100); | |
} | |
}, true); | |
document.addEventListener('load', needsRender, true); | |
window.setInterval(function() { | |
if (dirty) { | |
renderCardLinks(); | |
dirty = false; | |
} | |
}, 100); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment