jeudi 21 avril 2016

Function not working inside of an if statement

I'm going through a JSON table and getting the ID of an item on ROBLOX. In case you don't work with ROBLOX, we'll use letters. If A's name is B's asset ID, then change A's name to B's name. That's basically what I want to do, but it's not working. Here's my if statement. The function on line 61 isn't running. By the way this code is ran inside of Chrome console.

var tags = "Tags: muscle stripes cats stealth pilot telamon free VIP funny awesome flames dogs fur gir builderman anti noob fat muscle super superman spiderman green goblin joker jacket free jacked fun VIP 1waffle1 cafe orange blue grey black red purple turqoise stripes DC volcom tan pink coolest best money nothing family guy stewie peter meg lois quagmire giggity haha lol happy time rich most awesome contest winner best selling =D roblox scatman skull god mini chris cowboy spy zombie batman simpsons bart maggie marge vike gogocrazy monkey sloth pig evil dark super script lesson mini cool blockhead hoodie LOL :D :) :( Cool DC disney shirt pink OUT in rubbish hobo numa poke jacket 1 2 3 4 5 6 7 8 9 monster energy fallen twilight zoo york america";

function edit(id, name) {
    $.get("http://ift.tt/1NE9asE" + id).success(function(data) {
        var ET      = "ctl00$cphRoblox$SubmitButtonTop";
        var EA      = "";
        var VS      = $("#__VIEWSTATE", data).val();
        var VSG     = $("#__VIEWSTATEGENERATOR", data).val();
        var EV      = $("#__EVENTVALIDATION", data).val();
        var PP      = $("#__PREVIOUSPAGE", data).val();
        var Data = {
            __EVENTTARGET : encodeURIComponent(ET),
            __EVENTARGUMENT : "",
            __VIEWSTATE : encodeURIComponent(VS),
            __VIEWSTATEGENERATOR : encodeURIComponent(VSG),
            __PREVIOUSPAGE : PP  == "undefined" ? "" : PP,
            __EVENTVALIDATION : encodeURIComponent(EV)
        }
        Data[encodeURIComponent("ctl00$cphRoblox$NameTextBox")] = encodeURIComponent(name)
        Data[encodeURIComponent("ctl00$cphRoblox$EnableCommentsCheckBox")] = "on"
        Data[encodeURIComponent("GenreButtons2")] = 1
        Data[encodeURIComponent("ctl00$cphRoblox$SellThisItemCheckBox")]= "on"
        Data[encodeURIComponent("ctl00$cphRoblox$SellForRobux")]= "on"
        Data[encodeURIComponent("ctl00$cphRoblox$actualGenreSelection")] = 1
        Data[encodeURIComponent("ctl00$cphRoblox$DescriptionTextBox")] = encodeURIComponent(tags)
        Data[encodeURIComponent("ctl00$cphRoblox$RobuxPrice")] = 5
        var Request = new XMLHttpRequest();
        var ParamString = "";
        Request.open("POST", "http://ift.tt/1NE9asE" + id, true);
        Request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
        Request.setRequestHeader("Cache-Control", "max-age=0");
        Request.setRequestHeader("Upgrade-Insecure-Requests", "1");
        Request.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
        $.each(Data, function(Key, Value){
            ParamString = ParamString + Key + "=" + Value + "&";
        });
        ParamString = ParamString.substr(0, ParamString.length-1); // Removes trailing "&"
        Request.send(ParamString);
        console.log("Item edited successfully.");
    });
}

function loop(page, cb) {
    $.get("http://ift.tt/1Wg6BUq" + page).success(function(data) {
        cb(data);
    });
}


for (var page = 1; page < 15; page++) {
    loop(page, function(data) {
        console.log("On page: " + page);
        for (var i = 0; i < data.length; i++) {
            var prev = data[i].Name;
            var id       = data[i].AssetId
            if ($.isNumeric(prev)) {
                console.log("Number: " + prev);
                //console.log("Name was Number, changing...")
                $.get("http://ift.tt/1NE9asH" + parseInt(prev)).success(function(data2) {
                    var name = $("h1.notranslate", data2).text();
                    edit(id, name); // function doesn't run here???
                    //console.log("Changed to " + name);
                });
            } else if (!$.isNumeric(prev)) {
                console.log("String: " + prev);
                edit(id, prev);
            }
        }
    });
}

Aucun commentaire:

Enregistrer un commentaire