window.onscroll = function() {
let d = document.documentElement;
let offset = d.scrollTop + window.innerHeight;
let height = d.offsetHeight;
console.log('offset = ' + offset);
console.log('height = ' + height);
if (offset >= height) {
console.log('At the bottom');
}
};