Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A TamperMonkey script that turns bugzilla bug references in Trello into clickable links. Handles formats like "BZ123", "BZ-123", "BZ 123" or "BZ#123"
// ==UserScript==
// @name Trello Bugzilla Linker
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Links Trello issues to Bugzilla
// @author Charles Blaxland
// @match https://trello.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
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 = /BZ[\s#-]*([0-9]+)/g;
document.querySelectorAll(cardTitleSel).forEach(function(el) {
el.innerHTML = el.innerHTML.replace(markdownUrlPattern, function(match, bz) {
return '<u href="https://bugzilla.example.com/bugzilla/show_bug.cgi?id=' + bz + '">BZ-' + bz + '</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');
console.log("hehe " + (e.ctrlKey));
if (e.target.nodeName === 'U' && href && href.indexOf('/') !== 0 && e.ctrlKey) {
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
You can’t perform that action at this time.