Created
October 31, 2014 18:10
-
-
Save cskevint/32dbabb80962713319d8 to your computer and use it in GitHub Desktop.
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 Add Branch Links | |
// @namespace http://www.github.com/ | |
// @version 0.1 | |
// @description Add extra links to branches page | |
// @match https://github.com/*/branches* | |
// @copyright 2014, Kevin Trotter | |
// ==/UserScript== | |
$(function () { | |
$("a.branch-name").each(function (i, o) { | |
var $this = $(o), | |
org = $('.author span').text(), | |
repo = $('.js-current-repository').text(), | |
defaultBranch = $(".branch-group-name:first").parent().parent().find(".branch-name").text(), | |
branch = $this.text(), | |
$commitsUrl = $("<span> <a href='/" + org + "/" + repo + "/commits/" + branch + "'>commits</a></span>"), | |
$compareUrl = $("<span> · <a href='/" + org + "/" + repo + "/compare/%branch%..." + branch + "'>compare to...</a></span>"), | |
$beforeText = $this.parent().find(".branch-meta"); | |
if (defaultBranch != branch) { | |
$compareUrl.insertAfter($beforeText); | |
} | |
$commitsUrl.insertAfter($beforeText); | |
$compareUrl.find("a").click(function () { | |
var branch = prompt("Which branch would you like to compare to?"); | |
if (!branch) { | |
branch = defaultBranch; | |
} | |
var href = $(this).attr("href"); | |
$(this).attr("href", href.replace("%branch%", branch)); | |
}) | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment