diff options
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/background.js | 29 | ||||
-rw-r--r-- | src/js/like.js | 11 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/js/background.js b/src/js/background.js new file mode 100644 index 0000000..f8a7684 --- /dev/null +++ b/src/js/background.js @@ -0,0 +1,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) + diff --git a/src/js/like.js b/src/js/like.js new file mode 100644 index 0000000..cd1e015 --- /dev/null +++ b/src/js/like.js @@ -0,0 +1,11 @@ +function likePost(type, id){ + fetch(`/post/like/${type}/${id}`) + .then(response => response.json()) + .then(response => { + console.log(response) + let btn_id=`btn_${type}_${id}` + let el = document.getElementById(btn_id) + el.innerText = `👍 (${response.likes})` + }) +} + |