-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (51 loc) · 1.88 KB
/
script.js
File metadata and controls
70 lines (51 loc) · 1.88 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
var handle = document.getElementById("username");
//gets the 'info' object and sets the input value
chrome.storage.sync.get("CFhandle", function (data) {
if (!chrome.runtime.error) {
console.log(data.CFhandle);
handle.value = data.CFhandle;
}
});
document.getElementById("user_button").addEventListener('click', function () {
getDetails();
});
// function to get details of a user
function getDetails() {
var request = new XMLHttpRequest();
var url = "http://codeforces.com/api/user.info?handles=";
var username = handle.value;
info = {
"CFhandle": username,
};
//saves the 'info' object
chrome.storage.sync.set(info, function () {
if (!chrome.runtime.error) {
console.log("Username Updated");
console.log(info);
}
})
request.open('GET', url + username, true)
request.onload = function () {
// Begin accessing JSON data here
var json = JSON.parse(this.response)
if (json.status == "OK") {
var object = json.result[0];
var photo = `https:${object.titlePhoto}`;
document.getElementById("photo").setAttribute("src", photo);
var fullName = `${object.firstName} ${object.lastName}`;
document.getElementById("name").innerHTML = fullName;
var rating = object.rating;
document.getElementById("rating").innerHTML = rating;
var rank = object.rank;
document.getElementById("rank").innerHTML = rank;
var college = object.organization;
document.getElementById("college").innerHTML = college;
var city = object.city;
document.getElementById("city").innerHTML = city;
document.getElementById("profile").style.display = "block";
} else {
console.log('error')
}
}
request.send()
}