HaJaeKyung / KittyExtension

Fan add-on for https://www.cryptokitties.co
MIT License
232 stars 87 forks source link

"speed.InnerText" can be wrong in overlay() #42

Open PilotFlying opened 6 years ago

PilotFlying commented 6 years ago

The text says "Fast"

ck_hover

but, at the same time, the API call returns (the correct) cooldown index of 9:

ck_api

This fix works I believe, api_data is passed to requestId() later (don't really know javascript so not submitting a file):

function overlay() {
     [...]
                element.innerHTML += "<div class='extWrapper'><ul style='list-style: none;' class='extBounce extAttUl'>🐈</ul></div>";

                // Fix incorrect speed.innerText above
                //   nativeElement.getElementsByClassName('KittyCard-coldown')[0]
                //   may return innertext "Fast" for cat which is "Slow"
                // Save api data to global variable to avoid a repeat call in requestId()
                api_data = stats.fast = null;
                $.ajax({
                    url: "https://api.cryptokitties.co/kitties/"+curId,
                    async: false,
                    dataType: 'json',
                    success: function(data) {
                        let cd_index = data.status.cooldown_index;
                        api_data = data;
                        stats.fast = cdTbl.indexOf(cdValueTbl[cd_index]);
                    }
                });