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

27 lines
959 B
JavaScript
Raw Normal View History

2024-11-17 13:15:57 +00:00
const christmas = isItChristmas();
if (christmas) {
2024-12-06 00:25:50 +00:00
console.log("Merry christmas!")
2024-11-17 13:15:57 +00:00
var head = document.getElementsByTagName('head')[0];
var snowJS = document.createElement("script");
snowJS.type = "text/javascript";
2024-11-17 13:18:43 +00:00
snowJS.src = "./res/js/snowstorm.js";
2024-11-17 13:15:57 +00:00
head.appendChild(snowJS);
const profileImage = document.querySelector("img.profile-image");
2024-11-17 13:18:43 +00:00
profileImage.src = "./res/images/profile-christmas.jpg";
2024-12-06 00:25:50 +00:00
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>"
2024-11-17 13:15:57 +00:00
}
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;
}