-
Notifications
You must be signed in to change notification settings - Fork 1
/
businessonline-downloader.js
97 lines (85 loc) · 3.54 KB
/
businessonline-downloader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// ==UserScript==
// @name Businessonline Downloader
// @namespace Downloaders
// @include https://businessonline.ge/Pages/Transactions/View/NationalTransferOut.aspx
// @require https://raw.githubusercontent.com/cowboy/jquery-throttle-debounce/v1.1/jquery.ba-throttle-debounce.js
// @version 1
// @grant none
// ==/UserScript==
(function() {
// we must assign json to this variable. The json data that should be downloaded by the script.
var infoArray = [];
var i = -1;
var timeout;
var buttonClicked = false;
var listItemsCheckboxWasClicked = false;
var searchButtonId = '#ContentPlaceHolderMain_AboveList_Filter_ButtonFilter';
var listItemsCheckboxHolderId = '#ContentPlaceHolderMain_RepeaterList_CheckAll';
var downloadLinkHolderId = '#ContentPlaceHolderMain_LinkButtonPrintBottom';
window.addEventListener('load', function() {
$(searchButtonId).live('click', function(e) {
buttonClicked = true;
});
$(listItemsCheckboxHolderId).live('change', function(e) {
listItemsCheckboxWasClicked = true;
});
document.addEventListener('xhrResponse', function(r) {
combinedExecution();
}, false);
nextItemDownload();
}, false);
function nextItemDownload() {
i++;
if (i < infoArray.length) {
setParams(infoArray[i]);
$(searchButtonId).get(0).click();
console.log('Iteration: ', i);
} else {
$(searchButtonId).die();
$(listItemsCheckboxHolderId).die();
$(downloadLinkHolderId).die();
console.log('Done');
}
}
function combinedExecution() {
if (buttonClicked) {
buttonWasClickedAndResponseReturned();
buttonClicked = false;
} else if (listItemsCheckboxWasClicked) {
listItemsCheckboxWasClickedAndResponseReturned();
listItemsCheckboxWasClicked = false;
} else {
console.error('misfire!');
}
}
function buttonWasClickedAndResponseReturned() {
if ($('#ContentPlaceHolderMain_RepeaterList_CheckAll').get(0) != undefined) {
console.log('downloading: ', infoArray[i].accountNumber);
$(listItemsCheckboxHolderId).get(0).click();
} else {
console.log('can not download: ' + infoArray[i].accountNumber + " skip!");
timeout = setTimeout(nextItemDownload, 10);
}
}
function listItemsCheckboxWasClickedAndResponseReturned() {
$(downloadLinkHolderId).get(0).click();
timeout = setTimeout(nextItemDownload, 10);
}
function setParams(inf) {
document.getElementById('ContentPlaceHolderMain_AboveList_Filter_TextBoxBenefAccount').value = inf.accountNumber;
document.getElementsByName('ctl00$ctl00$ContentPlaceHolderMain$AboveList$Filter$DropDownListSenderAccount')[0].value = '${SENDER_ACCOUT_ID}';
document.getElementById('ContentPlaceHolderMain_AboveList_Filter_TextBoxDateFrom').value = inf.dateFrom;
document.getElementById('ContentPlaceHolderMain_AboveList_Filter_TextBoxDateTo').value = inf.dateTo;
}
var origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
var response = this;
response.addEventListener('load', function() {
var event = new CustomEvent('xhrResponse', {
'response': response
});
document.dispatchEvent(event);
});
origOpen.apply(this, arguments);
};
})();