auto restart level (gpop.io)

auto restarts your gpop.io levels

// ==UserScript==
// @name         auto restart level (gpop.io)
// @namespace    http://tampermonkey.net/
// @version      v1.0.0
// @description  auto restarts your gpop.io levels
// @license MIT
// @author       Pandy
// @match        gpop.io/play/*
// @icon         https://cdn-1.webcatalog.io/catalog/gpop-io/gpop-io-icon-filled-256.png?v=1675594051106
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    (function enableAutoRestart() {
        let game_object_found = false;

        const watcherLoop = setInterval(() => {
            const gameObj = window._$W;
            if (gameObj && !game_object_found) {
                game_object_found = true;
                console.log("Game object found, (re)starting autoplayer.");
                startAutoplayer();
            } else if (!gameObj && game_object_found) {
                game_object_found = false;
                stopAutoplayer();
                console.log("Game object lost — waiting to restart...");
            }
        }, 500);
    })();

})();