-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
48 lines (40 loc) · 1.14 KB
/
scripts.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
document.body.onload = function() {
randomizeBackground();
insertReadings();
}
function randomizeBackground() {
const NUM_BG = 38;
const BG_PATH = "assets/backgrounds/texture";
let n = parseInt(1 + Math.random() * NUM_BG).toString();
document.body.style.backgroundImage = "url(" + BG_PATH + n + ".png)";
}
function insertReadings() {
let anchor = document.getElementById("readings");
for (let category in READINGS["categories"])
{
let h3 = document.createElement("h3");
h3.textContent = category;
h3.className = "category";
anchor.appendChild(h3);
READINGS["categories"][category].forEach(reading => {
if(Object.keys(reading).length == 0)
return;
let p = document.createElement("p");
p.className = "reading";
if(reading['url'] != "") {
let a = document.createElement("a");
a.href = reading['url'];
a.textContent = reading['title'];
a.style.fontStyle = "italic";
p.appendChild(a);
} else {
p.textContent = reading['title'];
}
if(reading['author'] != "") {
let author = document.createTextNode(" by " + reading['author'])
p.appendChild(author);
}
anchor.appendChild(p);
})
}
}