Easy Execute %

Calculate and display Execute %

当前为 2024-05-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Easy Execute %
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Calculate and display Execute %
  6. // @author ChatGPT
  7. // @match https://www.torn.com/loader.php?sid=attack*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to calculate 19% of a value
  16. function calculatePercentage(value) {
  17. return value * 0.19; // Change this to your Execute %
  18. }
  19.  
  20. // Function to extract maximum health value from the webpage and calculate 19% of it
  21. function updatePercentage() {
  22. // Select all elements whose ID contains "player-health-value_"
  23. var healthValueElements = document.querySelectorAll('[id^="player-health-value_"]');
  24. if (healthValueElements.length > 0) {
  25. healthValueElements.forEach(function(element) {
  26. var healthText = element.textContent.trim();
  27. var maxHealth = healthText.split("/")[1].replace(",", "").trim(); // Extract maximum health value
  28. var value = parseFloat(maxHealth);
  29. if (!isNaN(value)) {
  30. var percentage = calculatePercentage(value);
  31. // Display the result on the screen
  32. displayPercentage(percentage);
  33. // Log the result to the console
  34. console.log("19% of maximum health is: " + percentage.toFixed(2));
  35. }
  36. });
  37. }
  38. }
  39.  
  40. // Function to display the calculated percentage on the screen
  41. function displayPercentage(percentage) {
  42. var existingDisplay = document.getElementById("percentage-display");
  43. if (existingDisplay === null) {
  44. // Create a new element if it doesn't exist
  45. var displayElement = document.createElement("div");
  46. displayElement.id = "percentage-display";
  47. displayElement.style.position = "absolute";
  48. displayElement.style.top = "109px";
  49. displayElement.style.left = "950px";
  50. displayElement.style.background = "transparent";
  51. displayElement.style.padding = "8px";
  52. document.body.appendChild(displayElement);
  53. existingDisplay = displayElement;
  54. }
  55. // Round down the percentage to remove decimal points
  56. var roundedPercentage = Math.floor(percentage);
  57. // Update the content of the element with the new rounded percentage
  58. existingDisplay.textContent = "Execute HP: " + roundedPercentage;
  59. }
  60.  
  61. // Call updatePercentage after a short delay to allow the page to fully load
  62. setTimeout(updatePercentage, 500); // delay
  63.  
  64. })();