-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlanyard.js
More file actions
executable file
·87 lines (71 loc) · 2.89 KB
/
lanyard.js
File metadata and controls
executable file
·87 lines (71 loc) · 2.89 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const LANYARD_ENABLED = true;//false;
const lanyard_url = "https://api.lanyard.rest/v1/users/645264167623983124";
const boyne_status_container = document.getElementById("boyne-status-container");
const online_status_element = document.getElementById("online-status");
const activity_element = document.getElementById("lanyard-activity-name");
async function get_lanyard_status() {
try {
let request_result = await fetch(lanyard_url);
let request_json = (await request_result.json())["data"];
return await request_json
} catch (NetworkError) {
return null;
}
}
function construct_online_status(json) {
// Reset
online_status_element.innerText = ""
activity_element.innerText = ""
if (json == null) {
json = {
discord_status: "unreachable"
}
}
// Online/Offline indicator
if (json["discord_status"] == "online") {
online_status_element.className = "online"
online_status_element.innerText = "online"
} else if (json["discord_status"] == "idle") {
online_status_element.className = "idle"
online_status_element.innerText = "idle"
} else if (json["discord_status"] == "dnd") {
online_status_element.className = "dnd"
online_status_element.innerText = "on do not disturb"
} else if (json["discord_status"] == "unreachable") {
online_status_element.className = "unreachable"
online_status_element.innerText = "unreachable"
boyne_status_container.style.display = "none";
}
else {
online_status_element.className = "offline"
online_status_element.innerText = "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()
online_status_element.innerText = "using"
activity_element.innerText = activity["name"];
}
}
}
if (json["spotify"] != null) {
online_status_element.className = "spotify"
online_status_element.innerText = "listening to"
const spotify = json["spotify"];
activity_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();