import Cookies from 'js-cookie'; document.addEventListener("readystatechange", event => { if(event.target.readyState === 'complete') { initOverflow(); initExternalLinks(); initNinetiesToggle(); } }); function initOverflow() { let body = document.querySelector('body'); if (body.scrollHeight > window.outerHeight) { body.style.height = 'auto'; } } function initNinetiesToggle() { document.querySelector('.nineties-toggle').addEventListener('click', function() { let body = document.querySelector('body'); if (body.classList.contains('nineties')) { body.classList.remove('nineties'); Cookies.remove('nineties'); } else { body.classList.add('nineties'); Cookies.set('nineties', true, { sameSite: 'strict' }); } }) } function initExternalLinks() { document.querySelectorAll('a').forEach(elem => { if(isExternalURL(elem.getAttribute('href'))) { elem.setAttribute('target', '_blank'); } }) } const isExternalURL = (url) => new URL(url).origin !== location.origin;