koc chat

chat test

目前為 2025-05-17 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


Tabs.AutoPorterTracker = {
  tabOrder: 2200,
  tabLabel: "Porter Tracker",
  tabColor: "cyan",
  myDiv: null,
  porters: [], // Array to store tracked porters

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

  paint() {
    const m = `
      <div class="divHeader" align="center">Auto Porter Tracker</div>
      <br>
      <div align="center">
        <label for="porterInput">Porter Name/UID:</label>
        <input type="text" id="porterInput" class="btInput">
        <button id="addPorterButton" class="buttonv2 std blue">Track Porter</button>
        <div id="porterList"></div>
        <br>
        <div id="porterTrackerStatus"></div>
      </div>
    `;
    this.myDiv.innerHTML = m;

    // Add click listener
    $("#addPorterButton").click(() => this.addPorter());
  },

  async addPorter() {
    const porterInput = $("#porterInput").val().trim();
    if (porterInput === "") return;

    try {
      const player = await getPlayerInfo(porterInput); // You must define this

      if (player) {
        this.porters.push({
          player,
          lastSeenLocation: player.location, // Assuming player has this
          lastSeenAt: Date.now()
        });

        this.savePorters();
        this.displayPorterList();
        this.updateStatus(`Porter ${player.name} added to tracking list.`);
      } else {
        this.updateStatus("Player not found.");
      }
    } catch (err) {
      this.updateStatus("Error retrieving player data.");
    }

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

  displayPorterList() {
    const listDiv = $("#porterList");
    if (!this.porters.length) {
      listDiv.html("<i>No porters are currently being tracked.</i>");
      return;
    }

    let html = "<table class='portersTable'><tr><th>Name</th><th>UID</th><th>Last Location</th><th>Last Seen</th></tr>";
    this.porters.forEach(({ player, lastSeenLocation, lastSeenAt }) => {
      html += `<tr>
        <td>${player.name}</td>
        <td>${player.uid}</td>
        <td>${lastSeenLocation}</td>
        <td>${new Date(lastSeenAt).toLocaleString()}</td>
      </tr>`;
    });
    html += "</table>";
    listDiv.html(html);
  },

  async checkPorterLocations() {
    for (const porterData of this.porters) {
      const { player, lastSeenLocation } = porterData;

      const updatedPlayer = await getPlayerInfo(player.uid); // Use UID for accuracy
      if (updatedPlayer && updatedPlayer.location !== lastSeenLocation) {
        this.notifyPort(updatedPlayer, updatedPlayer.location);
        porterData.player = updatedPlayer;
        porterData.lastSeenLocation = updatedPlayer.location;
        porterData.lastSeenAt = Date.now();
        this.savePorters();
        this.displayPorterList();
      }
    }
  },

  notifyPort(player, newLocation) {
    this.updateStatus(`⚠️ Porter ${player.name} has ported to ${newLocation}!`);
    // Optional: play a sound or flash tab
  },

  updateStatus(message) {
    $("#porterTrackerStatus").html(`<b>${message}</b>`);
  },

  savePorters() {
    GM_setValue("trackedPorters", JSON.stringify(this.porters));
  },

  loadPorters() {
    const saved = GM_getValue("trackedPorters", "[]");
    this.porters = JSON.parse(saved);
  },

  show() {
    this.loadPorters();
    this.displayPorterList();
  },

  hide() {
    // Optional cleanup
  },

  EverySecond() {
    this.checkPorterLocations();
  }
};