Created
September 21, 2012 06:47
-
-
Save jroper/3760066 to your computer and use it in GitHub Desktop.
Play Lighthouse Linker Greasemonkey Script
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 Play 2 Lighthouse Linker | |
// @description Links Play 2 Lighthouse ticket references to lighthouse | |
// @namespace http://playframework.org | |
// @version 1.0 | |
// @author James Roper <[email protected]> | |
// @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