Elethor General Purpose

Provides some general UI additions to Elethor

目前为 2021-01-08 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Elethor General Purpose
  3. // @description Provides some general UI additions to Elethor
  4. // @namespace https://www.elethor.com/
  5. // @version 1.0.0
  6. // @author Anders Morgan Larsen (Xortrox)
  7. // @match https://elethor.com/*
  8. // @match https://www.elethor.com/*
  9. // @run-at document-start
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. const playerHealthBarElementDefinition = '.progress.is-medium.is-danger';
  15. const playerHealthBarTextElementDefinition = '.is-fight-health';
  16.  
  17. function getBattleHealthPercentage() {
  18. const playerHealth = document.querySelector(playerHealthBarElementDefinition);
  19.  
  20. if (!playerHealth) {
  21. return 0;
  22. }
  23.  
  24. return playerHealth.value / playerHealth.max * 100;
  25. }
  26.  
  27. function initializeUpdateBattleHealthPercentage() {
  28. if (window.elethorExtrasInterval) {
  29. clearInterval(window.elethorExtrasInterval);
  30. }
  31.  
  32. window.elethorExtrasInterval = setInterval(() => {
  33. const playerHealthText = document.querySelector(playerHealthBarTextElementDefinition);
  34. const healthPercentage = getBattleHealthPercentage();
  35.  
  36. if (playerHealthText && healthPercentage && !isNaN(healthPercentage)) {
  37. let percentageDisplay;
  38. if (playerHealthText.children.length === 0) {
  39. percentageDisplay = document.createElement('span');
  40.  
  41. playerHealthText.appendChild(percentageDisplay);
  42. } else {
  43. percentageDisplay = playerHealthText.children[0];
  44. }
  45. if (percentageDisplay) {
  46. percentageDisplay.innerText = ` (${healthPercentage.toFixed(3)}%)`;
  47. }
  48. }
  49. }, 500);
  50. }
  51.  
  52. (function run() {
  53. initializeUpdateBattleHealthPercentage();
  54. })();
  55. })();