Instagram Mobile Home Feed Suggested Video Prevention

Simple script to prevent scrolling beyond "You've completely caught up" element

// ==UserScript==
// @name         Instagram Mobile Home Feed Suggested Video Prevention
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Simple script to prevent scrolling beyond "You've completely caught up" element
// @author       gtarr
// @match        https://www.instagram.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=instagram.com
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    // Function to find "You've completely caught up" element
    function findSuggested() {
        // Find a child of the "You've completely caught up" element
        const suggestedChild = document.querySelector('.xh8yej3.x1ye3gou.x1gan7if.xn6708d.x1miatn0.xdt5ytf.x78zum5.x9f619.xjbqb8w.x6s0dn4');

        // Loops until the "You've completely caught up" element is found
        if (suggestedChild) {
            // Select the "You've completely caught up" element
            const suggested = suggestedChild.parentElement;
            stopAtElement(suggested);

        } else {
            setTimeout(findSuggested, 100);
        }
    }

    // Function to prevent scrolling past element
    function stopAtElement(suggested) {

        function handleScroll() {
            // Prevents scrolling beyond "You've completely caught up" element
            const elementRect = suggested.getBoundingClientRect();
            if (elementRect.bottom+40 < window.innerHeight) {
                console.log("test3");
                const bodyRect = document.body.getBoundingClientRect()
                window.scrollTo(0, elementRect.bottom+40 - bodyRect.bottom);
            }
        }

        window.addEventListener('scroll', handleScroll);
    }

    findSuggested();
})();