Nitro Type - Auto Close Reward Popup

Closes the Reward Popup automatically on race pages.

// ==UserScript==
// @name         Nitro Type - Auto Close Reward Popup
// @version      0.1.0
// @description  Closes the Reward Popup automatically on race pages.
// @author       Toonidy
// @match        *://*.nitrotype.com/race
// @match        *://*.nitrotype.com/race/*
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAIAAACR5s1WAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9bpVIqilYQcchQnSyIijhqFYpQIdQKrTqYXPoFTRqSFBdHwbXg4Mdi1cHFWVcHV0EQ/ABxc3NSdJES/5cUWsR4cNyPd/ced+8Af73MVLNjHFA1y0gl4kImuyoEXxFCL/ogYEBipj4nikl4jq97+Ph6F+NZ3uf+HN1KzmSATyCeZbphEW8QT29aOud94ggrSgrxOfGYQRckfuS67PIb54LDfp4ZMdKpeeIIsVBoY7mNWdFQiaeIo4qqUb4/47LCeYuzWq6y5j35C8M5bWWZ6zSHkcAiliBSRzKqKKEMCzFaNVJMpGg/7uEfcvwiuWRylcDIsYAKVEiOH/wPfndr5icn3KRwHOh8se2PESC4CzRqtv19bNuNEyDwDFxpLX+lDsx8kl5radEjoGcbuLhuafIecLkDDD7pkiE5UoCmP58H3s/om7JA/y0QWnN7a+7j9AFIU1fJG+DgEBgtUPa6x7u72nv790yzvx9fO3KfqkKlgwAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+ULCBEQCo/KC2cAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAABmJLR0QAcgACAAKX272SAAAHfklEQVRYw82YCVATVxjHX2mr1tLSghTUaqFY7CFqK9RjqLWdsdfYqaP2omU6bUdbZ7D1KkjAOkWtNIBQETk8KAiCEGQUuSyHIQQJLLnI5lpCyLUhJNyIgJX04eIzkihEpHbnP5D98vJ9v/3e977dfcAcH//QBah/Ox0cHopuQzwsAsQxCpHx/IL706k5ninuLyBNCuKi12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5P2GtPT4+YpFUQfbUE+2ErqtSoJUS6vzjx8P8/KZqu+huCl+1qhHDyI6Bkloi9ocfpnbPaox2OTrS/PyKMzMJHE8oaITPVacPHZryjTMkIcaXSZtlKiOhac+pFCtbe7jsmri7lOFUQRAKLaFqU7S04gK8NCvrSFDQf7SF+L/YTH3o+hfertB4W63rtAAAAABJRU5ErkJggg==
// @require      https://greasyfork.org/scripts/443718-nitro-type-userscript-utils/code/Nitro%20Type%20Userscript%20Utils.js?version=1042360
// @grant        none
// @license      MIT
// @namespace    https://greasyfork.org/users/858426
// ==/UserScript==

/* global createLogger findReact */

const logging = createLogger("Nitro Type Auto Close Reward Popup")

const root = document.getElementById("root")
if (!root) {
    logging.error()("Unable to find the root container")
    return
}

/** Triggers a popup close event. */
const hidePopup = (node) => {
    const reactObj = findReact(node)
    if (!reactObj) {
        logging.error()("Unable to find the react component")
        return
    }
    reactObj.props.close()
}

/** Mutation Observer to track whether popup shows after the race (or loading?). */
const popupMutationObserver = new MutationObserver((mutations, observer) => {
    for (const m of mutations) {
        for (const newNode of m.addedNodes) {
            if (newNode.classList?.contains("takeoverTemp")) {
                observer.disconnect()
                hidePopup(newNode)
                logging.info()("Popup Found", newNode)
                return
            }
        }
    }
})

// Hide the first popup and any additional ones after the race
const popup = root.querySelector(".takeoverTemp")
if (popup) {
    hidePopup(popup)
    logging.info()("Popup Found on Init", popup)
}

popupMutationObserver.observe(root, { childList: true })
logging.info()("Reward Popup Tracker initialized")