// ==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 '' + linkText + ''; }); }); } 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); })();