-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patham4.js
245 lines (205 loc) · 8.87 KB
/
am4.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// ==UserScript==
// @name AM4 bot
// @namespace http://tampermonkey.net/
// @version 0.6
// @description automate depart for flights, better auto-price for new routes, automatic low price fuel and CO2 buying, start eco-friendly campaign before departing
// @author LouisJ
// @match https://www.airlinemanager.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_log
// ==/UserScript==
// noinspection JSUnresolvedFunction
// Set the price thresholds under which we buy fuel and CO2
let fuelPriceThreshold = 550;
let co2PriceThreshold = 125;
var autoDepartTimeoutID;
var autoBuyerTimeoutID;
// start function
(function () {
'use strict';
setTimeout(injectToggle, 2000);
betterAutoPrice();
})();
// Toggle buttons
function injectToggle() {
// Auto-depart checkbox
let departCheckboxText = "<li class=\"nav-item text-white text-center\"><span class=\"xs-text text-grayed exo\">Auto-Depart</span><br><input type=\"checkbox\" id='autoDepartCheckbox'></li>";
document.getElementsByClassName("navbar-nav")[0].children[1].insertAdjacentHTML('afterend', departCheckboxText);
document.getElementById("autoDepartCheckbox").addEventListener("change", toggleAutoDepart);
// Auto-buy fuel checkbox
let buyerCheckboxText = "<li class=\"nav-item text-white text-center\"><span class=\"xs-text text-grayed exo\">Auto-buy fuel and CO2</span><br><input type=\"checkbox\" id='autoBuyerCheckbox'></li>";
document.getElementById("autoDepartCheckbox").parentElement.insertAdjacentHTML('afterend', buyerCheckboxText);
document.getElementById("autoBuyerCheckbox").addEventListener("change", toggleAutoBuyer);
}
function toggleAutoDepart() {
if (document.getElementById("autoDepartCheckbox").checked) {
autoDepartTimeoutID = setTimeout(autoDepartRoutine, 500);
} else {
clearTimeout(autoDepartTimeoutID);
}
}
function toggleAutoBuyer() {
if (document.getElementById("autoBuyerCheckbox").checked) {
autoBuyerTimeoutID = setTimeout(scanConsumable, 500);
} else {
clearTimeout(autoBuyerTimeoutID);
}
}
// Auto-depart
function autoDepartRoutine() {
// Trying to avoid detection
// 4.5-5.5 minutes interval between each check
const min = 270000;
const max = 330000;
const randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
GM_log("Next check in " + Math.floor(randomNum / 60000) + " minutes and " + (randomNum % 60000) / 1000 + " seconds.");
autoDepartTimeoutID = setTimeout(autoDepartRoutine, randomNum);
departAll()
}
function departAll() {
const numberSpan = document.getElementById("listDepartAmount");
GM_log(numberSpan.innerText + " flight(s) to depart.");
if (numberSpan.innerText !== "0") {
// before departing, start eco-friendly campaign
// No better way to do it, since countdown is not visible by default
startEcoCampaign();
// slight delay to give time for eco-friendly campaign to start
setTimeout(function () {
const departButton = numberSpan.parentElement;
if (departButton) {
departButton.click();
}
}, 1000);
}
}
function startEcoCampaign() {
// Create a new XMLHttpRequest object
const xhttp = new XMLHttpRequest();
// Define the callback function that will be executed when the request completes
xhttp.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
// Do something with the response
GM_log("Eco-friendly campaign call : " + this.responseText);
}
};
// Open the connection to the server and send the request
xhttp.open("GET", "marketing_new.php?type=5&mode=do&c=1", true);
xhttp.send();
}
// Better auto-price
function betterAutoPrice() {
const observer = new MutationObserver(
() => {
const autoPriceButton = document.getElementById('introAuto');
if (autoPriceButton) {
const line = autoPriceButton.getAttribute('onclick');
const values = line.slice(line.indexOf('(') + 1, line.indexOf(')')).split(',');
const priceValues = values.slice(0, 4);
GM_log(priceValues);
autoPrice(Math.floor(priceValues[0] * 1.1) - 10, Math.floor(priceValues[1] * 1.08) - 10, Math.floor(priceValues[2] * 1.06) - 10, priceValues[3]);
observer.disconnect();
setTimeout(betterAutoPrice, 5000);
}
});
// watch the new routes window
const targetNode = document.getElementById('newRouteInfo');
const config = {attributes: true, childList: true, subtree: true};
observer.observe(targetNode, config);
}
function getBankBalance() {
// Get the top left element with the bank balance
const bankBalance = document.getElementById("headerAccount");
const intBankBalance = parseInt(bankBalance.innerText.replace(/[^0-9]/g, ""));
GM_log("Bank balance: " + intBankBalance);
return intBankBalance;
}
// Fuel and CO2 auto-buy
function scanConsumable() {
// open the fuel window
popup('fuel.php', 'Fuel', false, false, true);
// wait for the window to load, then do the fuel routine
setTimeout(function () {
// get the main element
const element = document.getElementById("fuelMain");
// Get the price text
const price = element.children[0].children[0].children[2].children[0].innerText;
// Transform the price into an integer
const intPrice = parseInt(price.replace(/[^0-9]/g, ""));
// if the price is lower than 550, buy fuel
if (intPrice <= fuelPriceThreshold) {
GM_log("Fuel price is low: " + intPrice);
// Get the capacity text
const capacity = element.children[0].children[2].children[2].innerText;
// transform the capacity into an integer
const intCapacity = parseInt(capacity.replace(/[^0-9]/g, ""));
// Get the bank balance
const intBankBalance = getBankBalance();
// Calculate the amount of fuel buyable
const intBuyable = Math.floor(intBankBalance / intPrice * 1000);
// Buy the minimum between the amount of fuel buyable and the capacity
const intBuy = Math.min(intBuyable, intCapacity);
GM_log("Buying " + intBuy + " fuel");
buyFuel(intBuy);
}
}, 500);
// do the CO2 routine
setTimeout(function () {
// click on the CO2 window button
document.getElementById("popBtn2").click();
// wait for the window to load, then do the CO2 routine
setTimeout(function () {
// get the main element
const element = document.getElementById("co2Main");
// Get the price text
const price = element.children[0].children[1].children[2].children[0].innerText;
// Transform the price into an integer
const intPrice = parseInt(price.replace(/[^0-9]/g, ""));
// if the price is lower than 120, buy CO2
if (intPrice <= co2PriceThreshold) {
// Get the capacity text, transform it into an integer
const capacity = element.children[0].children[3].children[2].innerText;
const intCapacity = parseInt(capacity.replace(/[^0-9]/g, ""));
// get the bank balance
const intBankBalance = getBankBalance();
// calculate the amount of CO2 buyable
const intBuyable = Math.floor(intBankBalance / intPrice * 1000);
// buy the minimum between the buyable amount and the capacity
const intBuy = Math.min(intBuyable, intCapacity);
GM_log("Buying " + intBuy + " CO2");
buyCO2(intBuy);
}
setTimeout(function () {
// close the window
closePop();
GM_log("Consumable scan done");
}, 1000);
// Wait 30 mins before scanning again
const time = 30 * 60 * 1000;
autoBuyerTimeoutID = setTimeout(scanConsumable, time)
}, 500);
}, 2000);
}
function buyFuel(intAmount) {
const url = 'fuel.php?mode=do&amount=' + encodeURIComponent(intAmount);
call(url);
}
function buyCO2(intAmount) {
const url = 'co2.php?mode=do&amount=' + encodeURIComponent(intAmount);
call(url)
}
function call(url) {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
const response = xhr.responseText;
// Do something with the response
GM_log('Response:', response);
} else {
GM_log('AJAX request failed:', xhr.status);
}
}
};
xhr.open('GET', url, true);
xhr.send();
}