This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript_market.js
75 lines (65 loc) · 2.13 KB
/
script_market.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
parent.updateit = (function() {
let COLLECTION_SERVER = 'http://localhost:25326';
let COLLECTION_SERVER2 = window.aldc_second_server;
let API_KEY = window.aldc_apikey;
let SCRIPT_VERSION = window.aldc_script_version;
let LAST_CALL = null;
function register_handler(event, handler) {
parent.prev_handlers.push([event, handler]);
parent.socket.on(event, handler);
}
function update() {
if(!parent) {
console.error("Unable to get parent object");
return;
}
if(parent.server_identifier === "HARDCORE") {
console.error("Market not avaliable on HARDCORE server");
return;
}
if(API_KEY.length < 15) {
console.error("Invalid API key");
return;
}
if(!character.stand) {
console.log("Waiting for stand to open...");
return;
}
if(LAST_CALL && mssince(LAST_CALL) < 5000) {
console.log("Let's not spam the server.");
return;
}
update_market(get_character_items());
}
function get_character_items() {
let items = [];
for(let key of Object.keys(character.slots)) {
if(key.startsWith('trade')) {
if(character.slots[key]) {
items.push(character.slots[key]);
}
}
}
return items;
}
function update_market(items) {
let payload = {
items: items,
map: character.map,
server: parent.server_name,
player: character.name,
key: API_KEY,
version: SCRIPT_VERSION
};
let data = new FormData();
data.append('json', JSON.stringify(payload));
let content = { method: 'POST', body: data };
fetch(`${COLLECTION_SERVER}/update`, content).catch(() => {});
if(COLLECTION_SERVER2) {
fetch(`${COLLECTION_SERVER2}/update`, content).catch(() => {});
}
LAST_CALL = new Date(0);
}
parent.ui_success("Use the market script with parent.updateit()");
return update;
}());