Halloweek Equipment Alert

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Halloweek Equipment Alert
// @namespace    http://tampermonkey.net/
// @version      1.0.2
// @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&comment=HEAlert&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 is missing\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()
})();