-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (59 loc) · 2.36 KB
/
index.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
64
65
66
const getQueryVariable = (variable) => {
const query = window.location.search.substring(1);
const pairs = query.split("&");
for (const pair of pairs) {
const [key, value] = pair.split("=")
if (key === variable) {
return value;
}
}
return "";
}
const getBadgeColor = (compliance) => {
const colors = ["red","red","orange","orange","yellow", "green"];
const count = compliance.filter((elem) => {return elem === "1"}).length;
return colors[count];
};
const getBadgeSymbols = (elem) => {
const symbol_compliant = "%E2%97%8F";
const symbol_noncompliant = "%E2%97%8B";
if (elem === "1") {
return symbol_compliant;
}
return symbol_noncompliant;
};
const setBadge = (compliance) => {
const state = compliance.map(getBadgeSymbols).join("%20%20");
const color = getBadgeColor(compliance);
const src = "https:\/\/img.shields.io\/badge\/fair--software.eu-" + state + "-" + color;
document.getElementById("badge").getElementsByTagName("img")[0].src = src;
}
const setVisibility = (compliance) => {
const recommendations = ["repository", "license", "registry", "citation", "checklist"];
for (const [i, recommendation] of recommendations.entries()) {
if (compliance[i] === "1") {
document.getElementById(recommendation)
.getElementsByClassName("compliant")[0].classList.remove("hidden")
document.getElementById(recommendation)
.getElementsByClassName("noncompliant")[0].classList.add("hidden")
} else {
document.getElementById(recommendation)
.getElementsByClassName("compliant")[0].classList.add("hidden")
document.getElementById(recommendation)
.getElementsByClassName("noncompliant")[0].classList.remove("hidden")
}
}
}
const addCompliments = () => {
const compliments = ["Good job! ", "Well done! ", "Great work! ", "Nice! "];
document.querySelectorAll("span.compliment").forEach((span) => {
const i = Math.floor(Math.random() * compliments.length);
span.innerText = compliments[i];
});
}
document.addEventListener('DOMContentLoaded', (event) => {
const compliance = (getQueryVariable("compliance") + "00000").split("").slice(0, 5);
setBadge(compliance)
setVisibility(compliance)
addCompliments()
})