Mousehunt manually send gits and raffles

No need to move the mouse! Click on the button 20 times to send gifts or tickets to everyone. Only works in friends page

// ==UserScript==
// @name         Mousehunt manually send gits and raffles
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  No need to move the mouse! Click on the button 20 times to send gifts or tickets to everyone. Only works in friends page
// @author       lobsterindustry
// @match        https://www.mousehuntgame.com/*
// @require      https://cdn.jsdelivr.net/npm/[email protected]/mousehunt-utils.js
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mousehuntgame.com
// @grant        none
// ==/UserScript==

(function() {
    var i=0;
    var j=0;

    //create buttons
    var prevButton = document.createElement("BUTTON");
    var giftButton = document.createElement("BUTTON");
    var raffleButton = document.createElement("BUTTON");
    var nextButton = document.createElement("BUTTON");

    prevButton.innerHTML = "Previous";
    giftButton.innerHTML = "Gift(0)";
    raffleButton.innerHTML = "Raffle(0)";
    nextButton.innerHTML = "Next";

    function sendGift(){
        if (i < 20) {
            var buttonsView = document.getElementsByClassName("userInteractionButtonsView full_buttons")[i];
            var lastChildIndex = buttonsView.children.length - 2;
            buttonsView.children[lastChildIndex].children[0].children[0].onclick();
            i++;
            giftButton.innerHTML = "Gift(" + i + ")";
            if (i == 20){giftButton.disabled = true;}
        }
    }

    //send raffle
    function sendRaffle(){
        if (j < 20) {
            var buttonsView = document.getElementsByClassName("userInteractionButtonsView full_buttons")[j];
            var lastChildIndex = buttonsView.children.length - 1;
            buttonsView.children[lastChildIndex].children[0].children[0].onclick();
            j++;
            raffleButton.innerHTML = "Raffle(" + j + ")";
            if (j == 20){raffleButton.disabled = true;}
        };
    }

    //show buttons
    function showButtons() {
        var prevCheck = document.getElementsByClassName("friendsPage-friendListContainer view_friends")[0].children[2].children[0].classList.length;
        var nextCheck = document.getElementsByClassName("friendsPage-friendListContainer view_friends")[0].children[2].children[2].classList.length;

        if (prevCheck == 2){prevButton.disabled = true;}
        if (nextCheck == 2){nextButton.disabled = true;}

        var div = document.getElementsByClassName("friendsPage-list-header")[0];
        div.appendChild(prevButton);
        div.appendChild(giftButton);
        div.appendChild(raffleButton);
        div.appendChild(nextButton);
    };


    //reset buttons
    function resetButtons(){
        i=0;
        j=0;
        giftButton.disabled = false;
        raffleButton.disabled = false;
        giftButton.innerHTML = "Gift(0)";
        raffleButton.innerHTML = "Raffle(0)";
    };

    //when clicked
    prevButton.onclick = () => {
        app.pages.FriendsPage.tab_view_friends.pager.showPreviousPage(event);
        var prevCheck = document.getElementsByClassName("friendsPage-friendListContainer view_friends")[0].children[2].children[0].classList.length;
        var nextCheck = document.getElementsByClassName("friendsPage-friendListContainer view_friends")[0].children[2].children[2].classList.length;
        nextButton.disabled = false;
        if (prevCheck == 2){prevButton.disabled = true;}
        resetButtons()
    };

    giftButton.onclick = () => {sendGift()};
    raffleButton.onclick = () => {sendRaffle()};

    nextButton.onclick = () => {
        app.pages.FriendsPage.tab_view_friends.pager.showNextPage(event);
        var prevCheck = document.getElementsByClassName("friendsPage-friendListContainer view_friends")[0].children[2].children[0].classList.length;
        var nextCheck = document.getElementsByClassName("friendsPage-friendListContainer view_friends")[0].children[2].children[2].classList.length;
        prevButton.disabled = false;
        if (nextCheck == 2){nextButton.disabled = true;}
        resetButtons()
    };


    //when page change
    onPageChange({
        friends: {
            show: () => {
                showButtons()
            }
        },
    });

    onAjaxRequest(() => {
        var prevCheck = document.getElementsByClassName("friendsPage-friendListContainer view_friends")[0].children[2].children[0].classList.length;
        var nextCheck = document.getElementsByClassName("friendsPage-friendListContainer view_friends")[0].children[2].children[2].classList.length;
        if (prevCheck == 2){prevButton.disabled = true;
                           } else {prevButton.disabled = false;}
        if (nextCheck == 2){nextButton.disabled = true;
                           } else {nextButton.disabled = false;}
        resetButtons();
    }, 'managers/ajax/pages/friends.php')

    if (window.location.href.indexOf("https://www.mousehuntgame.com/friends.php") > -1) {
        showButtons();
    }
})();