Skip to content

Instantly share code, notes, and snippets.

@jroper
Created September 21, 2012 06:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jroper/3760066 to your computer and use it in GitHub Desktop.
Save jroper/3760066 to your computer and use it in GitHub Desktop.
Play Lighthouse Linker Greasemonkey Script
// ==UserScript==
// @name Play 2 Lighthouse Linker
// @description Links Play 2 Lighthouse ticket references to lighthouse
// @namespace http://playframework.org
// @version 1.0
// @author James Roper <james@jazzy.id.au>
// @include https://github.com/playframework/Play20/*
// @require http://code.jquery.com/jquery-1.8.2.min.js
// @run-at document-end
// ==/UserScript==
var playLighthouseLinker = (function() {
var replaceIssues = function(element) {
if (element.nodeType == 3) {
var html = element.data;
} else {
var html = $(element).html();
}
var results = html.match(/\[#([0-9]+)\]/);
if (results) {
var replace = html.replace(results[0], '<a href="https://play.lighthouseapp.com/projects/82401/tickets/' + results[1] + '">' + results[0] + '</a>');
if (element.nodeType == 3) {
$(element).replaceWith(replace)
} else {
$(element).html(replace)
}
}
}
$(".message code, .commit-title, .commit-desc, .discussion-topic-title").each(function() {
// If the commit message is linked, break it up.
$(this).contents().each(function() {
if (this.nodeType == 1 && this.tagName == "A") {
var href = $(this).attr("href");
var html = $(this).html();
var results = html.match(/\[#([0-9]+)\]/);
if (results) {
var replace = '<a href="' + href + '">' +
html.replace(results[0], '</a><a href="https://play.lighthouseapp.com/projects/82401/tickets/' + results[1] + '">'
+ results[0] + '</a><a href="' + href + '">')
+ "</a>";
$(this).replaceWith(replace);
}
} else {
replaceIssues(this);
}
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment