Save The Chain!

Monitor chain timer and provide quick access to targets in Torn City. Alerts trigger only for chains of 10 hits or more.

当前为 2024-08-22 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Save The Chain!
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Monitor chain timer and provide quick access to targets in Torn City. Alerts trigger only for chains of 10 hits or more.
// @author       MummaPhucka
// @match        https://www.torn.com/*/*
// @icon         none
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Torn API Key
    const API_KEY = 'YOUR_API_KEY_HERE';

    // Target IDs
    const TARGET_IDS = ['200728', '67254', '112024', '583658'];

    // Torn API Endpoints
    const CHAIN_ENDPOINT = `https://api.torn.com/faction/?selections=chain&key=${API_KEY}`;

    // Notification threshold in seconds (e.g., 300 seconds = 5 minutes)
    const ALERT_THRESHOLD = 180;

    // Minimum chain hits required to trigger alerts
    const MIN_CHAIN_HITS = 1;

    // Send Notification
    function sendNotification(message) {
        const notification = new Notification("Torn Chain Alert", {
            body: message,
            icon: "https://www.torn.com/favicon.ico" // Optional: Torn City favicon or any other icon URL
        });

        notification.onclick = function() {
            window.focus();
        };
    }

    // Request notification permission if not already granted
    if (Notification.permission !== "granted") {
        Notification.requestPermission();
    }

    // Get Chain Data
    async function getChainData() {
        try {
            const response = await fetch(CHAIN_ENDPOINT);
            const data = await response.json();
            const chainHits = data.chain.current || 0;
            const chainTimer = data.chain.timeout || 0;
            return { chainHits, chainTimer };
        } catch (error) {
            console.error('Error fetching chain data:', error);
            return { chainHits: 0, chainTimer: 0 };
        }
    }

    // Generate Attack Links for Multiple Targets
    function generateAttackLinks() {
        return TARGET_IDS.map(id => `Attack Target: https://www.torn.com/loader.php?sid=attack&user2=${id}`).join('\n');
    }

    // Monitor Chain Timer
    async function monitorChain() {
        while (true) {
            const { chainHits, chainTimer } = await getChainData();

            if (chainHits >= MIN_CHAIN_HITS && chainTimer <= ALERT_THRESHOLD) {
                const attackLinks = generateAttackLinks();
                const message = `Chain of ${chainHits} hits is at ${chainTimer} seconds!\n\n${attackLinks}`;
                sendNotification(message);
            }

            await new Promise(resolve => setTimeout(resolve, 60000)); // Wait for 1 minute before checking again
        }
    }

    // Start monitoring when the script runs
    monitorChain();

})();