aboutsummaryrefslogtreecommitdiff
path: root/src/js/background.js
blob: f8a7684684ded69edf2be011f4462d1c2cc5b8bd (plain)
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
function set_background_image(){
    let date = new Date();
    let current_hour = date.getHours() 
    if(current_hour <= 8 || current_hour >= 20){
        var photo = "night.jpg"
    } else if(current_hour <= 10 || current_hour > 17){
        var photo = "change.jpg"
    } else {
        var photo = "day.jpg"
    }
    let btn = document.getElementById("loadBtn")
    if(btn){
        btn.remove()
    }
    if(!document.getElementById("backgroundId")){
        document.body.style.backgroundImage = `url('/res/${photo}')`; 
        let desc = document.createElement("p")
        desc.id = "backgroundId"
        desc.innerHTML = "Background images in the public domain, painted by <a href=\"https://artvee.com/artist/ivan-konstantinovich-aivazovsky/\">Ivan Konstantinovich Aivazovsky.</a>"
        footer.appendChild(desc)
    }
}
let el = document.createElement("a")
el.id = "loadBtn"
el.innerText = "load background"
el.onclick = set_background_image
let footer = document.getElementsByTagName("footer")[0]
footer.appendChild(el)