23 lines
619 B
JavaScript
23 lines
619 B
JavaScript
|
document.addEventListener("readystatechange", event => {
|
||
|
if(event.target.readyState === 'complete') {
|
||
|
initOverflow();
|
||
|
initExternalLinks();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
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');
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
const isExternalURL = (url) => new URL(url).origin !== location.origin;
|