nike / Kamihime Project R - Display eidolon turns

// ==UserScript==
// @name         Kamihime Project R - Display eidolon turns
// @description  Displays eidolon turn cooldown directly on eidolon card
// @updateURL    https://openuserjs.org/meta/nike/Kamihime_Project_R_-_Display_eidolon_turns.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.SummonCard) {
            clearInterval(interval);
            kh.SummonCard.prototype.init = function(parentWidget) {
                this._card = parentWidget.seekWidgetByName(this.CARD_NAME);
                this._element = parentWidget.seekWidgetByName(this.ELEMENT_NAME);
                this._turnLabel = parentWidget.seekWidgetByName(this.TURN_LABEL_NAME);
                this._turnLabelCard = khutil.cloneWithAction(this._turnLabel)
                this._turnLabelCard.setPosition(45, 65)
                parentWidget.addChild(this._turnLabelCard)
                this.setVisible(false);

                return this;
            }

            kh.SummonCard.prototype.cleanup = function(parentWidget) {
                if (this._card) {
                    this._card.addTouchEventListener(null, null);
                    this._card = null;
                }
                this._element = null;
                this._turnLabel = null;
                this._turnLabelCard = null;
            }

            kh.SummonCard.prototype.updateTurn = function(turn) {
                if (turn <= 0) {
                    this._turnLabel.setVisible(false);
                    this._turnLabelCard.setVisible(false);
                    return;
                }
                // MEMO:この t はフォントで「Turn」に展開されます
                this._turnLabel.string = "t" + turn;
                this._turnLabel.setVisible(this._turnNumberEnabled);
                this._turnLabelCard.string = turn.toString()
                this._turnLabelCard.setVisible(!this._turnNumberEnabled);
            }

        }
    }, 10);

})();