TruceMonitor

dove mon test

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/536371/1591169/TruceMonitor.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// truceMonitor.js (New Tab for Truce/AP Monitoring)

Tabs.TruceMonitor = {
    tabOrder: 2180, // Adjust order as needed
    tabLabel: "Truce Monitor",
    tabColor: "grey", // Or another suitable color
    myDiv: null,
    targets: [], // Array to store monitored players/cities

    init(div) {
        this.myDiv = div;
        this.paint();
    },

    paint() {
        // ... (UI for adding and removing targets to monitor) ...
        // This could be a text input for player names/UIDs or a more
        // sophisticated system using a searchable list.

        const m = `
            <div class="divHeader" align="center">Truce/AP Monitor</div>
            <br>
            <div align="center">
                <label for="targetInput">Player Name/UID:</label>
                <input type="text" id="targetInput" class="btInput">
                <button id="addTargetButton" class="buttonv2 std blue">Add Target</button>
                <br><br>
                <div id="targetList"></div> <br>
                <div id="truceMonitorStatus"></div>
            </div>
        `;

        this.myDiv.innerHTML = m;

        // Event listeners
        $("#addTargetButton").click(() => this.addTarget());
    },

    addTarget() {
        const targetInput = $("#targetInput").val().trim();
        if (targetInput === "") {
            return;
        }

        // ... (Your logic to resolve player name/UID to a Player object) ...
        // This might involve using your existing player search functionality
        // or making an API request to get player information.

        // Example (assuming you have a Player class):
        getPlayerInfo(targetInput)  // Your function to get player info
            .then(player => {
                if (player) {
                    this.targets.push(player);
                    this.saveTargets(); // Save targets to storage
                    this.displayTargetList();
                    this.updateStatus(tx("Target added."));
                } else {
                    this.updateStatus(tx("Player not found."));
                }
            });


        $("#targetInput").val(""); // Clear input field
    },

    displayTargetList() {
        // ... (Display the list of monitored targets in the #targetList div) ...
    },

    checkTrucesAndAP() {
        this.targets.forEach(target => {
            // ... (Your logic to check truce and AP expiration for the target) ...
            // This might involve fetching player data using the API or
            // monitoring the game UI for changes.

            // Example (assuming you have functions to check truce and AP):
            const truceEnds = getTruceEndTime(target);
            const apEnds = getAPEndTime(target);

            if (truceEnds) {
                this.displayTruceInfo(target, truceEnds);
            }

            if (apEnds) {
                this.displayAPInfo(target, apEnds);
            }
        });
    },

    displayTruceInfo(target, endTime) {
        // ... (Display truce information for the target, including end time) ...
        const timeLeft = endTime - unixTime();
        if (timeLeft <= 0) { // Truce has ended
            this.notifyTruceEnded(target);
        } else {
            // ... (Display time remaining) ...
        }
    },

    displayAPInfo(target, endTime) {
        // ... (Display AP information for the target, including end time) ...
        const timeLeft = endTime - unixTime();
        if (timeLeft <= 0) { // AP has ended
            this.notifyAPEnded(target);
        } else {
            // ... (Display time remaining) ...
        }
    },

    notifyTruceEnded(target) {
        // ... (Notify the user that the target's truce has ended) ...
        // This could be a chat message, sound alert, or other notification.
        this.updateStatus(`Target ${target.name}'s truce has ended!`);
    },

    notifyAPEnded(target) {
        // ... (Notify the user that the target's AP has ended) ...
        this.updateStatus(`Target ${target.name}'s AP has ended!`);
    },


    updateStatus(message) {
        $("#truceMonitorStatus").html(message);
    },

    // ... (Implement saveTargets and loadTargets using GM_setValue or IndexedDB) ...

    show() {
        this.loadTargets(); // Load saved targets
        this.displayTargetList();
    },

    hide() {
        // ...
    },

    EverySecond: function() {
        this.checkTrucesAndAP();
    }
};