Torn API Test (PapaNads)

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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";
      }
    });
  });
})();