forked from dodying/UserJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhvSellEquipment2.user.js
258 lines (255 loc) · 7.39 KB
/
hvSellEquipment2.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/* eslint-env browser */
// ==UserScript==
// @name [HV]SellEquipment2
// @description
// @include http*://hentaiverse.org/
// @include http*://hentaiverse.org/?s=Character&ss=ch
// @include http*://hentaiverse.org/?s=Battle&ss=ba&encounter=*
// @include http://alt.hentaiverse.org/
// @include http://alt.hentaiverse.org/?s=Character&ss=ch
// @include http://alt.hentaiverse.org/?s=Battle&ss=ba&encounter=*
// @version 1.01
// @grant none
// @author dodying
// @namespace https://github.com/dodying/
// @supportURL https://github.com/dodying//UserJs/issues
// @icon https://gitee.com/dodying/userJs/raw/master/Logo.png
// @run-at document-end
// ==/UserScript==
(function () {
/**
* [keepEqps description]
* the Equipment that you DON'T want to sell
* @type {Array}
* Eg. ['Magnificent', 'Legendary', 'Peerless']
* Eg. ['Legendary Arctic Redwood Staff of Destruction']
*/
let keepEqps = ['Magnificent', 'Legendary', 'Peerless'];
/**
* [func description]
* here put in what you want to do after sell the eqps
*/
const func = function () {
// grFunc();//start GrindFest
// location.href = location.href;//page reload
};
/**
* [price description]
* here put in the price of each material
*/
const price = [{ // Scrap
Cloth: 0,
Leather: 0,
Metal: 0,
Wood: 0,
}, { // Low-Grade
Cloth: 0,
Leather: 0,
Metal: 0,
Wood: 0,
}, { // Mid-Grade
Cloth: 0,
Leather: 0,
Metal: 0,
Wood: 0,
}, { // High-Grade
Cloth: 0,
Leather: 0,
Metal: 0,
Wood: 0,
}];
/*
var price = [{ //Scrap
Cloth: 90,
Leather: 85,
Metal: 85,
Wood: 90,
}, { //Low-Grade
Cloth: 200,
Leather: 200,
Metal: 200,
Wood: 200,
}, { //Mid-Grade
Cloth: 600,
Leather: 550,
Metal: 550,
Wood: 600,
}, { //High-Grade
Cloth: 20000,
Leather: 800,
Metal: 1200,
Wood: 9500
}];
*/
/**
*
*/
if (!gE('#navbar')) return;
const quality = [/Crude|Fair|Average/, /Superior/, /Exquisite/, /Magnificent|Legendary|Peerless/];
const material = {
'1handed': 'Metal',
'2handed': 'Metal',
staff: 'Wood',
shield: 'Wood',
acloth: 'Cloth',
alight: 'Leather',
aheavy: 'Metal',
};
const url = ['1handed', '2handed', 'staff', 'shield', 'acloth', 'alight', 'aheavy'];
keepEqps = new RegExp(keepEqps.join('|'));
let eids;
const eidsSell = [];
const eidsSalvage = {
'1handed': [],
'2handed': [],
staff: [],
shield: [],
acloth: [],
alight: [],
aheavy: [],
};
let amountSalvage = 0;
let eqvalue;
let valueSell;
let valueSalvage;
let len = 0;
let i; let
j;
let amount;
let doSell;
let doSalvage = 0;
const result = {};
let text;
let html = '';
url.forEach((i) => {
post(`?s=Bazaar&ss=es&filter=${i}`, (data) => {
checkFunc(data, i);
});
});
var checkFunc = function (data, url) {
len++;
eids = {};
gE('#eqshop_outer>.eqshop_pane:nth-child(1) .eqp>.iu+div[id]', 'all', data).forEach((i) => {
if (!keepEqps.test(i.textContent)) eids[i.id.match(/\d+/)[0]] = i.textContent;
});
if (Object.keys(eids).length !== 0) {
eqvalue = JSON.parse(gE('#mainpane>script[src]+script', data).text.match(/var eqvalue = (.*?);/)[1]);
for (i in eids) {
valueSell = eqvalue[i];
if (quality[0].test(eids[i])) {
amount = Math.ceil(valueSell / 100);
valueSalvage = amount * price[0][material[url]];
} else {
amount = Math.ceil(valueSell / 500);
valueSalvage = amount * price[0][material[url]];
for (j = 1; j < quality.length; j++) {
if (quality[j].test(eids[i])) break;
}
valueSalvage = valueSalvage + price[j][material[url]];
}
if (valueSell >= valueSalvage) {
eidsSell.push(i);
} else {
amountSalvage++;
eidsSalvage[url].push(i);
}
}
}
if (len === 7) {
console.log(eidsSell, eidsSalvage);
if (eidsSell.length > 0) {
post('?s=Bazaar&ss=es', () => {
doSell = true;
if (doSell && doSalvage === amountSalvage) doFunc();
}, `storetoken=${gE('input[name="storetoken"]', data).value}&select_group=item_pane&select_eids=${encodeURIComponent(eidsSell.join())}`);
} else {
doSell = true;
}
salvageFunc(eidsSalvage);
}
};
var salvageFunc = function (eidsSalvage) {
for (i in eidsSalvage) {
if (eidsSalvage[i].length === 0) {
delete eidsSalvage[i];
continue;
} else {
break;
}
}
if (Object.keys(eidsSalvage).length === 0) return;
post(`?s=Forge&ss=sa&filter=${i}`, () => {
countResult(gE('#messagebox>div:nth-child(2)>div>div>div>div>div', 'all'));
eidsSalvage[i].splice(0, 1);
doSalvage++;
if (doSell && doSalvage === amountSalvage) {
doFunc();
} else {
salvageFunc(eidsSalvage);
}
}, `select_item=${eidsSalvage[i][0]}`);
};
var doFunc = function () {
if (amountSalvage !== 0) {
for (i in result) {
html = `${html}<div><div style="width:530px; height:20px"><div style="width:530px; height:17px"><div class="fc2 fac fcb" style="width:530px"><div>Salvaged ${result[i]}x ${i}</div></div></div></div></div>`;
}
gE('#messagebox>div:nth-child(2)').innerHTML = html;
}
func();
};
var countResult = function (obj) {
obj.forEach((i) => {
text = i.textContent.replace(/^Salvaged (\d+x )/, '');
amount = i.textContent.match(/\d+/) ? i.textContent.match(/\d+/)[0] * 1 : 1;
if (text in result) {
result[text] += amount || 1;
} else {
result[text] = amount || 1;
}
});
};
const grFunc = function () {
post('?s=Battle&ss=gr', (data) => {
post('?s=Battle&ss=gr', () => {
window.location.href = window.location.href;
}, `initid=1&inittoken=${gE('img[src*="startgrindfest.png"]', data).getAttribute('onclick').match(/init_battle\(1, '(.*?)'\)/)[1]}`);
});
};
function gE(ele, mode, parent) { // 获取元素
if (typeof ele === 'object') {
return ele;
} if (mode === undefined && parent === undefined) {
return (isNaN(ele * 1)) ? document.querySelector(ele) : document.getElementById(ele);
} if (mode === 'all') {
return (parent === undefined) ? document.querySelectorAll(ele) : parent.querySelectorAll(ele);
} if (typeof mode === 'object' && parent === undefined) {
return mode.querySelector(ele);
}
}
function post(href, func, parm, type) { // post
let xhr = new window.XMLHttpRequest();
xhr.open(parm ? 'POST' : 'GET', href);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
xhr.responseType = type || 'document';
xhr.onerror = function () {
xhr = null;
post(href, func, parm, type);
};
xhr.onload = function (e) {
if (e.target.status >= 200 && e.target.status < 400 && typeof func === 'function') {
const data = e.target.response;
if (xhr.responseType === 'document' && gE('#messagebox', data)) {
if (gE('#messagebox')) {
gE('#csp').replaceChild(gE('#messagebox', data), gE('#messagebox'));
} else {
gE('#csp').appendChild(gE('#messagebox', data));
}
}
func(data, e);
}
xhr = null;
};
xhr.send(parm);
}
}());