koc chat

chat test

Version vom 17.05.2025. Aktuellste Version

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.ip-ddns.com/scripts/534139/1590693/koc%20chat.js


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();
  }
};