Greasy Fork is available in English.

MissionShopDB

Collecting anonymous data about mission rewards

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         MissionShopDB
// @namespace    de.sabbasofa.missionrewarddb
// @version      1.0.4
// @description  Collecting anonymous data about mission rewards
// @author       Hemicopter [2780600], Lazerpent [2112641]
// @match        https://www.torn.com/loader.php?sid=missions*
// @match        https://www.torn.com/page.php?sid=missions*
// @icon         https://torn.com/loader.php?sid=missions*
// @grant        GM_xmlhttpRequest
// @connect      api.lzpt.io
// ==/UserScript==

(function() {
    'use strict';

    setTimeout(getRewardData, 1000);

    function getRewardData() {
        try {
            if(!document.getElementsByClassName("rewards-list")[0]) return;
            let bundle = [];

            for(let list of document.getElementsByClassName("rewards-list")) {
                let rewards = list.children;

                for (let reward of rewards) {
                    let data = JSON.parse(reward.attributes["data-ammo-info"].value);
                    let rewardData = {};
                    rewardData.timestamp = data.timestamp;
                    rewardData.name = data.name;
                    rewardData.amount = data.amount;
                    rewardData.points = data.points;
                    rewardData.label = data.label? data.label : "none";
                    bundle.push(rewardData);
                }

            }

            console.log("[MissionShopDB] Ready to send bundle.", JSON.stringify(bundle));
            sendBundleToAPI(bundle);

        } catch(error) {
            console.error("[MissionShopDB] Error sending bundle to API:", error);
            alert("MissionShopDB error #42. Please check console and report this to Lazerpent [2112641] or Hemicopter [2780600]: " + error);
        }
    }

    function sendBundleToAPI(bundle) {
        GM_xmlhttpRequest({
            method: "POST",
            url: "https://api.lzpt.io/missionshopdb",
            headers: {"Content-Type": "application/json"},
            data: JSON.stringify(bundle),
            onload: function (response) {
                if(!response) return; // because pda doesn't know how to network i guess
                console.log("[MissionShopDB] Bundle successfully sent to API:", response.responseText);

                const json = JSON.parse(response.responseText);
                if (json.error) {
                    alert("MissionShopDB error #58. Please check console and report this to Lazerpent [2112641] or Hemicopter [2780600]: " + response.responseText);
                }
            },
            onerror: function (error) {
                console.error("[MissionShopDB] Error sending bundle to API:", error);
                alert("MissionShopDB error #63. Please check console and report this to Lazerpent [2112641] or Hemicopter [2780600]: " + error);
            }
        });
    }
})();