-
Notifications
You must be signed in to change notification settings - Fork 4
/
lanyard.js
63 lines (49 loc) · 2.08 KB
/
lanyard.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
57
58
59
60
61
62
63
const LANYARD_ENABLED = true;//false;
const lanyard_url = "https://api.lanyard.rest/v1/users/645264167623983124";
const online_status_element = document.getElementById("online-status");
const spotify_song_element = document.getElementById("lanyard-track-name");
const activity_element = document.getElementById("lanyard-activity-name");
async function get_lanyard_status() {
let request_result = await fetch(lanyard_url);
let request_json = (await request_result.json())["data"];
return await request_json
}
function construct_online_status(json) {
// Online/Offline indicator
if (json["discord_status"] == "online") {
online_status_element.className = "online"
} else if (json["discord_status"] == "idle") {
online_status_element.className = "idle"
} else if (json["discord_status"] == "dnd") {
online_status_element.className = "dnd"
}
else {
online_status_element.className = "offline"
}
if (json["activities"].length != 0) {
online_status_element.className = "activity"
for (let activity of json["activities"]) {
if (activity["type"] == 4) {
//activity_element.innerText = activity["state"];
} else {
//online_status_element.innerText = activity["name"].toLowerCase()
//if (activity["state"]) { online_status_element.innerText = activity["state"].toLowerCase() };
//online_status_element.innerText = activity["details"].toLowerCase()
activity_element.innerText = activity["name"];
}
}
}
if (json["spotify"] != null) {
online_status_element.className = "spotify"
const spotify = json["spotify"];
spotify_song_element.innerHTML = "<strong>" + spotify["song"] + "</strong> by <strong>" + spotify["artist"] + "</strong>"
}
console.log(json);
}
function update_lanyard_loop() {
get_lanyard_status().then(json => {
construct_online_status(json);
setTimeout(update_lanyard_loop, 10000);
});
}
if (LANYARD_ENABLED) update_lanyard_loop();