forked from jerone/UserScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGithub_Pull_Request_From.user.js
More file actions
58 lines (50 loc) · 2.33 KB
/
Copy pathGithub_Pull_Request_From.user.js
File metadata and controls
58 lines (50 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ==UserScript==
// @name Github Pull Request From Link
// @namespace https://github.com/jerone/UserScripts/
// @description Make pull request branches linkable
// @author jerone
// @copyright 2014+, jerone (http://jeroenvanwarmerdam.nl)
// @license CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
// @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @homepage https://github.com/jerone/UserScripts/tree/master/Github_Pull_Request_From
// @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Pull_Request_From
// @downloadURL https://github.com/jerone/UserScripts/raw/master/Github_Pull_Request_From/Github_Pull_Request_From.user.js
// @updateURL https://github.com/jerone/UserScripts/raw/master/Github_Pull_Request_From/Github_Pull_Request_From.user.js
// @supportURL https://github.com/jerone/UserScripts/issues
// @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW
// @icon https://github.githubassets.com/pinned-octocat.svg
// @version 20.0
// @grant none
// @include https://github.com/*/pull/*
// @exclude https://github.com/*/*.diff
// @exclude https://github.com/*/*.patch
// ==/UserScript==
(function () {
String.format = function (string) {
var args = Array.prototype.slice.call(arguments, 1, arguments.length);
return string.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] !== 'undefined' ? args[number] : match;
});
};
function init() {
Array.prototype.filter.call(document.querySelectorAll('.commit-ref[title], .base-ref[title], .head-ref[title]'), function (treeSpan) {
return !treeSpan.querySelector('.unknown-repo');
}).forEach(function (treeSpan) {
const [repo, branch] = treeSpan.title.split(':');
var treeParts = treeSpan.querySelectorAll('.css-truncate-target');
var treeLink = document.createElement('a');
// Show underline on hover.
Array.prototype.forEach.call(treeParts, function (part) {
part.style.display = 'inline';
});
treeLink.setAttribute('href', String.format('/{0}/tree/{1}', repo, branch));
treeLink.innerHTML = treeSpan.innerHTML;
treeSpan.innerHTML = '';
treeSpan.appendChild(treeLink);
});
}
// Page load.
init();
// On pjax.
document.addEventListener('pjax:end', init);
})();