MissionShopDB

Collecting anonymous data about mission rewards

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         MissionShopDB
// @namespace    de.sabbasofa.missionrewarddb
// @version      1.0.3
// @description  Collecting anonymous data about mission rewards
// @author       Hemicopter [2780600], Lazerpent [2112641]
// @match        https://www.torn.com/loader.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);
            }
        });
    }
})();