Changing text color in YEP_ShopMenuCore

Hi everybody!
I'm new here and it's my firts post; I hope it's the right place to post this...

I'm currently trying to edit Yanfly ShopMenuCore so that it show elements/states rates with icons.
This is the main function I added:

Code:
Window_ShopStatus.prototype.drawAttributes = function() {
    let item = this._item
    let rateList = [1, 1, 1, 1]
    let iconList = [78, 76, 31, 92];
    let iconPos = [4, 69, 132, 196];
    let attributes = ''
    let p = 0;
    let i;
    for (i in item.traits) {
      if (item.traits[i].code === 11) {
        var id = item.traits[i].dataId - 1;
        rateList[id] *= item.traits[i].value;
      }
    }
    for (i = 0; i < 4; i++) {
      if (rateList[i] !== 1) {
        rateList[i] = Math.floor(-1 * (100 - rateList[i] * 100));
        if (rateList[i] >= 200) {
          this.changeTextColor(this.textColor(10));
        } else if (rateList[i] >= 100) {
          this.changeTextColor(this.textColor(2))
        } else if (rateList[i] >= 1) {
          this.changeTextColor(this.textColor(14))
        } else if (rateList[i] >= -25) {
          this.changeTextColor(this.textColor(5))
        } else if (rateList[i] >= -50) {
          this.changeTextColor(this.textColor(13))
        } else if (rateList[i] > -75) {
          this.changeTextColor(this.textColor(31))
        } else if (rateList[i] <= -75) {
          rateList[i] = 'Immune'
          this.changeTextColor(this.textColor(27))
        } else if (rateList[i] < -100) {
          rateList[i] = 'Regen'
          this.changeTextColor(this.textColor(24))
         }
        var iconIndex = iconList[i];
        var bitmap = ImageManager.loadSystem('IconSet');
        var pw = Window_Base._iconWidth;
        var ph = Window_Base._iconHeight;
        var sx = iconIndex % 16 * pw;
        var sy = Math.floor(iconIndex / 16) * ph;
        var dw = 24;
        var dh = 24;
        var dx = iconPos[p];
        var dy = 180;
        this.contents._context.imageSmoothingEnabled = false;
        this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh)
        this.contents._context.imageSmoothingEnabled = true;
        attributes += rateList[i] + '%' + '    ';
        p += 1;
      }
    }
    var rect = this.getBigRectPos(0);
    this.drawText(attributes, rect.x + 30, rect.y - 3, rect.width);
};

And this how it looks:
screen2.png

So it work fine except for the color changes...
I would like it to look like this:

screen1.png

A different color depending on the rate value.
This was scripted in the Yanfly ItemCore <Info Eval> notetag where text codes are accepted.
Since text codes can't be used inside the plugin js files I tried to use the function:
this.changeTextColor(this.textColor(id));
But it change the color of the whole text according to the last entry that was checked in the loop...
I think this is because the this keyword represent the whole function, but I can't figure out how to apply the function to a specific entry;
rateList[id].changeTextColor... makes the game crash.

So I was wondering if someone can point me toward some solutions?
Thanks in advance to anyone who will take the time to reply.
TSR
I solved my problem last night!
I splited the function in 3 functions for the sake of clarity and the solution just appeared to me...
This is the finale 3 functions:

Code:
Window_ShopStatus.prototype.drawAttributes = function() {
    let item = this._item
    let attributes = ''
    let rateList = [1, 1, 1, 1];
    let textPos = [30, 95, 158, 222];
    var p = 0;
    var i;
    var rect = this.getBigRectPos(0);
    for (i in item.traits) {
      if (item.traits[i].code === 11) {
        var id = item.traits[i].dataId - 1;
        rateList[id] *= item.traits[i].value;
      }
    }
    for (i = 0; i < 4; i++) {
      if (rateList[i] !== 1) {
        rateList[i] = Math.floor(-1 * (100 - rateList[i] * 100));
        var text = rateList[i]
        var Text = this.getTextColor(text)
        attributes =  Text + '%' + '    ';
        this.drawText(attributes, textPos[p], rect.y - 3, rect.width);
        this.getIcon(i, p);
        p += 1;
      } 
    }   
};

Window_ShopStatus.prototype.getIcon = function(i, p) {
        let iconList = [78, 76, 31, 92];
        let iconPos = [4, 69, 132, 196];
        let iconIndex = iconList[i];
        let bitmap = ImageManager.loadSystem('IconSet');
        let pw = Window_Base._iconWidth;
        let ph = Window_Base._iconHeight;
        let sx = iconIndex % 16 * pw;
        let sy = Math.floor(iconIndex / 16) * ph;
        let dw = 24;
        let dh = 24;
        let dx = iconPos[p];
        let dy = 180;
        this.contents._context.imageSmoothingEnabled = false;
        this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh)
        this.contents._context.imageSmoothingEnabled = true;
}

Window_ShopStatus.prototype.getTextColor = function(text) {
       if (text >= 200) {
          this.changeTextColor(this.textColor(10));
          text = '+'.concat(text);
        } else if (text >= 100) {
          this.changeTextColor(this.textColor(2));
          text = '+'.concat(text);
        } else if (text >= 1) {
          this.changeTextColor(this.textColor(14));
          text = '+'.concat(text);
        } else if (text >= -25) {
          this.changeTextColor(this.textColor(5));
        } else if (text >= -50) {
          this.changeTextColor(this.textColor(13));
        } else if (text > -75) {
          this.changeTextColor(this.textColor(31));
        } else if (text <= -75) {
          text = 'Immune'
          this.changeTextColor(this.textColor(27));
        } else if (rateList[i] < -100) {
          text = 'Regen'
          this.changeTextColor(this.textColor(24));
        }
      return text
};

This Thread can be close, thanks.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/changing-text-color-in-yep_shopmenucore.115477/