WFMario / Scientist Overview tweaks

// ==UserScript==
// @name         Scientist Overview tweaks
// @version      2024-06-06
// @author       Mario
// @license MIT
// @match        https://beta4.atmoburn.com/overview.php?view=13
// @grant        unsafeWindow
// ==/UserScript==

eval(unsafeWindow.byId.toString());
unsafeWindow.eval(hiredScientists.toString());
unsafeWindow.eval(availableScientists.toString());

hiredScientists()
availableScientists()

// builds the max stats overview for currently hired scientists
function hiredScientists() {
    let stats = [0,0,0,0,0,0,0,0,0,0,0];

    Array.from(document.getElementsByClassName("flexwrap dark margin2 marginauto flexTableWide")[0].parentElement.children).forEach(scientist => {
        let nStat = 0;
        Array.from(scientist.children[1].children).forEach(stat => {
            stats[nStat] = Math.max(parseInt(stat.innerHTML), stats[nStat]);
            nStat += 1;
        })
    })

    let maxStats = document.createElement('div');
    maxStats.className = "flexwrap dark margin2 marginauto flexTableWide";
    document.getElementsByClassName("flexwrap dark margin2 marginauto flexTableWide")[0].parentElement.prepend(maxStats);

    let maxStatsSection1 = document.createElement('div');
    maxStatsSection1.className = "flex";
    maxStatsSection1.style = "flex: 1 0 25em; align-items: center;";
    maxStatsSection1.innerHTML = '<div class="padding5 alignleft bold">Max scientist stats: </div>';
    maxStats.append(maxStatsSection1);

    let maxStatsSection2 = document.createElement('div');
    maxStatsSection2.className = "flex";
    maxStatsSection2.style = "flex: 1 0 25em; padding: 0.5em 0; align-items: center;";
    maxStats.append(maxStatsSection2);

    stats.forEach(stat => {
        let statElement = document.createElement('div');
        statElement.style = "flex: 1 0 1.5em;";
        statElement.innerHTML = stat.toString();
        maxStatsSection2.append(statElement);
    })
}

// builds the max stats overview for scientists available for hire
// builds the max stats overview for currently hired scientists
function availableScientists() {
    let stats = [0,0,0,0,0,0,0,0,0,0,0];

    Array.from(document.getElementsByClassName("midtitle bold")[2].nextElementSibling.nextElementSibling.getElementsByClassName("dark margin2 marginauto flexTableWide")).forEach(scientist => {
        let nStat = 0;
        Array.from(scientist.children[1].children).forEach(stat => {
            stats[nStat] = Math.max(parseInt(stat.innerHTML), stats[nStat]);
            nStat += 1;
        })
    })

    let maxStats = document.createElement('div');
    maxStats.className = "dark margin2 marginauto flexTableWide";
    let siblingForm = document.getElementsByClassName("midtitle bold")[2].nextElementSibling.nextElementSibling;
    let formParent = siblingForm.parentNode;
    formParent.insertBefore(maxStats, siblingForm);
    // document.getElementsByClassName("midtitle bold")[2].nextElementSibling.nextElementSibling.append(maxStats);

    let maxStatsSection1 = document.createElement('div');
    maxStatsSection1.className = "flex";
    maxStatsSection1.style = "flex: 1 0 25em; align-items: center;";
    maxStatsSection1.innerHTML = '<div class="padding5 alignleft bold">Max scientist stats: </div>';
    maxStats.append(maxStatsSection1);

    let maxStatsSection2 = document.createElement('div');
    maxStatsSection2.className = "flex";
    maxStatsSection2.style = "flex: 1 0 24em; padding: 0.5em 0; align-items: center;";
    maxStats.append(maxStatsSection2);

    stats.forEach(stat => {
        let statElement = document.createElement('div');
        statElement.style = "flex: 1 0 1.5em;";
        statElement.innerHTML = stat.toString();
        maxStatsSection2.append(statElement);
    })
}