// ==UserScript== // @name Contador de tropas // @namespace http://tampermonkey.net/ // @version 3.5 // @license MIT // @description Muestra tropas defensivas u ofensivas con imágenes actualizadas y permite copiar el listado filtrado en un formato específico para mensajes en Grepolis. // @author Tu Nombre // @match https://*.grepolis.com/game/* // @grant GM_addStyle // @grant GM_setClipboard // @downloadURL none // ==/UserScript== (function() { 'use strict'; const uw = unsafeWindow; // CSS para la ventana GM_addStyle(` #GTM_button { margin-bottom: 3px; cursor: pointer; } #GTM_window { display: none; width: 600px; z-index: 1100; position: absolute; top: 100px; left: 30vw; text-align: center; background-color: #f0e6d6; border: 2px solid black; border-radius: 10px; padding: 10px; } #GTM_close { float: right; margin-top: -20px; cursor: pointer; font-size: 18px; } .GTM_unit { display: inline-block; margin: 5px; text-align: center; } .GTM_unit img { width: 40px; height: 40px; display: block; margin: 0 auto; } .GTM_unit span { display: block; margin-top: 5px; font-weight: bold; } .GTM_total { font-weight: bold; color: red; margin-top: 10px; } #GTM_message_button { margin-top: 10px; cursor: pointer; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; font-size: 14px; } #GTM_message_button:hover { background-color: #45a049; } #GTM_filters { margin-bottom: 10px; } .GTM_filter_button { cursor: pointer; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; font-size: 14px; margin-right: 5px; } .GTM_filter_button.active { background-color: #45a049; } .GTM_filter_button:hover { background-color: #45a049; } `); // Mapeo de unidades defensivas y ofensivas con sus nombres en español e imágenes actualizadas const defensiveUnits = { "sword": { name: "Espadachín", img: "https://imgur.com/SUCgJU3.png" }, "archer": { name: "Arquero", img: "https://i.imgur.com/xLOtNgs.png" }, "hoplite": { name: "Hoplita", img: "https://imgur.com/fjjL6GT.png" }, "chariot": { name: "Carro", img: "https://i.imgur.com/GpLHnv3.png" }, "bireme": { name: "Birreme", img: "https://i.imgur.com/kLQCM99.png" }, "trireme": { name: "Trirreme", img: "https://i.imgur.com/0YlGkCP.png" }, "fire_ship": { name: "Brulote", img: "https://i.imgur.com/JNfJ3h0.png" } }; const offensiveUnits = { "slinger": { name: "Hondero", img: "https://imgur.com/SEgKJTm.png" }, "rider": { name: "Caballero", img: "https://imgur.com/mFnNJ0E.png" }, "catapult": { name: "Catapulta", img: "https://i.imgur.com/oFEOsXo.png" }, "harpy": { name: "Arpía", img: "https://i.imgur.com/PA4uFbi.png" }, "griffin": { name: "Grifo", img: "https://i.imgur.com/EHb10e5.png" }, "manticore": { name: "Mantícora", img: "https://i.imgur.com/ttR3Q8x.png" }, "hydra": { name: "Hidra", img: "https://i.imgur.com/bQTnQv1.png" }, "flame_ship": { name: "Lanzallamas", img: "https://i.imgur.com/43NVBNT.png" }, "attack_ship": { name: "Nave Incendiaria", img: "https://i.imgur.com/Y5WorTq.png" }, "trireme": { name: "Trirreme", img: "https://i.imgur.com/0YlGkCP.png" } }; let currentFilter = 'defensive'; // Función para extraer la información de las tropas según el filtro function getTroopData() { let troopData = {}; try { const player_towns = uw.ITowns.towns; for (let townId in player_towns) { if (player_towns.hasOwnProperty(townId)) { const town = player_towns[townId]; const units = town.units(); for (let unit in units) { if (units.hasOwnProperty(unit) && units[unit] > 0) { const unitList = currentFilter === 'defensive' ? defensiveUnits : offensiveUnits; if (unitList[unit]) { if (!troopData[unit]) troopData[unit] = 0; troopData[unit] += units[unit]; } } } } } } catch (e) { console.error("Error while fetching troop data:", e); } return troopData; } // Función para generar el mensaje de texto function generateMessageText(troopData) { let messageText = 'Tengo las siguientes tropas:\n'; const unitList = currentFilter === 'defensive' ? defensiveUnits : offensiveUnits; for (let unit in unitList) { if (troopData.hasOwnProperty(unit)) { messageText += `${unitList[unit].name}: ${troopData[unit]}\n`; } } return messageText; } // Función para copiar el texto al portapapeles function copyToClipboard(troopData) { const messageText = generateMessageText(troopData); GM_setClipboard(messageText, 'text'); alert('El texto ha sido copiado al portapapeles.'); } // Función para mostrar la ventana con las tropas function displayTroopManager() { let troopData = getTroopData(); let troopHtml = ''; const unitList = currentFilter === 'defensive' ? defensiveUnits : offensiveUnits; for (let unit in unitList) { if (troopData.hasOwnProperty(unit)) { troopHtml += `