Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function infinite loop and ignoring parts of other functions

Okay, so basically all I wrote this script to do is clear and click a button if the textbox is full and refresh the page if its not.

I can successfully clear the text box when its full and refresh the page when its not, but as soon as I try to use my clickButton function it kicks into an infinite loop and skips the if() in clrLog

function addFunction(func, exec) {
  var script = document.createElement('script');
  script.textContent = '-' + func + (exec ? '()' : '');
  document.body.appendChild(script);
  document.body.removeChild(script);
}
function clickButton(val) {
  buttons = document.getElementsByTagName('INPUT');
  for (var i = 0; i < buttons.length; i++)
  {
    if (buttons[i].type == 'submit' && buttons[i].value == val)
    {
      buttons[i].click();
    }
  }
}
function clrLog() {
  var elements = [
  ];
  elements = document.getElementsByClassName('logarea');
  if (elements.log.value === '')
  setTimeout(function () {
    location.reload();
  }, 5000);
  for (var i = 0; i < elements.length; i++) {
    elements[i].value = '';
  }
  clickButton('Edit log file');
}
function main() {
  addFunction(clrLog(), true);
}
main();
like image 574
m44m31 Avatar asked Dec 14 '25 02:12

m44m31


1 Answers

I found out that I could avoid using a for loop by using document.querySelector(); instead - so much easier :)

like image 114
m44m31 Avatar answered Dec 15 '25 23:12

m44m31



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!