Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   перебор- перезагрузка и еще раз перебор (https://javascript.ru/forum/dom-window/73698-perebor-perezagruzka-i-eshhe-raz-perebor.html)

dantist433 08.05.2018 09:30

перебор- перезагрузка и еще раз перебор
 
Добрый день, не судите строго, я новичок, может еще что то не понимаю.

есть скрипт рабочий
Код:

var pCounter = 0;
  $('.icon_a').each(function(idx,el){
    timerId = setTimeout(function(){$(el).click();}, pCounter*332 + Math.floor(Math.random()*120)) ; pCounter++;
                                          }
                        );

Смысл этого скрипта - пройти по всем icon_a и нажать их.

необходимо после прохождения - перезагрузить страницу и пройти еще раз их(например через минуту).
Делал через
setTimeout(
		 function() {
			 location.reload();
        }, 60000
		);


однако если много icon_a то он перезагружается до прохождения всех значений, а после перезагрузки не запускается снова

P.s. может быть не в ту ветку написал, не судите строго

Malleys 08.05.2018 10:01

<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>document</title>
</head>
<body>
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<script>

	function delay(ms) {
		return new Promise(resolve => {
			setTimeout(resolve, ms);
		});
	}

	(async function() {
		let pCounter = 0;
		for(let el of document.querySelectorAll(".icon_a")) {
			await delay(pCounter * 332 + Math.floor(Math.random() * 120));
			el.click();
		}

		//delay(60000); // раскомментируйте если надо подождать минуту
		location.reload();
	})();

	</script>
</body>
</html>


Конечно вместо checkbox может быть всё, по чему можно кликнуть...

dantist433 08.05.2018 10:22

благодарю

рони 08.05.2018 11:18

dantist433,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

  <script>
$(function() {
  var pCounter = 0;
  $(".icon_a").each(function(idx, el) {
    pCounter = idx;
    setTimeout(function() {
      $(el).click();
      !--pCounter && location.reload();
    }, pCounter * 332 + Math.floor(Math.random() * 120));
  });
});
  </script>
</head>

<body>
    <input type="checkbox" class="icon_a">
    <input type="checkbox" class="icon_a">
    <input type="checkbox" class="icon_a">
    <input type="checkbox" class="icon_a">
    <input type="checkbox" class="icon_a">
    <input type="checkbox" class="icon_a">
    <input type="checkbox" class="icon_a">
    <input type="checkbox" class="icon_a">
    <input type="checkbox" class="icon_a">
    <input type="checkbox" class="icon_a">
</body>
</html>

Dilettante_Pro 08.05.2018 11:58

без async/await
<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>document</title>
</head>
<body>
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<script>
                var elems = document.querySelectorAll(".icon_a"), i = 0;
                (function loop() {
                       setTimeout(function() {
                             elems[i].click();
                             if(i == elems.length -1) location.reload();
                             i++;
                             loop();
                        }, 333);
		})();
	</script>
</body>
</html>

j0hnik 08.05.2018 16:49

<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>document</title>
</head>
<body>
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<input type="checkbox" class="icon_a">
	<script>
		var elems = document.querySelectorAll(".icon_a")
		 elems.forEach((el,i)=>{
			el.click();
			if(i == elems.length-1) setTimeout(()=>location.reload(),6000);
		});
	</script>
</body>
</html>


Часовой пояс GMT +3, время: 10:01.