(function (){ var comfiture = {}; var activeLink; var activeContent; var motds = [ "Made by Fristi", "Made by a crocodile", "Made by a Dutch potato", "Fristi? Fristi habe ich nicht.", "[Subject quote here]", "Press R or Z twice to do a barrel roll", "You wouldn't download a car.", "The last metroid is in captivity.", "Suavemente, bésame", "What is love?", "Justice in Spades", "Let's get Volatile", "Yeah, RIP", "What a shame." ]; //Function to set the wallpaper comfiture.setupWallpaper = function () { let wallpaper = 'a' + (Math.floor(Math.random() * 12) + 1) + '.gif'; document.querySelector('.background').style.backgroundImage = 'url("backgrounds/'+wallpaper+'")'; }; comfiture.printMotd = function () { let motd = motds[Math.floor(Math.random() * motds.length)]; document.write(motd); } //Onload window.addEventListener('load', function(){ //Hide all content let contents = document.querySelectorAll('.content'); contents.forEach(function (element) { element.classList.add('hide'); }); //Activate content matching hash in url (or home instead) let hash = window.location.hash; if(!hash) hash = '#home'; switchActiveContent(hash); //Add click event handlers for header/footer links window.addEventListener("click", event => { var elements = document.querySelectorAll('header a, footer a'); elements.forEach(element => { if (element && element.contains(event.target)) { let hash = element.getAttribute('href'); switchActiveContent(hash); } }); }); }); function switchActiveContent(id) { let link = document.querySelector('a[href="'+id+'"]'); let content = document.querySelector(id); if(link && content) { if(activeLink) activeLink.classList.remove('active'); if(activeContent) activeContent.classList.add('hide'); link.classList.add('active'); content.classList.remove('hide'); activeLink = link; activeContent = content; } else { console.error('Error: not switching content; link or content element for id ' + id + ' does not exist.'); } } //Expose comfiture object to document window.comfiture = comfiture; })();