Halloweek Equipment Alert

Show an alert if you're about to fly without one or more of special Halloween weapons/armor.

当前为 2024-10-30 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Halloweek Equipment Alert
// @namespace    http://tampermonkey.net/
// @version      2024-10-30
// @description  Show an alert if you're about to fly without one or more of special Halloween weapons/armor.
// @author       Vrocks [2577848]
// @match        https://www.torn.com/travelagency.php
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @license MIT
// @grant        none
// ==/UserScript==

// START - CONFIGURATION
const API_KEY = "REPLACE_THIS_WITH_YOUR_API_KEY";

const CHECK_MELEE = true;
const CHECK_ARMOR = true;
const CHECK_TEMPORARY = true;
// END - CONFIGURATION

const ID_CRYSTALINE_FALCATA = 1173;
const ID_STARSHIELD_BREASTPLATE = 1174;
const ID_STYGIAN_DARKNESS = 1175;

const getPlayerEquipment = async () => {
    const url = "https://api.torn.com/user/?selections=equipment&key=" + API_KEY;
    const response = await fetch(url);

    try {
        if (!response.ok) {
            return null;
        }

        const responseJson = await response.json();

        if (!"equipment" in responseJson) {
            return null;
        }

        return responseJson.equipment
    } catch (error) {
        console.error(error);
        return null;
    }
};

const checkPlayerEquipment = async () => {
    const equipmentArray = await getPlayerEquipment();

    if (!equipmentArray) {
        alert(`Halloweek Equipment Alert\n\nSomething went wrong while checking your equipment.\n- The API key you provided may not have access to your inventory\n-Torn API is acting up\nPlease make sure to check your equipment manually.`)
        return
    }

    window.equipmentArray =equipmentArray
    const hasMelee = equipmentArray.some(
        (item) => item.ID === ID_CRYSTALINE_FALCATA
    );
    const hasArmor = equipmentArray.some(
        (item) => item.ID === ID_STARSHIELD_BREASTPLATE
    );
    const hasTemporary = equipmentArray.some(
        (item) => item.ID === ID_STYGIAN_DARKNESS
    );

    if (CHECK_MELEE && !hasMelee) {
        alert("Halloweek Equipment Alert\n\nYou have not equipped the melee weapon - Crystalline Falcata.");
    }

    if (CHECK_ARMOR && !hasArmor) {
        alert("Halloweek Equipment Alert\n\nYou have not equipped the armor - Starshield Breastplate.");
    }

    if (CHECK_TEMPORARY && !hasTemporary) {
        alert("Halloweek Equipment Alert\n\nYou have not equipped the temporary weapon - Stygian Darkness.");
    }
};
(function() {
    'use strict';
    checkPlayerEquipment()
})();