-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
56 lines (51 loc) · 1.37 KB
/
popup.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
48
49
50
51
52
53
54
55
56
function setUsername(username) {
chrome.storage.local.set({'gitUsername': username}, function() {
});
}
function showContributionGraph(username) {
//Show content
console.log(username);
document.getElementById("content").innerHTML="<img src='http://ghchart.rshah.org/"+
username + "' alt='" + username + "' />" +
"<button id='change_account'>Change Account</button>";
try {
document.getElementById("change_account").addEventListener("click", changeAccount);
} catch(e) {
console.log(e);
}
}
function showLogin() {
document.getElementById("content").innerHTML="<span>Username: </span><input id='username_input'/>" + "<br/>" +
"<button id='submit'>Submit</button>";
try {
document.getElementById("submit").addEventListener("click", setAndShow);
} catch(e) {
console.log(e);
}
}
function setAndShow() {
var new_username = document.getElementById('username_input').value;
setUsername(new_username);
showContributionGraph(new_username);
}
function changeAccount() {
showLogin();
}
//Main
document.addEventListener('DOMContentLoaded', function () {
var username = "";
// Read local storages for username
chrome.storage.local.get('gitUsername', function(result) {
try {
username = result.gitUsername;
} catch(e) {
username = "";
}
console.log(username);
if (username != "") {
showContributionGraph(username);
} else {
showLogin();
}
});
});