// ==UserScript==
// @name         Aquarius Wars - Stats and Timers
// @version      1.0
// @description  Displays spy stats on war the page and after pulling the mini profile of enemies (hold click) (it might take a sec to update , if not pull the mini profile again) it will start a timer countdown in front of the stats corresponding to the time for them to get out of the Hospital
// @author       XeiDaMoKa [2373510]
// @match        <https://www.torn.com/factions.php?step=your*>
// ==/UserScript==

/* global $ */

$(document).ready(function() {
    'use strict';

    function initialize() {

// Players and their Stats
var playerStats = {
    'argh': '11,534,009,580',
    'Flex': '11,429,189,290',
    'Tramadol': '10,254,480,661',
    'RAPY': '9,423,020,324',
    'Kyle600': '9,258,962,126',
    'WombatMustache': '7,883,385,105',
    'gratify': '7,530,000,000',
    '-O-MR_thunder': '7,250,990,574',
    'outspoking': '6,979,643,970',
    'Flanete': '6,664,248,600',
    'shad0wqueen': '6,589,187,015',
    'JTB': '5,574,517,985',
    'The_Gorilla': '5,539,960,514',
    'Shedu': '4,935,410,038',
    'Slovich': '4,720,875,722',
    'MrEvilDr': '3,206,068,872',
    'MrCreatifity': '2,634,172,874',
    'TomSawyer': '2,517,609,681',
    'Dryroastednuttz': '2,469,581,315',
    'Ikuhruss': '2,295,115,611',
    'Unauthorised': '1,983,619,310',
    'nitrogenous': '1,936,934,899',
    'Ochenbe': '1,480,132,666',
    'blockhead77': '1,471,355,278',
    'Juhon': '1,461,162,675',
    'El_Colonel': '1,272,630,414',
    'Chisui': '1,226,314,888',
    'Vanquisher': '1,181,895,699',
    'jd1201': '993,893,581',
    'Bozo': '965,842,394',
    'Subzero': '949,759,095',
    'DrDoom': '710,788,695',
    'Physc0': '573,899,179',
    'ZeehZeeh': '537,025,712',
    'tonydank': '404,703,204',
    'Merzman': '304,321,860',
    'Marnix0126': '281,364,885',
    'The_Sherlock': '264,824,311',
    'toshko2': '220,649,421',
    'ChillDude22': '180,191,958',
    'Baller_Bernd': '178,460,373',
    '-BlackraM-': '158,991,306',
    'Nanlex': '138,690,519',
    'Zess_T': '102,359,364',
    'Dagsy1': '81,755,395',
    'Chopper1234': '49,804,422',
    'IshotMarvin': '33,433,886',
    'Twinpipes': '32,603,216',
    'CoughingDog': '25,857,467',
    'MiguelMighty': '25,391,834',
    'DirtyDan1234': '16,038,048',
    'PhantomNoKira': '10,982,529',
    'MuDWayne': '6,444,677',
    'erpaen': '5,953,352',
    'FBomb': '5,210,134',
    'Fiar': '2,891,636',
    'Lenord': '1,601,069',
    'Phoenix_Frost': '1,152,831',
    'AtivanStan': '945,457',
    'IRON-STUD': '665,775',
    'silverfang492': '538,694',
    'ScubaSteve': '437,403',
    'Trujo': '256,724',
    'Bonghorn': '196,879',
    'Dazzl': '116,406',
    'ChalkOutlinez': '89,421',
    'SD90MacDaddy': '9,471'
};

// Function to add stats to enemys
        function addStatsToPlayers() {
            $('.members-list .enemy:not(.stats-added)').each(function() {
                var playerName = $(this).find('.honor-text').text().trim(); // Get the player's name
                var stats = playerStats[playerName]; // Get the stats for the player

                if (stats !== undefined) { // Check if stats are defined for the player

                    // Append stats to the player's list item
                    $(this).addClass('stats-added'); // Add a class to mark stats added

                    // Extracting hospital timer information
                    var description = $(this).find('.profile-container .description .main-desc').text().trim();
                    var timer = description.match(/In hospital for (\\d+) minutes and (\\d+) seconds/i);

                    // Create a div element with centered text for stats
                    var statsText = timer ? stats + ' - ' + parseInt(timer[1]) + 'm ' + parseInt(timer[2]) + 's' : stats;
				var statsElement = $('<div class="stats"></div>').css({'margin-left': '17.5%', 'margin-bottom': '2px'}).text(statsText);

                    // Append the stats element
                    $(this).append(statsElement);
                }
            });
        }

// Find the elements within the mini profile wrapper for name and description
function logMiniProfileData(miniProfileWrapper) {

    var nameElement = $(miniProfileWrapper).find('.profile-mini-_userNameWrapper___Po1gZ');
    var descriptionElement = $(miniProfileWrapper).find('.profile-container .description .main-desc');

// Check if both name and description elements exist
    if (nameElement.length && descriptionElement.length) {

// Extract the player's name and description
        var playerName = nameElement.text().trim();
        var description = descriptionElement.text().trim();

// Iterate over enemy elements in the members list
        $('.members-list .enemy').each(function() {
            var playerNameInList = $(this).find('.honor-text').text().trim();

// Check if the player's name in the list matches the player's name in the mini profile
            if (playerNameInList === playerName) {
                var statsElement = $(this).find('.stats');
                if (statsElement.length) {
                    var stats = statsElement.text().trim().split(' - ')[0]; // Extracting only the stats part

// Check if the description contains numbers
                    var numbersMatch = description.match(/\\d+\\s*(?:day|hour|minute|second)s?/ig);
                    if (numbersMatch && numbersMatch.length >= 2) {
                        var days = 0;
                        var hours = 0;
                        var minutes = 0;
                        var seconds = 0;

// Parse the numbers and units from the description
                        numbersMatch.forEach(function(match) {
                            var parts = match.split(/\\s+/);
                            var value = parseInt(parts[0]);
                            var unit = parts[1].toLowerCase();

// Assign the value to corresponding time unit
                            if (unit.includes('day')) {
                                days = value;
                            } else if (unit.includes('hour')) {
                                hours = value;
                            } else if (unit.includes('minute')) {
                                minutes = value;
                            } else if (unit.includes('second')) {
                                seconds = value;
                            }
                        });

// Convert days, hours, and minutes to total seconds
                        var totalSeconds = days * 86400 + hours * 3600 + minutes * 60 + seconds;

// Clear existing interval before starting a new one
                        clearInterval(statsElement.data('intervalId'));

                        var currentDisplayedSeconds = totalSeconds; // To track the displayed seconds

// Update the timer every second
                        var intervalId = setInterval(function() {
                            if (currentDisplayedSeconds > 0) {
                                currentDisplayedSeconds--;
                                var updatedDays = Math.floor(currentDisplayedSeconds / 86400);
                                var remainingSeconds = currentDisplayedSeconds % 86400;
                                var updatedHours = Math.floor(remainingSeconds / 3600);
                                var remainingSecondsAfterHours = remainingSeconds % 3600;
                                var updatedMinutes = Math.floor(remainingSecondsAfterHours / 60);
                                var updatedSeconds = remainingSecondsAfterHours % 60;

// Display the updated timer
                                var displayTime = '';
                                if (updatedDays > 0) {
                                    displayTime += updatedDays + 'd ';
                                }
                                if (updatedHours > 0 || updatedDays > 0) {
                                    displayTime += updatedHours + 'h ';
                                }
                                displayTime += updatedMinutes + 'm ' + updatedSeconds + 's';

// Display the updated timer
                                statsElement.text(stats + ' - ' + displayTime);
                            } else {
                                clearInterval(intervalId);

// If the timer expires, remove the timer from display
                                statsElement.text(stats);
                            }
                        }, 1000);

// Store the interval id as data attribute
                        statsElement.data('intervalId', intervalId);
                    } else {

// If it's not a timer, display the description as is
                        statsElement.text(stats + ' - ' + description);
                    }
                }
            }
        });
    }
}

// Function to check for new mini profiles and log their data
function checkForNewMiniProfiles() {

// Iterate over each mini profile wrapper element
    $('.profile-mini-root .mini-profile-wrapper').each(function() {
        var miniProfileWrapper = this; // Get the current mini profile wrapper

// Check if the current mini profile wrapper has already been processed
        if (!processedProfileWrappers.has(miniProfileWrapper)) {

// If not processed, log the data for the mini profile
            logMiniProfileData(miniProfileWrapper);

// Add the mini profile wrapper to the set of processed wrappers
            processedProfileWrappers.add(miniProfileWrapper);
        }
    });
}

// Avoid duplicates
        var processedProfileWrappers = new Set();

// Add stats to players initially
        addStatsToPlayers();

// Check every second to aply
        setInterval(addStatsToPlayers, 1000);

// Check for new mini profiles initially
        checkForNewMiniProfiles();

        // Check for new mini profiles every 1 second
        setInterval(checkForNewMiniProfiles, 1000);
    }

    initialize();
});

https://prnt.sc/_C1fi7GHh6dT

// ==UserScript== // @name Aquarius Wars - Stats and Timers // @version 1.0 // @description Displays spy stats on war the page and after pulling the mini profile of enemies (hold click) (it might take a sec to update , if not pull the mini profile again) it will start a timer countdown in front of the stats corresponding to the time for them to get out of the Hospital // @author XeiDaMoKa [2373510] // @match https://www.torn.com/factions.php?step=your* // ==/UserScript==

/* global $ */

$(document).ready(function() { 'use strict';

function initialize() {

// Players and their Stats var playerStats = { 'argh': '5.5 - 11,534,009,580', 'Flex': '11,429,189,290', 'Tramadol': '10,254,480,661', 'RAPY': '9,423,020,324', 'Kyle600': '9,258,962,126', 'WombatMustache': '7,883,385,105', 'gratify': '7,530,000,000', '-O-MR_thunder': '7,250,990,574', 'outspoking': '6,979,643,970', 'Flanete': '6,664,248,600', 'shad0wqueen': '6,589,187,015', 'JTB': '5,574,517,985', 'The_Gorilla': '5,539,960,514', 'Shedu': '4,935,410,038', 'Slovich': '4,720,875,722', 'MrEvilDr': '3,206,068,872', 'MrCreatifity': '2,634,172,874', 'TomSawyer': '2,517,609,681', 'Dryroastednuttz': '2,469,581,315', 'Ikuhruss': '2,295,115,611', 'Unauthorised': '1,983,619,310', 'nitrogenous': '1,936,934,899', 'Ochenbe': '1,480,132,666', 'blockhead77': '1,471,355,278', 'Juhon': '1,461,162,675', 'El_Colonel': '1,272,630,414', 'Chisui': '1,226,314,888', 'Vanquisher': '1,181,895,699', 'jd1201': '993,893,581', 'Bozo': '965,842,394', 'Subzero': '949,759,095', 'DrDoom': '710,788,695', 'Physc0': '573,899,179', 'ZeehZeeh': '537,025,712', 'tonydank': '404,703,204', 'Merzman': '304,321,860', 'Marnix0126': '281,364,885', 'The_Sherlock': '264,824,311', 'toshko2': '220,649,421', 'ChillDude22': '180,191,958', 'Baller_Bernd': '178,460,373', '-BlackraM-': '158,991,306', 'Nanlex': '138,690,519', 'Zess_T': '102,359,364', 'Dagsy1': '81,755,395', 'Chopper1234': '49,804,422', 'IshotMarvin': '33,433,886', 'Twinpipes': '32,603,216', 'CoughingDog': '25,857,467', 'MiguelMighty': '25,391,834', 'DirtyDan1234': '16,038,048', 'PhantomNoKira': '10,982,529', 'MuDWayne': '6,444,677', 'erpaen': '5,953,352', 'FBomb': '5,210,134', 'Fiar': '2,891,636', 'Lenord': '1,601,069', 'Phoenix_Frost': '1,152,831', 'AtivanStan': '945,457', 'IRON-STUD': '665,775', 'silverfang492': '538,694', 'ScubaSteve': '437,403', 'Trujo': '256,724', 'Bonghorn': '196,879', 'Dazzl': '116,406', 'ChalkOutlinez': '89,421', 'SD90MacDaddy': '9,471' };

// Function to add stats to enemys function addStatsToPlayers() { $('.members-list .enemy:not(.stats-added)').each(function() { var playerName = $(this).find('.honor-text').text().trim(); // Get the player's name var stats = playerStats[playerName]; // Get the stats for the player

            if (stats !== undefined) { // Check if stats are defined for the player

                // Append stats to the player's list item
                $(this).addClass('stats-added'); // Add a class to mark stats added

                // Extracting hospital timer information
                var description = $(this).find('.profile-container .description .main-desc').text().trim();
                var timer = description.match(/In hospital for (\\\\d+) minutes and (\\\\d+) seconds/i);

                // Create a div element with centered text for stats
                var statsText = timer ? stats + ' - ' + parseInt(timer[1]) + 'm ' + parseInt(timer[2]) + 's' : stats;
			var statsElement = $('<div class="stats"></div>').css({'margin-left': '17.5%', 'margin-bottom': '2px'}).text(statsText);

                // Append the stats element
                $(this).append(statsElement);
            }
        });
    }

// Find the elements within the mini profile wrapper for name and description function logMiniProfileData(miniProfileWrapper) {

var nameElement = $(miniProfileWrapper).find('.profile-mini-_userNameWrapper___Po1gZ');
var descriptionElement = $(miniProfileWrapper).find('.profile-container .description .main-desc');

// Check if both name and description elements exist if (nameElement.length && descriptionElement.length) {

// Extract the player's name and description var playerName = nameElement.text().trim(); var description = descriptionElement.text().trim();

// Iterate over enemy elements in the members list $('.members-list .enemy').each(function() { var playerNameInList = $(this).find('.honor-text').text().trim();

// Check if the player's name in the list matches the player's name in the mini profile if (playerNameInList === playerName) { var statsElement = $(this).find('.stats'); if (statsElement.length) { var stats = statsElement.text().trim().split(' - ')[0]; // Extracting only the stats part

// Check if the description contains numbers var numbersMatch = description.match(/\d+\s*(?:day|hour|minute|second)s?/ig); if (numbersMatch && numbersMatch.length >= 2) { var days = 0; var hours = 0; var minutes = 0; var seconds = 0;

// Parse the numbers and units from the description numbersMatch.forEach(function(match) { var parts = match.split(/\s+/); var value = parseInt(parts[0]); var unit = parts[1].toLowerCase();

// Assign the value to corresponding time unit if (unit.includes('day')) { days = value; } else if (unit.includes('hour')) { hours = value; } else if (unit.includes('minute')) { minutes = value; } else if (unit.includes('second')) { seconds = value; } });

// Convert days, hours, and minutes to total seconds var totalSeconds = days * 86400 + hours * 3600 + minutes * 60 + seconds;

// Clear existing interval before starting a new one clearInterval(statsElement.data('intervalId'));