-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
205 lines (157 loc) · 5.53 KB
/
content.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//----------------------------------------> Global Variables <--------------------------------------------
var nodes = document.getElementById("trade").childNodes[1].firstChild.getElementsByTagName("tr");
var endIndex = parseInt(document.getElementById("d08").textContent.toString().replace(",",""));
var maxAllowablePrice = parseInt(document.getElementById("d13").textContent.toString().replace(",",""));
var minAllowableprice = parseInt(document.getElementById("d14").textContent.toString().replace(",",""));
var firstIndexOLS = 0;
var lastIndexOLS = 0;
var lastIndexOfFirstSecond = 0;
var totalAcceptedVolume = 0;
var numberOfAcceptVolumes = 0;
var totalNumbers = endIndex;
var moreThanX = 0;
var xBound = 0;
var volRatio = 0;
//-------------------------------------------> Functions <----------------------------------------------
//Sort Time Column
function sortTime()
{
var trade = document.getElementById("trade");
trade = trade.childNodes[0].childNodes[1].firstChild.lastChild.childNodes[1].firstChild;
trade.click();
console.log("Time Has Been Sorted");
}
//Changing Style of Nodes
function ChangeStyle(index)
{
nodes[index].childNodes[0].style.backgroundColor = "red";
nodes[index].childNodes[1].style.backgroundColor = "red";
nodes[index].childNodes[2].style.backgroundColor = "red";
nodes[index].childNodes[3].style.backgroundColor = "red";
}
//First Second Trade
function fitstTimeTrade()
{
var firstSecond = nodes[1].childNodes[1].textContent.toString();
for(var i = 1; i <= endIndex; i++)
{
var volume = parseInt(nodes[i].childNodes[2].textContent.toString());
var price = parseInt(nodes[i].childNodes[3].textContent.toString());
if(nodes[i].childNodes[1].textContent.toString() != firstSecond)
{
firstIndexOLS = 1;
lastIndexOLS = i-1;
lastIndexOfFirstSecond = i-1;
break;
}
else if(volume*price >= 500000000)
{
ChangeStyle(i);
totalAcceptedVolume += volume;
numberOfAcceptVolumes++;
if(volume > xBound)
moreThanX++;
}
}
}
function FullTrade()
{
var tmpFirstIndexOLS = firstIndexOLS;
var tmpLastIndexOLS = lastIndexOLS;
for(var i = lastIndexOfFirstSecond+1; i <= endIndex; i++)
{
if(nodes[i].childNodes[1].textContent.toString() != nodes[i-1].childNodes[1].textContent.toString())
{
firstIndexOLS = tmpFirstIndexOLS;
lastIndexOLS = tmpLastIndexOLS;
}
var volume = parseInt(nodes[i].childNodes[2].textContent.toString());
var price = parseInt(nodes[i].childNodes[3].textContent.toString());
if(nodes[i].childNodes[1].textContent.toString() != nodes[i-1].childNodes[1].textContent.toString())
tmpFirstIndexOLS = i;
if(i == endIndex|| nodes[i].childNodes[1].textContent.toString() != nodes[i+1].childNodes[1].textContent.toString())
tmpLastIndexOLS = i;
if(price*volume >= 500000000)
{
if(price == maxAllowablePrice || price == minAllowableprice)
{
ChangeStyle(i);
totalAcceptedVolume += volume;
numberOfAcceptVolumes++;
if(volume > xBound)
moreThanX++;
}
else
{
var flag = false;
for(var j = lastIndexOLS; j >= firstIndexOLS; j--)
{
var prevPrice = parseInt(nodes[j].childNodes[3].textContent.toString());
if(price > prevPrice)
{
ChangeStyle(i);
totalAcceptedVolume += volume;
numberOfAcceptVolumes++;
if(volume > xBound)
moreThanX++;
flag = true;
break;
}
}
if(!flag)
{
for(var j = i-1; j > lastIndexOLS; j--)
{
var prevPrice = parseInt(nodes[j].childNodes[3].textContent.toString());
if(price > prevPrice)
{
ChangeStyle(i);
totalAcceptedVolume += volume;
numberOfAcceptVolumes++;
if(volume > xBound)
moreThanX++;
break;
}
}
}
}
}
}
}
//Send Message
function sendMessage()
{
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
if(request.from == "popup" && request.subject == "sendData")
{
var msg = {
totalAcceptedVolume : totalAcceptedVolume,
volRatio : volRatio,
xBound : xBound
};
sendResponse(msg);
}
});
console.log("All of Messages Have Been Sent");
}
function VolumeBound()
{
var cost = 500000000;
var minPermittedPrice = parseInt(document.getElementById("d14").textContent.toString().replace(",",""));
xBound = cost/minPermittedPrice;
}
function VolumeRatio()
{
volRatio = (moreThanX*100)/numberOfAcceptVolumes;
}
function Main()
{
VolumeBound();
//This Function Sort Time for another functions
sortTime();
fitstTimeTrade();
FullTrade();
VolumeRatio();
sendMessage();
}
Main();