Torn API Test (PapaNads)

Tests GM_xmlhttpRequest access to api.torn.com and prints the raw result.For troubleshooting your api.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Torn API Test (PapaNads)
// @namespace    https://tampermonkey.net/
// @version      0.1
// @description  Tests GM_xmlhttpRequest access to api.torn.com and prints the raw result.For troubleshooting your api.
// @author       papanad[3928917]
// @match        https://www.torn.com/*
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// @connect      api.torn.com
// @run-at       document-idle
// @license      MAT
// ==/UserScript==

(() => {
  "use strict";

  GM_addStyle(`
    #pn-api-test {
      position: fixed; right: 12px; bottom: 12px; z-index: 999999;
      background: rgba(0,0,0,.75); color: #39ff14; border: 1px solid rgba(57,255,20,.35);
      padding: 10px; border-radius: 10px; font-family: monospace; width: 360px;
      box-shadow: 0 0 18px rgba(57,255,20,.12);
    }
    #pn-api-test button {
      background: rgba(120,0,0,.85); color:#39ff14; border:1px solid rgba(255,51,51,.6);
      border-radius: 8px; padding: 6px 10px; cursor:pointer; font-weight:700;
    }
    #pn-api-test pre { white-space: pre-wrap; margin: 8px 0 0 0; max-height: 200px; overflow:auto; }
    #pn-api-key { width: 100%; box-sizing: border-box; margin-top: 8px; padding: 8px; border-radius: 8px;
      border: 1px solid rgba(57,255,20,.35); background: rgba(0,0,0,.35); color:#39ff14; }
  `);

  const box = document.createElement("div");
  box.id = "pn-api-test";
  box.innerHTML = `
    <div style="font-weight:800; margin-bottom:6px;">Torn API TEST</div>
    <button id="pn-test-btn">TEST API KEY</button>
    <input id="pn-api-key" type="password" placeholder="Paste your API key here (test only)" />
    <pre id="pn-out">Waiting...</pre>
  `;
  document.body.appendChild(box);

  const out = box.querySelector("#pn-out");
  const keyInput = box.querySelector("#pn-api-key");

  box.querySelector("#pn-test-btn").addEventListener("click", () => {
    const key = keyInput.value.trim();
    if (!key) {
      out.textContent = "Paste your API key first.";
      return;
    }

    const url = `https://api.torn.com/user/?selections=battlestats,workstats&key=${encodeURIComponent(key)}`;
    out.textContent = `Requesting...\n${url}`;

    GM_xmlhttpRequest({
      method: "GET",
      url,
      timeout: 15000,
      onload: (resp) => {
        const head = `HTTP status: ${resp.status}\nFinal URL: ${url}\n\n`;
        out.textContent = head + (resp.responseText || "(empty response)");
      },
      onerror: () => {
        out.textContent =
          "onerror fired.\n\nThis almost always means:\n- @connect is missing/blocked\n- another extension blocked api.torn.com\n- the userscript manager is not Tampermonkey / permissions not granted";
      },
      ontimeout: () => {
        out.textContent =
          "Timed out.\n\nThis can be:\n- Torn API temporarily slow\n- api.torn.com blocked by network/adblock";
      }
    });
  });
})();