let lowestKnownOffset = -1;
window.addEventListener("resize", () => lowestKnownOffset = -1);

const $Title = document.querySelector('.shgr-game-links')
let requestedFrame;

data = document.querySelector('#game-link-sticky-origin');
const clone = data.cloneNode(true);

sticky = document.querySelector('.game-link-sticky').appendChild(clone);

window.addEventListener("scroll", (event) => {
    if (requestedFrame) { return; }
    requestedFrame = requestAnimationFrame(() => {
        if (lowestKnownOffset === -1) { lowestKnownOffset = $Title.offsetTop; }
        lowestKnownOffset = Math.min(lowestKnownOffset, $Title.offsetTop);
        sticky = document.querySelector('.game-link-sticky');

        if (window.scrollY >= (lowestKnownOffset + 100)) {
            sticky.classList.add("link-sticky");
            sticky.classList.remove("hide");
        } else {
            sticky.classList.add("hide");
            sticky.classList.remove("link-sticky");
        }
        requestedFrame = undefined;
    });
})
