function $(s) { return document.querySelectorAll(s); } function $$(s) { return document.querySelector(s); } function pause(msec) { var date = new Date(); while (new Date() - date < msec) continue; } var max = 400; var forms = $('form[name=cancel]'); var i, f, id, http, url, params, total; total = 0; for (i = 0; i < forms.length - 1 && i < max; ++i) { ++total; f = forms[i]; id = f.querySelector('input[name=id]'); http = new XMLHttpRequest(); http.onreadystatechange = function(state) { if (this.readyState == 4) { if (--total <= 0) window.location.reload(); console.log('finished one', this.status); } }; url = document.URL + '/cancelbuild'; params = 'id=' + id.value; http.open('POST', url, true); console.log('hitting url', url, params); http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); http.send(params); pause(5); } console.log('spawned ' + total); if (total != forms.length) { console.log('total available: ' + forms.length); } //i = 5 * forms.length; //console.log('waiting', i, 'msecs'); //pause(i); //window.location.reload();