FightButtonLibrary

Library for fight button usage start

2024-03-15 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/489910/1343592/FightButtonLibrary.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         FightButtonLibrary
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Library for fight button usage start
// @author       h2o
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';

    // Function to prompt user for API key
    function promptForApiKey() {
        var apiKey = prompt("Please enter your API key:");
        if (apiKey !== null && apiKey !== "") {
            GM_setValue("apiKey", apiKey); // Save API key locally
            return apiKey;
        } else {
            alert("API key cannot be empty!");
            return null;
        }
    }

    // Function to start the process
    function startProcess() {
        // Check if API key is already saved
        var savedApiKey = GM_getValue("apiKey");

        if (!savedApiKey) {
            savedApiKey = promptForApiKey();
        }

        if (savedApiKey) {
            // Extract user ID from URL
            var url = window.location.href;
            var userIdMatch = url.match(/user2ID=(\d+)/);
            var userId = userIdMatch ? userIdMatch[1] : null;

            if (userId) {
                // Define the URL
                var apiUrl = "https://api-torn-members.glitch.me/update/";

                // Define the query parameters
                var query = {
                    "item": "startFight",
                    "key": savedApiKey,
                    "opponent": userId,
                };

                // Construct the full URL with query parameters
                var fullUrl = apiUrl + "?item=" + query.item + "&key=" + query.key + "&faction=&opponent=" + query.opponent;

                // Send the request
                GM_xmlhttpRequest({
                    method: "GET",
                    url: fullUrl,
                    onload: function(response) {
                        handleResponse(response.responseText); // Handle the response
                    },
                    onerror: function(error) {
                        console.error("Request failed:", error);
                    }
                });
            } else {
                console.error("User ID not found in URL.");
            }
        }
    }

    // Function to handle the response
    function handleResponse(responseText) {
        alert("API Response: " + responseText);
        // Additional functions can be added here to process the response
        // For example, you can call a function like startFight() here
        // startFight();
    }

    // Expose the startProcess function to be called externally
    window.updateItemLibrary = {
        startProcess: startProcess
    };

})();