Highlight Players with Name and Health Bar

Highlight all players and show their name and health bar

  1. // ==UserScript==
  2. // @name Highlight Players with Name and Health Bar
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description Highlight all players and show their name and health bar
  6. // @author You
  7. // @match https://tankionline.com
  8. // @match https://tankionline.com/play/
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to highlight players and display their name and health bar
  16. function highlightPlayers() {
  17. // Select all player elements (adjust selector as needed)
  18. const players = document.querySelectorAll('.player'); // Adjust '.player' to the actual selector for players
  19.  
  20. players.forEach(player => {
  21. // Highlight the player with a border and glowing effect
  22. player.style.border = '3px solid red';
  23. player.style.boxShadow = '0 0 10px rgba(255, 0, 0, 0.7)';
  24.  
  25. // Get player's name (assuming name is within an element with class 'player-name')
  26. const playerName = player.querySelector('.player-name'); // Adjust selector for player name
  27. if (playerName) {
  28. playerName.style.fontSize = '16px';
  29. playerName.style.fontWeight = 'bold';
  30. playerName.style.color = 'red';
  31. playerName.textContent = `Player: ${playerName.textContent}`; // Prefix name with "Player:"
  32. }
  33.  
  34. // Get player's health (assuming health is within an element with class 'health-bar')
  35. const healthBar = player.querySelector('.health-bar'); // Adjust selector for health bar
  36. if (healthBar) {
  37. // Display the health as a percentage
  38. const healthPercentage = healthBar.getAttribute('data-health'); // Assuming health is stored in 'data-health' attribute
  39. const healthText = document.createElement('div');
  40. healthText.textContent = `Health: ${healthPercentage}%`;
  41. healthText.style.position = 'absolute';
  42. healthText.style.top = '0';
  43. healthText.style.left = '50%';
  44. healthText.style.transform = 'translateX(-50%)';
  45. healthText.style.color = 'white';
  46. healthText.style.fontSize = '12px';
  47. healthText.style.fontWeight = 'bold';
  48. healthText.style.textShadow = '2px 2px 5px rgba(0, 0, 0, 0.7)';
  49. player.appendChild(healthText);
  50.  
  51. // Optionally, change the health bar color based on the health
  52. if (healthPercentage < 50) {
  53. healthBar.style.backgroundColor = 'orange';
  54. }
  55. if (healthPercentage < 20) {
  56. healthBar.style.backgroundColor = 'red';
  57. }
  58. }
  59. });
  60. }
  61.  
  62. // Run the highlight function every 1 second to keep players updated
  63. setInterval(highlightPlayers, 1000);
  64. })();