superbiche of Les enculeys
2/22/2017 - 3:53 PM

Trigger click on all buttons in a page.

Trigger click on all buttons in a page.

(function() {
  var jq = document.createElement('script');
  jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js";
  document.getElementsByTagName('head')[0].appendChild(jq);

  window.setTimeout(function() {
    jQuery.noConflict();
  }, 5000);
})();

(function($) {
  setTimeout(function() {
    var selector = '.sc-button-download';
    btns = $(selector);


    // all at once 

    btns.each(function(i, el) {
      $(el).trigger('click');
    });

  }, 8000);
})(jQuery);

/////////////

(function() {
  var jq = document.createElement('script');
  jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js";
  document.getElementsByTagName('head')[0].appendChild(jq);

  window.setTimeout(function() {
    jQuery.noConflict();
    (function($) {
      setTimeout(function() {
        // or with interval
        var selector = '.sc-button-download';
        btns = $(selector);
        var i = 0;
        var interval = 5000;

        var loop = setInterval(function() {
          if (i < btns.length + 1) {
            jQuery(btns[i]).trigger('click');
            i++;
          } else {
            clearInterval(loop);
          }

        }, interval);
      }, 8000);

    })(jQuery);
  }, 5000);
})();