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 ---------------------------- */