forked from shield-9/opcache-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-btn.html
91 lines (82 loc) · 2.47 KB
/
github-btn.html
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
90
91
<!DOCTYPE html>
<html>
<head>
<title>GitHub Button</title>
<link rel='stylesheet' href='css/github-btn.css' type='text/css' />
</head>
<body>
<span class=github-btn id=github-btn>
<a class=gh-btn id=gh-btn href="#" target=_blank>
<span class=gh-ico></span>
<span class=gh-text id=gh-text></span>
</a>
<a class=gh-count id=gh-count href="#" target=_blank></a>
</span>
<script type="text/javascript">
var params = function () {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}()
var user = params.user,
repo = params.repo,
type = params.type,
count = params.count,
size = params.size,
head = document.getElementsByTagName('head')[0],
button = document.getElementById('gh-btn'),
mainButton = document.getElementById('github-btn'),
text = document.getElementById('gh-text'),
counter = document.getElementById('gh-count');
function addCommas(n) {
return String(n).replace(/(\d)(?=(\d{3})+$)/g, '$1,')
}
function jsonp(path) {
var el = document.createElement('script');
el.src = path + '?callback=callback';
head.insertBefore(el, head.firstChild);
}
function callback(obj) {
if(type == 'watch') {
counter.innerHTML = addCommas(obj.data.watchers);
} else if(type == 'fork') {
counter.innerHTML = addCommas(obj.data.forks);
} else if(type == 'follow') {
counter.innerHTML = addCommas(obj.data.followers);
}
if(count == 'true') {
counter.style.display = 'block';
}
}
button.href = 'https://github.com/' + user + '/' + repo + '/';
if(type == 'watch') {
mainButton.className += ' github-watchers';
text.innerHTML = 'Star';
counter.href = 'https://github.com/' + user + '/' + repo + '/stargazers';
} else if(type == "fork") {
mainButton.className += " github-forks";
text.innerHTML = "Fork";
button.href = "https://github.com/" + user + "/" + repo + "/fork";
counter.href = "https://github.com/" + user + "/" + repo + "/network"
} else if(type == 'follow') {
mainButton.className += ' github-me';
text.innerHTML = 'Follow @' + user;
button.href = 'https://github.com/' + user;
counter.href = 'https://github.com/' + user + '/followers';
}
if(size == 'large') {
mainButton.className += ' github-btn-large';
}
if(type == 'follow') {
jsonp('https://github.com/gitapi/users/' + user);
} else {
jsonp('https://github.com/gitapi/repos/' + user + '/' + repo);
}
</script>
</body>
</html>