Created
October 27, 2016 07:24
-
-
Save ampedandwired/8b62d7a5b7ca5e896615d782d7e279d0 to your computer and use it in GitHub Desktop.
A TamperMonkey script that turns bugzilla bug references in Trello into clickable links. Handles formats
This file contains hidden or 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 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