-
Notifications
You must be signed in to change notification settings - Fork 2
/
Deriv AutoClicker.user.js
224 lines (193 loc) · 8.45 KB
/
Deriv AutoClicker.user.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// ==UserScript==
// @name Deriv AutoClicker
// @namespace Deriv_AutoClicker_Script
// @version 0.3
// @description Click on Purchase when matching conditions
// @author Kowshika
// @match https://smarttrader.deriv.app/en/trading.html
// @match https://smarttrader.deriv.app/en/trading.html*
// @include https://smarttrader.deriv.app/en/trading.html*
// @match https://smarttrader.deriv.*/en/trading.html
// @include https://smarttrader.deriv.*/en/trading.html*
// excludes *
// @icon https://smarttrader.deriv.app/images/common/logos/icon_deriv.svg
// @grant GM_addStyle
// @grant GM_getValue
// @grant GM_setValue
// @license MIT
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @run-at document-end
// ==/UserScript==
function has(String, search) { try { if (String.indexOf(search) > -1) { return true; } } catch (err) {} return false; }
function sleep(ms) { return new Promise(res => setTimeout(res, ms)); };
let sleepFunc = async function() { await sleep(5000); };
function waitForKeyElements(selectorTxt, actionFunction, bWaitOnce, iframeSelector) {
var targetNodes, btargetsFound;
if (typeof iframeSelector == "undefined")
targetNodes = $(selectorTxt);
else
targetNodes = $(iframeSelector).contents()
.find(selectorTxt);
if (targetNodes && targetNodes.length > 0) {
btargetsFound = true;
/*--- Found target node(s). Go through each and act if they
are new.
*/
targetNodes.each(function () {
var jThis = $(this);
var alreadyFound = jThis.data('alreadyFound') || false;
if (!alreadyFound) {
//--- Call the payload function.
var cancelFound = actionFunction(jThis);
if (cancelFound)
btargetsFound = false;
else
jThis.data('alreadyFound', true);
}
});
}
else {
btargetsFound = false;
}
//--- Get the timer-control variable for this selector.
var controlObj = waitForKeyElements.controlObj || {};
var controlKey = selectorTxt.replace(/[^\w]/g, "_");
var timeControl = controlObj[controlKey];
//--- Now set or clear the timer as appropriate.
if (btargetsFound && bWaitOnce && timeControl) {
//--- The only condition where we need to clear the timer.
clearInterval(timeControl);
delete controlObj[controlKey]
}
else {
//--- Set a timer, if needed.
if (!timeControl) {
timeControl = setInterval(function () {
waitForKeyElements(selectorTxt, actionFunction, bWaitOnce, iframeSelector);
}, 300);
controlObj[controlKey] = timeControl;
}
}
waitForKeyElements.controlObj = controlObj;
}
function mainMethod(jNode) {
setTimeout(function () {
sleepFunc();
console.clear();
console.log('Page loaded');
document.getElementByXPath = function(sValue) { var a = this.evaluate(sValue, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); if (a.snapshotLength > 0) { return a.snapshotItem(0); } };
if (document.getElementByXPath("//*[@id='underlying_component']//div/span[text()='Volatility 100 Index']") == null){
document.getElementByXPath("//*[@id='underlying_component']//div[contains(@class, 'market_current')]").click();
document.getElementByXPath("//*[@id='R_100']").click();
console.log("Selected Volatility 100 Index");
}
if (document.getElementByXPath("//*[@id='contract_component']//div/span[text()='Higher/Lower']") == null){
document.getElementByXPath("//*[@id='contract_component']//div[contains(@class, 'contract_current')]").click();
document.getElementByXPath("//*[@id='contract_component']//div[text()='Higher/Lower']").click();
console.log("Selected Higher/Lower");
}
sleepFunc();
waitForKeyElements("#spot", checkChart);
}, 5000)
}
function checkChart(jNode){
var match_digits = 4;
var time = 1;
var max = 2000000;
console.clear();
var error = false;
var matchedList = GM_getValue("matchList", "");
if (!matchedList) {
console.log("Error calculating matchList from memory. Auto Clicker Script Not Running.");
alert("Auto Clicker Script Not Running. Click on Set Match List button.");
error = true;
} else {
var matchList = matchedList.split(",").map(item => item.trim());
console.log(matchList);
if (matchList.length == 1 ){
if (matchList[0].length <= 0){
console.log("Error calculating matchList from memory. Auto Clicker Script Not Running.");
alert("Auto Clicker Script Not Running. Click on Set Match List button.");
error = true;
}
}
var interval = setInterval(function() {
if (!error && matchList && time <= max) {
var spot = document.getElementById('spot');
if (spot != null && spot.getAttribute('class')=='price_moved_up'){
var amount = spot.textContent;
var matched_digits = amount.substr(amount.length - match_digits);
if (matchList.includes(matched_digits)){
if (document.getElementByXPath("//div[contains(@class, 'contract_purchase') and contains(@class, 'disabled')]") == null
&& document.getElementById('spot').getAttribute('class')=='price_moved_up'){
clickHigherPurchaseBtn();
console.log("Blue : " + matched_digits + " from " + amount + " matched with list " + matchList);
sleepFunc();
clickcloseBtn();
sleepFunc();
}
} else {
console.log("Blue : but " + matched_digits + " did not match with list " + matchList);
}
clickcloseBtn();
} else {
clickcloseBtn();
}
time++;
} else { clearInterval(interval); }
}, 1000);
}
}
function clickcloseBtn() {
try{
if (document.getElementByXPath("//*[@id='contract_confirmation_container' and contains(@style, 'none')]") == null){
document.getElementById('contract_confirmation_container').click();
document.getElementById('close_confirmation_container').click();
}
} catch(err) {}
}
function clickHigherPurchaseBtn(){
try{
document.getElementById('purchase_button_top').click();
} catch(err) {}
}
function ButtonClickAction(zEvent) {
GM_setValue("matchList", "");
var matchList = prompt('To update your matching numbers list, enter last 3 digits comma separated. For example 2.40,2.80,1.02,8.40 etc...', '');
if (matchList) {
GM_setValue("matchList", matchList);
console.log("Stored matchList : " + matchList);
GM_setValue("UserCancelledPrompt", false);
// reload
self.location.assign(location);
}
else {
GM_setValue("UserCancelledPrompt", true);
console.log("User Cancelled prompt to update matchList.");
}
}
function AddButton() {
// Add a button element on div
var zNode = document.createElement('div');
zNode.innerHTML = '<button id="myButton" title="To update your stored matching numbers list, Click me" type="button">Set Higher Match List</button>';
zNode.setAttribute('id', 'myContainer');
document.body.appendChild(zNode);
//--- Activate the newly added button.
document.getElementById("myButton").addEventListener("click", ButtonClickAction, false);
//--- Style our newly added element using CSS.
GM_addStyle(`
#myContainer{position:fixed;bottom:30px;left:0;font-size:10px;margin:0;opacity:.75}#myButton{cursor:pointer;background-color:lightgrey;color:black}
#myButton:hover{background-color:#555;color:white;box-shadow:0 2px 6px 0 rgba(0,0,0,.24),0 5px 10px 0 rgba(0,0,0,.19);opacity:1}
`);
}
(async function() {
sleepFunc();
document.onreadystatechange = function () {
if (document.readyState == "complete") {
sleepFunc();
AddButton();
console.clear();
waitForKeyElements("span.market", mainMethod);
};
}
})();