1
\$\begingroup\$

all!

I am developing a web "app" with JavaScript and jQuery with the help of a couple of other libraries for ease of use.

Its purpose is to collect user ID's and to build a list of "attackable" targets for the game at https://torn.com

Details for the API can be found at https://api.torn.com, although I'm pretty sure it requires an account to do anything with it (needs an API Key, and I don't want to provide mine for security purposes)

The entirety of the site is on my gitlab instance

My biggest concern is whether or not I have created effective and efficient code to accomplish the purpose of the app. Specifically, the API call and data handling is what I am most concerned with here.


    $.get( url, function( data ) {
        var username = data.name;
        var userlevel = data.level;
        var userstatus = data.status.description;
        var liuser = $('<li/>')
        .addClass('userLevel')
        .text(userlevel)
        .appendTo(`ul.userListItem${value}`)
        var liname = $('<li/>')
        .addClass('userName')
        .text(username)
        .appendTo(`ul.userListItem${value}`);
        var listatus = $('<li/>')
        .addClass('userStatus')
        .text(userstatus)
        .appendTo(`ul.userListItem${value}`);
        var liattack = $('<li/>')
        .addClass('userAttack')
        .html(`<a href="https://www.torn.com/loader.php?sid=attack&user2ID=${value}" class="button" target="_blank">Attack!</a>`)
        .appendTo(`ul.userListItem${value}`);
        var liremove = $('<li/>')
        .addClass('userRemove')
        .html(`<a href="javascript:removeUser(${value})" type="button" class="button" id='removeuser${id}'>x</a>`)
        .appendTo(`ul.userListItem${value}`);
    });

This feels like a lot of work to do within a single API call. It works, and can be demo'd on the site it currently lives on: https://murdr.us

I'm also looking for a better input validation that can check for empty state or non-numbers entered and return an on-screen alert (rather than a browser alert as it currently shows).

here's the current validation method used:

function empty() {
    var x = $('input#useridValue').val();
    if (x == "") {
        alert("Enter a Valid User ID");
        return false;
    };
}

and the button that calls it:

$("button#submitUser").click(function() {
    if (empty() !== false ) { 
    var tempid = parseInt($('input#useridValue').val());
    console.log(tempid)
    addID(tempid);
    $('input#useridValue').val("");
    }
});

I greatly appreciate your time, folks. Hopefully, some insight and optimization techniques may be devised from this.

Thanks, all.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.