public-html/res/js/dynamic-content.js

27 lines
959 B
JavaScript

const christmas = isItChristmas();
if (christmas) {
console.log("Merry christmas!")
var head = document.getElementsByTagName('head')[0];
var snowJS = document.createElement("script");
snowJS.type = "text/javascript";
snowJS.src = "./res/js/snowstorm.js";
head.appendChild(snowJS);
const profileImage = document.querySelector("img.profile-image");
profileImage.src = "./res/images/profile-christmas.png";
const quote = document.querySelector("#quote");
const title = document.querySelector("#title");
title.innerHTML = "I changed the image with JS"
quote.innerHTML = "<em>(because of course I did it with JS)</em>"
}
function isItChristmas() {
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const startDate = new Date(`${currentYear}-11-10`);
const endDate = new Date(`${currentYear + 1}-03-01`);
return currentDate > startDate && currentDate < endDate;
}