forked from jerone/UserScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGithub_Pages_Linker.user.js
More file actions
89 lines (74 loc) · 2.92 KB
/
Copy pathGithub_Pages_Linker.user.js
File metadata and controls
89 lines (74 loc) · 2.92 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// ==UserScript==
// @id Github_Pages_Linker@https://github.com/jerone/UserScripts
// @name Github Pages Linker
// @namespace https://github.com/jerone/UserScripts/
// @description Add a link to Github Pages (gh-pages) when available.
// @author jerone
// @copyright 2014+, jerone (http://jeroenvanwarmerdam.nl)
// @license GNU GPLv3
// @homepage https://github.com/jerone/UserScripts/tree/master/Github_Pages_Linker
// @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Pages_Linker
// @downloadURL https://github.com/jerone/UserScripts/raw/master/Github_Pages_Linker/Github_Pages_Linker.user.js
// @updateURL https://github.com/jerone/UserScripts/raw/master/Github_Pages_Linker/Github_Pages_Linker.user.js
// @supportURL https://github.com/jerone/UserScripts/issues
// @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW
// @version 1.2.1
// @grant none
// @run-at document-end
// @include https://github.com/*
// ==/UserScript==
/* global unsafeWindow */
(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 addLink() {
if(document.getElementById("GithubPagesLinker")) {
return;
}
var meta = document.querySelector(".repository-meta");
if (!meta) {
return;
}
var branch = document.querySelector(".js-navigation-open[data-name='gh-pages']");
if (!branch) {
return;
}
var tree = branch.getAttribute("href").split("/"); // `/{user}/{repo}/tree/gh-pages`;
var url = String.format("https://{0}.github.io/{1}/", tree[1], tree[2]);
var div = document.createElement("div");
div.id = "GithubPagesLinker";
div.style.margin = "-10px 0px 10px";
meta.parentNode.insertBefore(div, meta.nextSibling);
var img = document.createElement("img");
img.setAttribute("src", "https://assets-cdn.github.com/images/icons/emoji/octocat.png");
img.setAttribute("align", "absmiddle");
img.classList.add("emoji");
img.style.height = "16px";
img.style.width = "16px";
div.appendChild(img);
div.appendChild(document.createTextNode(" "));
var a = document.createElement("a");
a.setAttribute("href", "https://pages.github.com");
a.setAttribute("title", "More info about gh-pages...");
a.style.color = "inherit";
a.appendChild(document.createTextNode("Github Pages"));
div.appendChild(a);
div.appendChild(document.createTextNode(": "));
var aa = document.createElement("a");
aa.setAttribute("href", url);
aa.appendChild(document.createTextNode(url));
div.appendChild(aa);
}
// Page load;
console.log('GithubPagesLinker', 'page load');
addLink();
// On pjax;
unsafeWindow.$(document).on("pjax:end", function() {
console.log('GithubPagesLinker', 'pjax');
addLink();
});
})();