Torn API Test (PapaNads)

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

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

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