SN's GLB Trains Remaining

Track career BT goals with a red warning before it's too late.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         SN's GLB Trains Remaining
// @namespace    SeattleNiner
// @description  Track career BT goals with a red warning before it's too late.
// @version      3.4
// @match        https://glb.warriorgeneral.com/game/training.pl?*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const PLATEAU_AGE = 160;
    const TP_PER_DAY = 4;
    const TP_PER_TRAIN = 2;

    function init() {
        const playerId = new URLSearchParams(window.location.search).get('player_id');
        if (!playerId) return;

        const storageKey = `glb_bt_goal_${playerId}`;
        const currentBT = parseInt(document.querySelector('a[href*="bonus_tokens.pl"]')?.innerText || 0);
        const bankedTP = parseInt(document.querySelector('#training_points_box .points')?.innerText || 0);
        const currentAge = parseInt(document.body.innerText.match(/Age:\s*(\d+)/i)?.[1] || 0);

        if (currentAge > PLATEAU_AGE) return;

        // --- MATH: Future Earnings ---
        const daysLeft = PLATEAU_AGE - currentAge;
        let futureTP = daysLeft * TP_PER_DAY;

        // Add the final 36 TP award only if the player hasn't reached Age 160 yet.
        // Once they are Age 160, they are in the final season and have already received it.
        if (currentAge < 160) {
            futureTP += 36;
        }

        const trainsLeft = Math.floor((bankedTP + futureTP) / TP_PER_TRAIN);
        const minBT = currentBT + (trainsLeft * 2);
        const maxBT = currentBT + (trainsLeft * 6);
        let goal = localStorage.getItem(storageKey) || 0;

        // --- UI STYLE ---
        let bg = "#007bff"; // Default Blue
        let warn = "";
        if (goal > 0) {
            if (maxBT < goal) { bg = "#000"; warn = " (FAIL)"; }
            else if (maxBT < (parseFloat(goal) + (goal * 0.1))) { bg = "#dc3545"; warn = " (DANGER)"; }
            else if (minBT >= goal) { bg = "#28a745"; warn = " (SAFE)"; }
            else { bg = "#ffc107"; } // Yellow
        }

        const container = document.getElementById('training_settings');
        if (!container) return;

        const bar = document.createElement('div');
        bar.style = `background:${bg}; color:${bg==="#ffc107"?"#000":"#fff"}; padding:3px 10px; margin-bottom:5px; border-radius:3px; font-weight:bold; font-size:11px; display:flex; justify-content:space-between; align-items:center; border:1px solid rgba(0,0,0,0.1);`;

        bar.innerHTML = `
            <span>${trainsLeft} trains left <span style="font-weight:normal; opacity:0.8;">(${minBT}-${maxBT} BT)${warn}</span></span>
            <span>Goal: <input type="number" id="bt_g" value="${goal}" style="width:45px; border:none; border-radius:2px; padding:0 3px; height:16px; font-size:10px;"> <button id="bt_s" style="height:16px; font-size:9px; cursor:pointer;">Set</button></span>
        `;

        container.prepend(bar);

        document.getElementById('bt_s').onclick = (e) => {
            e.preventDefault();
            localStorage.setItem(storageKey, document.getElementById('bt_g').value);
            window.location.reload();
        };
    }

    window.addEventListener('load', init);
    if (document.readyState === 'complete') init();
})();