website/assets/js/page.js

28 lines
853 B
JavaScript
Raw Normal View History

2021-08-05 13:51:44 +02:00
document.addEventListener("readystatechange", event => {
if(event.target.readyState === 'complete') {
initOverflow();
initExternalLinks();
initBackground();
}
});
function initOverflow() {
let body = document.querySelector('body');
if (body.scrollHeight > window.outerHeight) {
body.style.height = 'auto';
}
}
function initExternalLinks() {
document.querySelectorAll('a').forEach(elem => {
if(isExternalURL(elem.getAttribute('href'))) {
elem.setAttribute('target', '_blank');
}
})
}
function initBackground() {
let text = document.querySelector('.background .background-content').innerHTML;
document.querySelector('.background .background-content').innerHTML = text + text + text;
}
const isExternalURL = (url) => new URL(url).origin !== location.origin;