-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHEUpgrade31.user.js
123 lines (111 loc) · 3.61 KB
/
HEUpgrade31.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
// ==UserScript==
// @name HEUpgrade v3.1
// @namespace http://tampermonkey.net/
// @version 3.1
// @description Upgrade remaining CPUs and HDDs to max
// @author Emin Afroz (Omega on HackerExperience)
// @include https://*.hackerexperience.com/hardware
// @include https://*.hackerexperience.com/hardware?opt=upgrade
// @include https://*.hackerexperience.com/hardware?opt=xhd
// @include https://*.hackerexperience.com/internet?view=clan
// @require https://code.jquery.com/jquery-3.2.1.min.js
// @icon http://www.icon100.com/up/3294/256/panda_08.png
// ==/UserScript==
var account = 'ACCNUMBER';
var totalServers = $(".widget-content.padding > ul > a").length;
var index = 0;
var times;
var interval;
var clan;
$(document).ready(function() {
clan = window.location.href.includes("clan");
account = account.replace("#","");
$('.label.label-info').html("Starting...");
times = prompt("How many servers to upgrade? Leave negative value for all.",-1);
if(times !== null && times !== 0)
interval = setInterval(upgrade,2000);
else
$('.label.label-info').html("Have a nice day. ^^");
});
function upgrade(){
if(times === 0 || index == totalServers)
{
clearInterval(interval);
$('.label.label-info').html("Done :)");
return;
}
else
$('.label.label-info').html("Completed: " + index + "/" + totalServers);
var server = $(".widget-content.padding > ul > a").eq(index);
cpuUnit = server.find(".list-user > small").eq(0).text();
hddUnit = server.find(".list-user > small").eq(1).text();
while(cpuUnit == "4 GHz" && hddUnit == "10 GB")
{
index++;
server = $(".widget-content.padding > ul > a").eq(index);
cpuUnit = server.find(".list-user > small").eq(0).text();
hddUnit = server.find(".list-user > small").eq(1).text();
}
serverID = server.attr('href').replace("?opt=upgrade&id=","").replace("hardware","");
if(cpuUnit != "4 GHz")
getData(serverID,true);
if(hddUnit != "10 GB")
getData(serverID,false);
index++;
times--;
}
//getData(link,true);
function getData(id,isCPU){
var tempUrl;
if(clan)
tempUrl = "/internet?view=clan&action=upgrade&server=" + id;
else
tempUrl = "/hardware?opt=upgrade&id=" + id;
$.ajax({
type: 'GET',
async: false,
url: tempUrl,
success: function() {
if(isCPU)
postData('cpu',5000,8);
else
postData('hdd',8000,6);
}
});
}
//postData('cpu', 5000, 8);
function postData(itemToBuy, itemCost, itemId){
currentCost = moneyToNumber(itemCost);
if(currentCost < itemCost) {
clearInterval(interval);
$('.label.label-info').html("Out of money! :(");
return;
}
var dataObject = {};
dataObject.acc = account;
dataObject.act = itemToBuy;
dataObject['part-id'] = itemId;
dataObject.price = itemCost;
if(clan)
dataObject.clan = 1;
$.ajax({
type: 'POST',
async: false,
data: dataObject,
success: function() {
currentCost -= itemCost;
var newCost = "$" + currentCost.toLocaleString();
$("div.finance-info > div > span").html(newCost);
console.log("Bought a server!")
},
error: function() {
console.log("Already upgraded!");
}
});
}
//moneyToNumber("$123,456");
function moneyToNumber(x) {
currency = $("div.finance-info > div > span").html();
money = parseInt(currency.replace(/[^0-9\.-]+/g,""));
return money;
}