Guest User

Untitled

a guest
Mar 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. function sleep(waitMsec) {
  2.  
  3. var startMsec = new Date();
  4.  
  5. // 指定ミリ秒間、空ループ。CPUは常にビジー。
  6. while (new Date() - startMsec < waitMsec);
  7.  
  8. }
  9.  
  10. function asyncLoop(iterations, func, callback) {
  11. var index = 0;
  12. var done = false;
  13. var loop = {
  14. next: function() {
  15. if (done) {
  16. return;
  17. }
  18.  
  19. if (index < iterations) {
  20. index++;
  21. func(loop);
  22.  
  23. } else {
  24. done = true;
  25. callback();
  26. }
  27. },
  28.  
  29. iteration: function() {
  30. return index - 1;
  31. },
  32.  
  33. break: function() {
  34. done = true;
  35. callback();
  36. }
  37. };
  38. loop.next();
  39. return loop;
  40. }
  41.  
  42. asyncLoop(1000, function(loop) {
  43. console.log(loop.iteration());
  44. $(".JudgementButtonsUnderCardButton.-like").click();
  45. sleep(1000);
  46. loop.next();
  47. },
  48. function(){console.log('done')}
  49. );
Add Comment
Please, Sign In to add comment