2
\$\begingroup\$

I'm trying to simplify this code. It seems everything runs as it should; however, when in the refresh loop from iMacro, it seems a little inefficient and can take up to 7 seconds to fully execute (it seems to keep looping before actually running the next step).

As you can probably figure, it's an iMacros bot coded in JavaScript.

This bot's purpose is to refresh constantly as long as the text specified is on the screen. When that text is no longer on that screen (page changed) then it checks one of two things:

ONE

  • If a certain hyperlink is there, click it.
  • If the page after clicking the hyperlink has a button, click it and go to the next page.
  • If there is no button, go to the next page.
  • If there is certain error code under that button, go to the next page.

TWO

If the certain hyperlink is not there, go to the next page.

// REMOVED V 2.0
// REMOVED
// REMOVED

/*-------------------- BEGIN CODE ---------------------------- */

run(); // Runs REMOVED

// REMOVED. 
function run() {
    var currentURL = window.location.href; // Get current URL
    var pathArray = window.location.pathname.split( '/'); // split URL into parts after the dot
    var REMOVEDNumber = pathArray[2]; // extract REMOVED number from the 2nd dot
    var numb = REMOVEDNumber.replace(/[\D]/g, ''); // extract just the numbers
    var lastFive = numb.substr(numb.length - 5);
    var nextREMOVED = parseInt(lastFive) + 1; // turn that number into an integer

    // REMOVED
    var exists = doesElementExist();
    if (exists) {
        do {
            var exists = doesElementExist();
            iimPlay('CODE:' + '\n'
                + 'Refresh');
                if (exists !== true) {
                    // alert('REMOVED ' + exists);
                    var REMOVED = doesREMOVEDExist();
                    if (REMOVED) {
                        iimPlay('CODE:\n'
                        + 'TAB T=1\n'
                        + 'SET !TIMEOUT_TAG 1\n'
                        + 'TAG POS=1 TYPE=BUTTON ATTR=TXT:REMOVED\n');

                        var checkREMOVEDState = checkREMOVED();
                        if (checkREMOVEDState) {
                            iimDisplay('REMOVED');
                            window.location.href = 'REMOVED' + nextREMOVED;
                            run();
                        }
                        else {
                            var checkIfFake = checkTroll();
                            if (checkIfFake) {
                            iimDisplay('REMOVED Successfully');
                            }
                            else {
                                iimDisplay('REMOVED');
                                iimPlay('CODE: TAB CLOSE');
                                window.location.href = 'REMOVED' + nextREMOVED;
                                run();
                            }
                        }

                    }
                    else {
                        iimDisplay('No REMOVED links here, moving on.');
                        window.location.href = 'REMOVED' + nextREMOVED;
                        run();
                    }
                }
                if (exists === '#EANF#') {
                    break;
                }
        } while (exists);
    }

    // REMOVED
    else {
        var REMOVED = doesREMOVEDExist();
        if (REMOVED) {
            iimPlay('CODE:\n'
            + 'TAB T=1\n'
            + 'SET !TIMEOUT_TAG 1\n'
            + 'TAG POS=1 TYPE=BUTTON ATTR=TXT:REMOVED\n');

            var checkREMOVEDState = checkREMOVED();
            if (checkREMOVEDState) {
                iimDisplay('REMOVED Failed');
                window.location.href = 'REMOVED' + nextREMOVED;
                run();
            }
            else {
                var checkIfFake = checkTroll();
                if (checkIfFake) {
                    iimDisplay('REMOVED Successfully');
                }
                else {
                    iimDisplay('faggot was trolling, on to the next REMOVED.');
                    iimPlay('CODE: TAB CLOSE');
                    window.location.href = 'REMOVED' + nextREMOVED;
                    run();
                }
            }
        }

        // Checks if there are any REMOVED links on the REMOVED -- then moves on.
        else {

            do {
                iimDisplay('No REMOVED here');
                var nextREMOVED = parseInt(lastFive) + 1;

                iimDisplay('Going to next REMOVED');
                window.location.href = 'REMOVED' + nextREMOVED;
                nextREMOVED++;
                iimDisplay('next REMOVED will be ' + nextREMOVED);
                run();
            } while (nextREMOVED < 99999);

        }
    }
}

// Checking if a REMOVED has loaded or not
function doesElementExist() {
    iimDisplay('Checking if a REMOVED has loaded, or not.');
    var code = iimPlay('CODE: SET !TIMEOUT_TAG 1\n'
        + 'TAG POS=1 TYPE=DIV ATTR=TXT:REMOVED<SP>REMOVED<SP>-<SP>REMOVED');
    if (code !==1) {
        return false;
    }
    var extract = iimGetLastExtract(1);
    if (extract === '#EANF#') {
        return false;
    }
    return true;
}

// If REMOVED is loaded, we will check if there is an REMOVED link.
function doesREMOVEDExist() {
    iimDisplay('Checking if an REMOVED link is on page.');
    var link = iimPlay('CODE: SET !TIMEOUT_TAG 1\n'
        + 'TAG POS=1 TYPE=A ATTR=TXT:REMOVED');
    if (link !==1) {
        return false;
    }
    var extract = iimGetLastExtract(2);
    if (extract === '#EANF#') {
        return false;
    }
    return true;
}

// We will check if the REMOVED was already REMOVEDed.
function checkREMOVED() {
    iimDisplay('Checking if REMOVED if valid.');
    var link = iimPlay('CODE: SET !TIMEOUT_TAG 1\n'
        + 'TAG POS=1 TYPE=DIV ATTR=TXT:An<SP>error<SP>occurred:');
    if (link !==1) {
        return false;
    }
    var extract = iimGetLastExtract(2);
    if (extract === '#EANF#') {
        return false;
    }
    return true;
}

// Checks if the REMOVED link was real by checking if there is a REMOVED button.
function checkTroll() {
    iimDisplay('Checking if an REMOVED is on page');
    var link = iimPlay('CODE: SET !TIMEOUT_TAG 1\n'
                    + 'TAG POS=1 TYPE=BUTTON ATTR=TXT:REMOVED\n');
    if (link !==1) {
        return false;
    }
    var extract = iimGetLastExtract(2);
    if (extract === '#EANF#') {
        return false;
    }
    return true;
}

/*-------------------- END CODE ---------------------------- */ 
\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

The main problem you mention (it seems to keep looping before actually running the next step) looks like its probably due to the exists variable not being set properly to a non-truthy value.

You break out of the loop if (exists === '#EANF#') {, which seems impossible to accomplish, as doesElementExist only returns true or false. You'll also stop looping if exists stops being truthy. I would assume that the EANFCheck function never actually hits extract === '#EANF#' and that code!==1 in doesElementExist never hits, so your check always returns true and you keep on looping.

As far as optimizing or even being sure I'm analyzing the code correctly, it's a decent sized chunk of code, and there's a ton of censored variable names and strings that were all just replaced with REMOVED, so it's pretty hard to tell what's going on.

I have to assume that you've gotten all of the string censorship correct, and that variables and strings that appear the same ARE the same, although I suspect they probably aren't.

Anyway, maybe this edited block will help you, but if it doesn't - consider un-censoring some of this content or posting a smaller completely uncensored chunk.

Changes:

  • Moved run() call to the bottom. Not strictly necessary, but it's not great practice to declare functions and variables below where you call them
  • some variables were only used for if checks. Replaced those references with direct calls to the if check functions
  • Replaced all window.location.href = 'REMOVED' + nextREMOVED; run(); calls with callNext() function
  • condensed a couple else { if{ }else{ } } blocks to just if else { } else { }
  • Added an EANFCheck function to replace all your if(EANF) returns at the bottom

    // REMOVED V 2.0
    // REMOVED
    // REMOVED
    
    /*-------------------- BEGIN CODE ---------------------------- */
    
    // REMOVED. 
    function run() {
        var pathArray = window.location.pathname.split( '/'); // split URL into parts after the dot
        var REMOVEDNumber = pathArray[2]; // extract REMOVED number from the 2nd dot
        var numb = REMOVEDNumber.replace(/[\D]/g, ''); // extract just the numbers
        var lastFive = numb.substr(numb.length - 5);
        var nextREMOVED = parseInt(lastFive) + 1; // turn that number into an integer
    
        // REMOVED
        var exists = doesElementExist();
        if (exists) {
            do {
                var exists = doesElementExist();
                iimPlay('CODE:' + '\n'
                    + 'Refresh');
                    if (exists !== true) {
                        // alert('REMOVED ' + exists);
                        if ( doesREMOVEDExist() ) {
                            iimPlay('CODE:\n'
                            + 'TAB T=1\n'
                            + 'SET !TIMEOUT_TAG 1\n'
                            + 'TAG POS=1 TYPE=BUTTON ATTR=TXT:REMOVED\n');
    
                            if ( checkREMOVED() ) {
                                iimDisplay('REMOVED');
                                callNext( nextREMOVED );
                            }
                            else if ( checkTroll() ) {
                                iimDisplay('REMOVED Successfully');
                            }
                            else {
                                iimDisplay('REMOVED');
                                iimPlay('CODE: TAB CLOSE');
                                callNext( nextREMOVED );
                            }
    
                        }
                        else {
                            iimDisplay('No REMOVED links here, moving on.');
                            callNext( nextREMOVED );
                        }
                    }
                    if (exists === '#EANF#') {
                        break;
                    }
            } while (exists);
        }
    
        // REMOVED
        else if ( doesREMOVEDExist() ) {
            iimPlay('CODE:\n'
            + 'TAB T=1\n'
            + 'SET !TIMEOUT_TAG 1\n'
            + 'TAG POS=1 TYPE=BUTTON ATTR=TXT:REMOVED\n');
    
            if ( checkREMOVED() ) {
                iimDisplay('REMOVED Failed');
                callNext( nextREMOVED );
            }
            else if ( checkTroll() ) {
                iimDisplay('REMOVED Successfully');
            }
            else {
                iimDisplay('faggot was trolling, on to the next REMOVED.');
                iimPlay('CODE: TAB CLOSE');
                callNext( nextREMOVED );
            }
        }
    
        // Checks if there are any REMOVED links on the REMOVED -- then moves on.
        else {
    
            do {
                iimDisplay('No REMOVED here');
                var nextREMOVED = parseInt(lastFive) + 1;
    
                iimDisplay('Going to next REMOVED');
                window.location.href = 'REMOVED' + nextREMOVED;
                nextREMOVED++;
                iimDisplay('next REMOVED will be ' + nextREMOVED);
                run();
            } while (nextREMOVED < 99999);
    
        }
    }
    
    function callNext( nextREMOVED ){
        window.location.href = 'REMOVED' + nextREMOVED;
        run();
    }
    
    // Checking if a REMOVED has loaded or not
    function doesElementExist() {
        iimDisplay('Checking if a REMOVED has loaded, or not.');
        var code = iimPlay('CODE: SET !TIMEOUT_TAG 1\n'
            + 'TAG POS=1 TYPE=DIV ATTR=TXT:REMOVED<SP>REMOVED<SP>-<SP>REMOVED');
        if (code !==1) {
            return false;
        }
        return EANFCheck(1);
    }
    
    // If REMOVED is loaded, we will check if there is an REMOVED link.
    function doesREMOVEDExist() {
        iimDisplay('Checking if an REMOVED link is on page.');
        var link = iimPlay('CODE: SET !TIMEOUT_TAG 1\n'
            + 'TAG POS=1 TYPE=A ATTR=TXT:REMOVED');
        if (link !==1) {
            return false;
        }
        return EANFCheck(2);
    }
    
    // We will check if the REMOVED was already REMOVEDed.
    function checkREMOVED() {
        iimDisplay('Checking if REMOVED if valid.');
        var link = iimPlay('CODE: SET !TIMEOUT_TAG 1\n'
            + 'TAG POS=1 TYPE=DIV ATTR=TXT:An<SP>error<SP>occurred:');
        if (link !==1) {
            return false;
        }
        return EANFCheck(2);
    }
    
    // Checks if the REMOVED link was real by checking if there is a REMOVED button.
    function checkTroll() {
        iimDisplay('Checking if an REMOVED is on page');
        var link = iimPlay('CODE: SET !TIMEOUT_TAG 1\n'
                        + 'TAG POS=1 TYPE=BUTTON ATTR=TXT:REMOVED\n');
        if (link !==1) {
            return false;
        }
        return EANFCheck(2);
    }
    
    //Checks whatever all these variables mean
    function EANFCheck(lastExtract){
        var extract = iimGetLastExtract(lastExtract);
        return extract === '#EANF#' ? false : true;
    }
    
    run(); // Runs REMOVED
    
    /*-------------------- END CODE ---------------------------- */   
    

I'm sure there's optimizations that could be made to how your nested conditionals are set up, but the code is so obfuscated, it's really hard to tell.

\$\endgroup\$
2
  • \$\begingroup\$ YES! thank you very much. I wouldn't mind sharing with you the uncensored code :3 \$\endgroup\$ Aug 12, 2014 at 4:26
  • \$\begingroup\$ :( it seems there is no private message system here? \$\endgroup\$ Aug 12, 2014 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.