Last active
August 29, 2015 14:24
-
-
Save gunnarmorling/896aafe5ef18823f823b to your computer and use it in GitHub Desktop.
GreaseMonkey script for rendering source and target branches of GitHub PRs as links
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
// Copyright © 2015 Gunnar Morling | |
// This work is free. You can redistribute it and/or modify it under the | |
// terms of the Do What The Fuck You Want To Public License, Version 2, | |
// as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. | |
// ==UserScript== | |
// @name GitHub PR branch links | |
// @description Renders the source and target branches of GitHub pull requests as links | |
// @namespace http://gunnarmorling.de | |
// @include https://github.com/* | |
// @version 1 | |
// @grant none | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js | |
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js | |
// ==/UserScript== | |
waitForKeyElements("h1.gh-header-title", linkify()); | |
function linkify() { | |
var project = document.querySelectorAll('a[data-pjax="#js-repo-pjax-container"]')[0].textContent; | |
var branches = document.querySelectorAll(".commit-ref"); | |
var i; | |
for (i = 0; i < branches.length; i++) { | |
var spans = branches[i].querySelectorAll('span'); | |
var user = spans[0].textContent; | |
var branch = spans[1].textContent; | |
var link = "https://github.com/" + user + "/" + project + "/tree/" + branch; | |
var text = user + ":" + branch; | |
branches[i].innerHTML = '<a href="' + link + '" style="color: #336479">' + text + "</a>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment