There is a website where you can get statistics on sites. On the website the input in which you want to insert data

<input name="url"> 

Input in the button

 <input name="proceed"> 

Text:

 <b style="color:red"> 

I do this through tampermonkey. I do this:

 var jq = document.createElement('script'); jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"; document.getElementsByTagName('head')[0].appendChild(jq); jq.addEventListener('load',function () { var result = []; var websiteName = $('input[name=url]').val(); var styleRedEl = $('b[style*="color:red"]').text(); result[websiteName]=styleRedEl; console.log ( result ); var websitesArr = [ "ya.ru", "google.com", "ok.ru", "vk.com", "fb.com" ]; var inputVal = $('input[name=url]').val(); for (i=0; i<websitesArr.length; i++) { $('input[name=url]').val(websitesArr[i]); alert (websitesArr[i]); $('input[name=proceed]').trigger('click'); } }); 

How to solve the problem that the page is updated only after the cycle has passed through all the elements of the array and in turn has inserted them into the form and only after that presses the button. It is necessary that the button is pressed immediately after inserting each element of the array into the input.

  • one
    First, what is this button in the form of a text field? Secondly, why do you think that the button is pressed once? Give evidence. I am sure that the click occurs as you have and is indicated in the code - 5 times, at each iteration of the cycle. - Ivan Pshenitsyn
  • @IvanPshenitsyn 1) the question is how the button is framed not to me. I repeat - I work with someone else's site. My experience allows me to make a button from input, a, span, button, p and, in principle, any tag 2) the evidence is simple. if you remove the alert in the 4th line from the end of the code, then the result for fb.com , that is, the last element of the array, is simply shown; if you leave the alert, then the value is inserted from the array into the input, an alert is output with this element, then the next element is inserted from the array An alert is output to the input with the next element of the array, etc., and only at the end is the page updated - angelzzz
  • @IvanPshenitsyn and the simplest - I can tell whether the page has reloaded or not)) - angelzzz
  • Not understood. If when you click a button, the form is sent and the page is updated, then what do you want from 5 button presses? Five page updates?) The most obvious answer is that you press the button five times, as planned. But you have to understand that the js code is still running after the button is pressed and until the page reloads. He is with you and executed. And presses the button several times in a row. Hang up the listener $ ('form'). On ('submit', function () {console.log ('whatever')}) and I’m sure you’ll make sure that it is. - Ivan Pshenitsyn
  • @IvanPshenitsyn I want 5 page taps. I want that after the first update of the page I could read the obtained values, then press the button again and read the result again after updating the page and so 5 times - angelzzz

0