nike / Kamihime Project R - Dispaly Enemy HP (FIXED, compact)

// ==UserScript==
// @name         Kamihime Project R - Dispaly Enemy HP (FIXED, compact)
// @description  Displays enemy HP value
// @updateURL    https://openuserjs.org/meta/nike/Kamihime_Project_R_-_Dispaly_Enemy_HP_(FIXED,_compact).meta.js
// @license      MIT
// @match        https://gnkh-api-r.prod.nkh.dmmgames.com/front/cocos2d-proj/components-pc/game/app.html
// @run-at       document-start
// ==/UserScript==
(function () {

  var interval = setInterval(function () {
    if (typeof kh !== 'undefined' && kh.Enemy && kh.EnemyStatusBar && kh.BattleWorld) {
      clearInterval(interval);

      if (kh.enemyHpDefined) {
        return;
      }

      kh.enemyHpDefined = true

      var orig_ctor = kh.EnemyStatusBar.prototype.ctor;

      kh.EnemyStatusBar.prototype.ctor = function new_ctor(t, n, a, i) {
        orig_ctor.apply(this, new_ctor.arguments);
        var hp_text = this.ui.getChildByName("hp_text") || new ccui.Text();
        hp_text.setName("hp_text");
        hp_text.setFontSize(10);
        hp_text.enableOutline(cc.color.BLACK, 1);
        hp_text.setPosition([234, 145, 145][a - 1], 42);
        this.ui.addChild(hp_text);
      }

      var formatNumber = function (num) {
        return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
      }

      var updateHPText = function (e) {
        ccui.helper.seekWidgetByName(e.statusPanel.ui, "hp_text").setText(formatNumber(e.hp));
      }

      kh.Enemy.prototype.adjustHP = function (t) {
        kh.BattleUnit.prototype.adjustHP.call(this, t);
        updateHPText(this);
      }

      var orig_start = kh.BattleWorld.prototype._start;

      kh.BattleWorld.prototype._start = async function new_start(sceneInstanceId) {
        this.enemyList.filter(t => t && Object.entries(t).length).forEach(updateHPText);
        return orig_start.apply(this, [sceneInstanceId]);
      }

    }
  }, 10);

})();