FRHD Animator

Make FRHD animations easily

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/437014/998354/FRHD%20Animator.js

// ==UserScript==
// @name         FRHD Animator
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Make FRHD animations easily
// @author       1s3k3b
// @include      /^https?://(www.)?freeriderhd.com/create/
// @grant        none
// ==/UserScript==

(function main() {
    const lastHref = window.location.href;
    const reloadInv = setInterval(() => {
        if (lastHref !== window.location.href) {
            clearInterval(reloadInv);
            main();
        }
    }, 1000);
    if (!/^https?:\/\/(www\.)?freeriderhd\.com\/create/.test(window.location.href)) return;

    const topInv = setInterval(() => {
        const top = document.querySelector('.topMenu');
        if (!top) return;
        clearInterval(topInv);
        setInterval(() => {
            if (top.querySelector('#animate')) return;
            top.innerHTML += '<div class="topMenu-button topMenu-button_offline" title="New Frame" id="animate"><span class="editorgui_icons editorgui_icons-icon_offline_editor"></span><span class="text">Add Frame</span></div>';
            let x = 0;
            top.querySelector('#animate').onclick = () => {
                GameManager.game.currentScene.track.addPowerups([['W', ...[x, 30, x += 1000, 30].map(x => x.toString(32))].join(' ')]);
                for (const line of [...GameManager.game.currentScene.track.physicsLines]) {
                    if (!line.remove && line.p1.x < x && line.p1.x > (x - 1500)) GameManager.game.currentScene.track.addPhysicsLine(line.p1.x + 1000, line.p1.y, line.p2.x + 1000, line.p2.y);
                }
            };
        });
    });
})();