Greasy Fork is available in English.
Adds an healthbar and energybar to BiteFight
当前为
// ==UserScript==
// @name BiteFight Healthbar
// @namespace https://lobby.bitefight.gameforge.com/
// @version 0.2
// @description Adds an healthbar and energybar to BiteFight
// @author Spychopat
// @match https://*.bitefight.gameforge.com/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// ==/UserScript==
(function () {
'use strict';
// Script storage keys
const KEY_CHARACTER = 'character';
// Define character object
const CHARACTER = GM_getValue(KEY_CHARACTER, {
energy: 0,
maxEnergy: 0,
health: 0,
maxHealth: 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 = parseInt(currentEnergy); // Use parseFloat to preserve decimals
CHARACTER.maxEnergy = parseInt(maxEnergy); // Use parseFloat to preserve decimals
}
var health = statsValues[4].trim();
var currentHealth = formatNumber(health.split("/")[0]);
var maxHealth = formatNumber(health.split("/")[1]);
//console.log("maxhealth : "+maxHealth);
if (currentHealth && maxHealth) {
CHARACTER.health = parseInt(currentHealth);
CHARACTER.maxHealth = parseInt(maxHealth);
}
updateCharacter();
removeTheShit();
insertProgressBars(); // Insert progress bars after updating the character
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);
}
// 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 > 999 ? CHARACTER.health.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.') : CHARACTER.health}`;
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);
}
})();