forked from ikuwow/yourcontributions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
47 lines (38 loc) · 1.27 KB
/
main.js
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
(function(){
'use strict';
var getcode = document.getElementsByClassName('get-code')[0];
var preview = function() {
var gh_username = document.getElementsByClassName("form-gh-username")[0].value;
if (gh_username === "") {
return;
}
var preview = document.getElementById("preview-display");
var aTag = document.createElement("a");
aTag.href = "https://github.com/"+gh_username;
aTag.className = "gh-contributions";
aTag.dataset.ghUsername = gh_username;
aTag.target="_blank";
aTag.innerHTML = gh_username+"'s contributions";
var scriptTag = document.createElement("script");
scriptTag.src = location.href.split('?')[0]+"widget.min.js";
var child;
while (child = preview.lastChild) {
preview.removeChild(preview.firstChild);
}
preview.appendChild(aTag);
preview.appendChild(scriptTag);
getcode.textContent = aTag.outerHTML + scriptTag.outerHTML;
};
var ptb = document.getElementsByClassName("form-preview")[0];
var inputGitHubUsername = document.getElementsByClassName("form-gh-username")[0];
ptb.onclick = preview;
inputGitHubUsername.onkeypress = function() {
if (window.event.keyCode === 13) {
preview();
}
};
// autofocus
getcode.onclick = function(){
getcode.select();
};
})();