HALO (Debts Clean Names Only)

Simple faction drug debt tracker (Name, Debt, Reset only - no links)

当前为 2025-09-14 提交的版本,查看 最新版本

// ==UserScript==
// @name         HALO (Debts Clean Names Only)
// @namespace    http://tampermonkey.net/
// @version      2.3.1
// @description  Simple faction drug debt tracker (Name, Debt, Reset only - no links)
// @author       Nova
// @match        https://www.torn.com/*
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function() {
  'use strict';

  const factionId = "41990"; // your faction ID

  // Drug prices
  const DRUG_PRICES = {
      "xanax": 760000,
      "vicodin": 800,
      "ketamine": 2000,
      "shrooms": 2000,
      "cannabis": 4500,
      "speed": 6000,
      "pcp": 7500,
      "opium": 23000,
      "lsd": 32000,
      "ecstasy": 40000
  };

  let factionKey = GM_getValue("factionAPIKey", null);
  let debts = GM_getValue("factionDebts", {});
  let processedLogs = GM_getValue("processedLogs", {});

  GM_addStyle(`
    #armoryPanel {
      position: fixed;
      bottom: 0;
      right: 0;
      width: 22%;
      height: 40%;
      background: white;
      color: #000;
      font-family: monospace;
      font-size: 13px;
      border: 1px solid #444;
      border-radius: 8px 8px 0 0;
      overflow-y: auto;
      padding: 8px;
      z-index: 9999;
      display: none;
    }
    .resetBtn {
      cursor: pointer;
      background: #eee;
      border: 1px solid #aaa;
      border-radius: 4px;
      font-size: 12px;
      margin-left: 6px;
      padding: 1px 4px;
    }
    .resetBtn:hover { background: #ccc; }
    #bubbleBtn {
      position: fixed;
      bottom: 20px;
      right: 20px;
      background:#222;
      color:#fff;
      border-radius:50%;
      width:36px;
      height:36px;
      font-size:18px;
      cursor:pointer;
      display:flex;
      justify-content:center;
      align-items:center;
      z-index:10000;
    }
  `);

  const panel = document.createElement("div");
  panel.id = "armoryPanel";
  panel.innerHTML = `<div id="debtLog">Debts loading...</div>`;
  document.body.appendChild(panel);

  const bubble = document.createElement("div");
  bubble.id = "bubbleBtn";
  bubble.textContent = "💊";
  document.body.appendChild(bubble);

  let minimized = true;
  function togglePanel() {
      minimized = !minimized;
      panel.style.display = minimized ? "none" : "block";
  }
  bubble.addEventListener("click", togglePanel);

  function askKey() {
      let key = prompt("Enter your Faction (Armory) API Key:", factionKey || "");
      if (key) {
          GM_setValue("factionAPIKey", key);
          factionKey = key;
          loadLogs();
      }
  }
  if (!factionKey) askKey();

  async function loadLogs() {
      if (!factionKey) {
          document.getElementById("debtLog").innerHTML = "No API key set.";
          return;
      }
      try {
          let url = `https://api.torn.com/faction/${factionId}?selections=armorynews&key=${factionKey}`;
          let res = await fetch(url);
          let data = await res.json();
          if (data.error) {
              document.getElementById("debtLog").innerHTML = "Error: " + data.error.error;
              return;
          }

          const logs = data.armorynews;
          if (!logs) {
              document.getElementById("debtLog").innerHTML = "No drug activity.";
              return;
          }

          Object.entries(logs).forEach(([logId, entry]) => {
              const text = entry.news.toLowerCase();
              let matchedDrug = Object.keys(DRUG_PRICES).find(d => text.includes(d));
              if (matchedDrug) {
                  const userMatch = entry.news.match(/^(.+?) used/i);
                  const user = userMatch ? userMatch[1].replace(/<[^>]+>/g, "").trim() : "Unknown"; // strip HTML tags

                  if (!processedLogs[logId]) {
                      const charge = DRUG_PRICES[matchedDrug] || 0;
                      if (charge > 0) {
                          debts[user] = (debts[user] || 0) + charge;
                      }
                      processedLogs[logId] = true;
                  }
              }
          });

          GM_setValue("factionDebts", debts);
          GM_setValue("processedLogs", processedLogs);

          // Display debts only
          let debtDiv = document.getElementById("debtLog");
          debtDiv.innerHTML = "<b>Debts:</b><br>";

          if (Object.keys(debts).length === 0) {
              debtDiv.innerHTML += "No debts.";
          } else {
              Object.entries(debts).forEach(([u, d]) => {
                  let row = document.createElement("div");
                  row.textContent = `${u}: ${d.toLocaleString()}`;

                  let btn = document.createElement("button");
                  btn.className = "resetBtn";
                  btn.textContent = "✅";
                  btn.addEventListener("click", (e) => {
                      e.preventDefault();
                      e.stopPropagation();
                      debts[u] = 0;
                      GM_setValue("factionDebts", debts);
                      loadLogs();
                  });

                  row.appendChild(btn);
                  debtDiv.appendChild(row);
              });
          }

      } catch (e) {
          document.getElementById("debtLog").innerHTML = "Request failed.";
      }
  }

  setInterval(() => {
      if (!minimized && factionKey) loadLogs();
  }, 45000);

  if (factionKey) loadLogs();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址