// ==UserScript== // @name BiteFight Healthbar // @namespace https://lobby.bitefight.gameforge.com/ // @version 0.1 // @description Adds an healthbar and energybar to BiteFight // @author Spychopat // @match https://*.bitefight.gameforge.com/* // @grant GM_getValue // @grant GM_setValue // @grant GM_addStyle // @downloadURL none // ==/UserScript== (function () { 'use strict'; // Constants const DEFAULT_REQUEST_DELAY_IN_MILLISECONDS = 1000 + (Math.random() * 100); const SKILLS = ["STR", "DEF", "DEX", "RES", "CHA"]; // Script storage keys const KEY_CHARACTER = 'character'; // Define character object const CHARACTER = GM_getValue(KEY_CHARACTER, { energy: 0, maxEnergy: 0, fragments: 0, gold: 0, health: 0, maxHealth: 0, hellStones: 0, skills: { STR: 0, DEF: 0, DEX: 0, RES: 0, CHA: 0 } }); //console.log(CHARACTER); // Get Stats var allStatsElement = document.getElementsByClassName("gold")[0]; var statsValues = allStatsElement.textContent.split("\n"); statsValues = statsValues.map(value => value.trim()); statsValues.shift(); // Extract energy, fragments, gold, health, and hellStones var energy = statsValues[3].trim(); var currentEnergy = energy.split("/")[0]; var maxEnergy = energy.split("/")[1]; if (currentEnergy && maxEnergy) { CHARACTER.energy = parseFloat(currentEnergy); // Use parseFloat to preserve decimals CHARACTER.maxEnergy = parseFloat(maxEnergy); // Use parseFloat to preserve decimals } var fragments = formatNumber(statsValues[2]); if (fragments) CHARACTER.fragments = parseInt(fragments); var gold = formatNumber(statsValues[0]); if (gold) CHARACTER.gold = parseInt(gold); var health = statsValues[4].trim(); var currentHealth = health.split("/")[0]; var maxHealth = health.split("/")[1]; if (currentHealth && maxHealth) { CHARACTER.health = parseFloat(currentHealth); // Use parseFloat to preserve decimals CHARACTER.maxHealth = parseFloat(maxHealth); // Use parseFloat to preserve decimals } var hellStones = formatNumber(statsValues[1]); if (hellStones) CHARACTER.hellStones = parseInt(hellStones); updateCharacter(); removeTheShit(); function removeTheShit() { GM_addStyle(` #upgrademsg { display: none; } #premium > img { display: none; } #mmonetbar { display: none !important; visibility: hidden; } `); } // Format texts to return as numbers (no thousand separators) function formatNumber(value) { while (value.indexOf(".") > 0) value = value.replace(".", ""); return value; } // Update character in local storage function updateCharacter() { GM_setValue(KEY_CHARACTER, CHARACTER); insertProgressBars(); // Insert progress bars after updating the character } // Function to insert progress bars into the page // Function to insert progress bars into the page // Function to insert progress bars into the page function insertProgressBars() { // Create container for the progress bars let container = document.createElement('div'); container.style.marginTop = '0px'; container.style.paddingTop = '3px'; container.style.paddingBottom = '8px'; container.style.paddingLeft = '60px'; container.style.paddingRight = '60px'; container.style.textAlign = 'center'; container.style.display = 'flex'; // Use flexbox for side-by-side layout container.style.justifyContent = 'space-between'; // Space out the bars // Energy Progress Bar let energyBarContainer = document.createElement('div'); energyBarContainer.style.flex = '1'; // Ensure bars take equal space energyBarContainer.style.backgroundColor = 'black'; // Black background for the container energyBarContainer.style.borderRadius = '0px'; // Rounded corners for container energyBarContainer.style.padding = '2px'; // Padding for spacing between container and bar energyBarContainer.style.outline = '2px solid #333'; // Outline around the container energyBarContainer.style.position = 'relative'; // Positioning context for the text energyBarContainer.style.marginRight = '100px'; let energyBar = document.createElement('div'); energyBar.style.height = '20px'; energyBar.style.width = `${(CHARACTER.energy / CHARACTER.maxEnergy) * 100}%`; energyBar.style.backgroundColor = '#0000a4'; energyBar.style.borderRadius = '0px'; energyBar.style.outline = '2px solid #000'; // Outline for the progress bar // Create the text for the energy value let energyText = document.createElement('div'); energyText.textContent = `${CHARACTER.energy}`; energyText.style.position = 'absolute'; energyText.style.top = '50%'; energyText.style.left = '50%'; energyText.style.transform = 'translate(-50%, -50%)'; energyText.style.color = 'white'; energyText.style.fontSize = '12px'; energyText.style.fontWeight = 'bold'; energyText.style.fontFamily = 'monospace'; energyBarContainer.appendChild(energyBar); energyBarContainer.appendChild(energyText); // Add the text to the container container.appendChild(energyBarContainer); // Health Progress Bar let healthBarContainer = document.createElement('div'); healthBarContainer.style.flex = '1'; // Ensure bars take equal space healthBarContainer.style.backgroundColor = 'black'; // Black background for the container healthBarContainer.style.borderRadius = '0px'; // Rounded corners for container healthBarContainer.style.padding = '2px'; // Padding for spacing between container and bar healthBarContainer.style.outline = '2px solid #333'; // Outline around the container healthBarContainer.style.position = 'relative'; // Positioning context for the text let healthBar = document.createElement('div'); healthBar.style.height = '20px'; healthBar.style.width = `${(CHARACTER.health / CHARACTER.maxHealth) * 100}%`; healthBar.style.backgroundColor = '#b80000'; healthBar.style.borderRadius = '0px'; healthBar.style.outline = '2px solid #000'; // Outline for the progress bar // Create the text for the health value let healthText = document.createElement('div'); healthText.textContent = `${CHARACTER.health.toFixed(3)}`; healthText.style.position = 'absolute'; healthText.style.top = '50%'; healthText.style.left = '50%'; healthText.style.transform = 'translate(-50%, -50%)'; healthText.style.color = 'white'; healthText.style.fontSize = '12px'; healthText.style.fontWeight = 'bold'; healthText.style.fontFamily = 'monospace'; healthBarContainer.appendChild(healthBar); healthBarContainer.appendChild(healthText); // Add the text to the container container.appendChild(healthBarContainer); // Insert the container into the body or any desired element on the page document.getElementsByClassName("gold")[0].appendChild(container); } })();