]> git.wh0rd.org - chrome-ext/waterfall-buildbot-clicker.git/blob - click_all.js
initial code
[chrome-ext/waterfall-buildbot-clicker.git] / click_all.js
1 function $(s) { return document.querySelectorAll(s); }
2 function $$(s) { return document.querySelector(s); }
3
4 function pause(msec) {
5 var date = new Date();
6 while (new Date() - date < msec)
7 continue;
8 }
9
10 var max = 400;
11
12 var forms = $('form[name=cancel]');
13 var i, f, id, http, url, params, total;
14 total = 0;
15 for (i = 0; i < forms.length - 1 && i < max; ++i) {
16 ++total;
17
18 f = forms[i];
19 id = f.querySelector('input[name=id]');
20
21 http = new XMLHttpRequest();
22 http.onreadystatechange = function(state) {
23 if (this.readyState == 4) {
24 if (--total <= 0)
25 window.location.reload();
26 console.log('finished one', this.status);
27 }
28 };
29
30 url = document.URL + '/cancelbuild';
31 params = 'id=' + id.value;
32 http.open('POST', url, true);
33 console.log('hitting url', url, params);
34
35 http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
36 http.send(params);
37 pause(5);
38 }
39 console.log('spawned ' + total);
40 if (total != forms.length) {
41 console.log('total available: ' + forms.length);
42 }
43
44 //i = 5 * forms.length;
45 //console.log('waiting', i, 'msecs');
46 //pause(i);
47 //window.location.reload();