-
Notifications
You must be signed in to change notification settings - Fork 0
/
MqoUtility.user.js
416 lines (354 loc) · 13.2 KB
/
MqoUtility.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
// ==UserScript==
// @name MQO Utility
// @namespace https://github.com/davidmcclelland/
// @author Dave McClelland <[email protected]>
// @homepage https://github.com/davidmcclelland/MqoUtility
// @supportURL https://github.com/davidmcclelland/MqoUtility/issues
// @downloadURL https://github.com/davidmcclelland/MqoUtility/raw/master/MqoUtility.user.js
// @version 1.0.0
// @include http://www.midenquest.com/Game.aspx
// @include http://midenquest.com/Game.aspx
// @license LGPL-2.1
// @grant GM_addStyle
// @grant unsafeWindow
// @noframes
// ==/UserScript==
const sleep = m => new Promise(r => setTimeout(r, m));
if (unsafeWindow.MqoUtility === undefined) {
unsafeWindow.MqoUtility = {};
}
const ButtonBar = (() => {
const displayHtml = `<div id="MqoUtilityButtons" style="margin-top: 5px;"></div>`;
const displayStyle = `
#MqoUtilityButtons > input {
text-align: center;
font-size: 13px;
height: 30px;
width: auto;
align-self: center;
border: 1px solid #00000088;
border-radius: 5px;
font-weight: bold;
font-family: Helvetica;
}
`
const addToButtonBar = (elemStr) => {
$('#MqoUtilityButtons').append(elemStr);
}
$(document).ready(() => {
GM_addStyle(displayStyle);
$('#TitleEmbedded').remove();
$('#ZoneContent').prepend(displayHtml);
});
unsafeWindow.MqoUtility.ButtonBar = { addToButtonBar };
})();
const ChestOpener = (() => {
const openChestHtml = `<input type="button" class="gmButtonMed" value="Chests" onclick="MqoUtility.ChestOpener.openAllChests()">`;
const openBagHtml = `<input type="button" class="gmButtonMed" value="Bags/Keys" onclick="MqoUtility.ChestOpener.openBagsAndKeys()">`;
const bronzeChestId = '#btnOpenChest2';
const silverChestid = '#btnOpenChest3';
const goldChestId = '#btnOpenChest4';
const keyId = '#btnOpen';
const resBagId = '#btnOpenResBag';
const keepOpeningChest = (btnId) => {
return $(btnId).length && ($(btnId)[0].style.display !== 'none');
};
const openAllChestsOfType = async (btnId) => {
let btnLength = keepOpeningChest(btnId);
while (btnLength) {
$(btnId).click();
await sleep(500);
btnLength = keepOpeningChest(btnId);
}
}
const openAllChests = async () => {
sendRequestContentFill('getNavigation.aspx?screen=2&gambling=1');
await sleep(500);
await openAllChestsOfType(goldChestId);
await openAllChestsOfType(silverChestid);
await openAllChestsOfType(bronzeChestId);
};
const openBagsAndKeys = async () => {
await openAllChests();
await openAllChestsOfType(keyId);
await openAllChestsOfType(resBagId);
}
$(document).ready(() => {
unsafeWindow.MqoUtility.ButtonBar.addToButtonBar(openChestHtml);
unsafeWindow.MqoUtility.ButtonBar.addToButtonBar(openBagHtml);
});
unsafeWindow.MqoUtility.ChestOpener = { openAllChests, openBagsAndKeys };
})();
const Market = (() => {
const dealButtonHtml = `<input type="button" class="gmButtonMed" value="Deals" onclick="MqoUtility.Market.purchaseDailyDeals()">`;
const marketButtonHtml = `<input type="button" class="gmButtonMed" value="Market" onclick="MqoUtility.Market.goToMarket()">`;
const purchaseDailyDeals = async () => {
sendRequestContentFill('getNavigation.aspx?screen=2&market=1');
await sleep(500);
for (let buyIndex = 1; buyIndex <= 5; ++buyIndex) {
const buyButton = $('#btnBuy' + buyIndex);
if (buyButton.length) {
buyButton.click();
await sleep(500);
}
}
}
const goToMarket = () => {
sendRequestContentFill(`getMarket.aspx?null=`);
}
$(document).ready(() => {
unsafeWindow.MqoUtility.ButtonBar.addToButtonBar(dealButtonHtml);
unsafeWindow.MqoUtility.ButtonBar.addToButtonBar(marketButtonHtml);
});
unsafeWindow.MqoUtility.Market = { purchaseDailyDeals, goToMarket };
})();
const Perks = (() => {
const DrunkButtonId = '#btnActivatePerk21';
const EnragedButtonId = '#btnActivatePerk22';
const LuckyButtonId = '#btnActivatePerk23';
const PitiedButtonId = '#btnActivatePerk24';
const HoarderButtonId = '#btnActivatePerk25';
const desiredPerks = [DrunkButtonId, EnragedButtonId, LuckyButtonId, PitiedButtonId, HoarderButtonId];
const perkHtml = `<input type="button" class="gmButtonMed" value="Perks" onclick="MqoUtility.Perks.addPerks()">`;
const addPerk = async (btnId, numTimes) => {
$(btnId).click();
await sleep(250);
for (let clickCounter = 0; clickCounter < numTimes; ++clickCounter) {
$('#btnActivateOre').click();
await sleep(250);
}
}
const addPerks = async () => {
sendRequestContentFill('getInfoPerk.aspx?');
await sleep(500);
// Each click is 2 hours, so multiply number of days by 12
const clicksPerPerk = Number(prompt('How many days of perks would you like to add?', '5')) * 12;
for (let perkCounter = 0; perkCounter < desiredPerks.length; ++perkCounter) {
await addPerk(desiredPerks[perkCounter], clicksPerPerk);
}
}
$(document).ready(() => {
unsafeWindow.MqoUtility.ButtonBar.addToButtonBar(perkHtml);
});
unsafeWindow.MqoUtility.Perks = { addPerks };
})();
const BulkSell = (() => {
const bulkSellHtml = `<input type="button" class="gmButtonMed" value="Bulk Sell" onclick="MqoUtility.BulkSell.toggleSelling()">`;
let bulkSellButton = null;
let bulkSellInterval = null;
const startSelling = () => {
bulkSellButton.style.backgroundColor = '#d63031';
bulkSellInterval = setInterval(() => {
sendRequestContentFill('getCustomize.aspx?bulk=1&bulks=14&bulkq=4&bulke=1&confirmbs=1&null=');
}, 1000);
}
const stopSelling = () => {
bulkSellButton.style.backgroundColor = '#ffffff';
clearInterval(bulkSellInterval);
bulkSellInterval = null;
}
const toggleSelling = () => {
if(bulkSellInterval) {
stopSelling();
} else {
startSelling();
}
}
$(document).ready(() => {
bulkSellButton = $(bulkSellHtml)[0];
unsafeWindow.MqoUtility.ButtonBar.addToButtonBar(bulkSellButton);
});
unsafeWindow.MqoUtility.BulkSell = { toggleSelling };
})();
const Kingdom = (() => {
const maintainKingdomHtml = `<input type="button" class="gmButtonMed" value="KD Food" onclick="MqoUtility.Kingdom.maintainKingdomFood()">`;
const maintainKingdomFood = () => {
sendRequestContentFill('getKingdom.aspx?action=maintain&null=');
}
$(document).ready(() => {
unsafeWindow.MqoUtility.ButtonBar.addToButtonBar(maintainKingdomHtml);
});
unsafeWindow.MqoUtility.Kingdom = { maintainKingdomFood };
})();
const Runes = (() => {
const combineRunesHtml = `<input type="button" class="gmButtonMed" value="Runes" onclick="MqoUtility.Runes.createRune()">`;
const lastRuneLevelKey = 'mqoUtilityLastRuneLevel';
const combineRunesOfLevel = async () => {
sendRequestContentFill('getRuneUpgrade.aspx');
await sleep(500);
const runeLevel = prompt('What level of rune would you like to combine (entered as the string name)?', 'two');
const buttonId = `#dex_rune_${runeLevel}_btn`;
while (true) {
const dexButton = $(buttonId);
dexButton.click();
await sleep(10000);
const combineButton = $('#btnUpgrade');
if (combineButton.length) {
combineButton.click();
await sleep(3000);
} else {
break;
}
}
}
const countRunesOfLevel = (level) => {
// Set up the regex to be used on each option to find the value of the item.
const rgxLevel = / lv. (\d+)/i;
let skip = false;
let count = 0;
$('#SelectItemSource').find('option').each((index, element) => {
if (element.text == "---Rune to upgrade---") {
// Ignore all of the runes for a while because they are the equipped runes. Keep skipping the runes until we see the
// option/label that denotes the "real" runes are starting next.
skip = true;
return true;
}
if (skip) {
if (element.text == "---Inventory Runes---") {
skip = false;
}
return true;
}
var result = rgxLevel.exec(element.text);
if (result != null) {
var valueInt = parseInt(result[1], 10);
if (valueInt == level) {
count++;
return true;
}
} else {
// This entry does not have a value associated with it. It is probably one of the section headers or spacer lines.
}
});
return count;
}
const createRune = async () => {
sendRequestContentFill('getRuneUpgrade.aspx');
await sleep(500);
const defaultRuneLevel = unsafeWindow.localStorage.getItem(lastRuneLevelKey) || 15;
const targetRuneLevel = Number(prompt('What level of rune would you like to make?', defaultRuneLevel));
if (targetRuneLevel) {
unsafeWindow.localStorage.setItem(lastRuneLevelKey, targetRuneLevel);
createRuneOfLevel(targetRuneLevel);
}
}
const createRuneOfLevel = async (targetRuneLevel) => {
let sourceRuneLevel = targetRuneLevel - 1;
let sacrificedRuneLevel = targetRuneLevel - 6;
switch (targetRuneLevel) {
case 1:
return;
case 2:
return;
case 3:
sourceRuneLevel = 1;
sacrificedRuneLevel = 1;
break;
case 4:
sourceRuneLevel = 3;
sacrificedRuneLevel = 1;
break;
case 5:
sourceRuneLevel = 3;
sacrificedRuneLevel = 3;
break;
case 6:
sourceRuneLevel = 4;
sacrificedRuneLevel = 4;
break;
}
const amountNeeded = (sourceRuneLevel === sacrificedRuneLevel) ? 2 : 1;
while (countRunesOfLevel(sourceRuneLevel) < amountNeeded) {
if ((sourceRuneLevel === 1) || (sourceRuneLevel === 2)) {
alert('Not enough level 1 or 2 runes available to continue!');
throw 'Not enough level 1 or 2 runes available to continue!';
}
await createRuneOfLevel(sourceRuneLevel);
}
while (countRunesOfLevel(sacrificedRuneLevel) < amountNeeded) {
await createRuneOfLevel(sacrificedRuneLevel);
}
const sourceRuneCount = countRunesOfLevel(sourceRuneLevel);
const sacrificedRuneCount = countRunesOfLevel(sacrificedRuneLevel);
if ((amountNeeded > sourceRuneCount) || (amountNeeded > sacrificedRuneCount)) {
alert('Not enough runes are available to continue');
throw `Not enough runes available. sourceRuneLevel: ${sourceRuneLevel}, sacrificedLevel: ${sacrificedRuneLevel}`;
}
MQO_RuneHelper.selectRuneWrapper(sourceRuneLevel);
await sleep(2000);
if (sacrificedRuneLevel !== sourceRuneLevel) {
$('#dex_rune_minus5_btn').click();
await sleep(2000);
}
const combineButton = $('#btnUpgrade');
if (combineButton.length) {
combineButton.click();
await sleep(2000);
} else {
alert('The button to combine did not appear. Something went wrong!');
throw 'The button to combine did not appear. Something went wrong!';
}
}
const createMultipleRunesOfLevel = async (level, quantity) => {
sendRequestContentFill('getRuneUpgrade.aspx');
await sleep(500);
for (let i = 0; i < quantity; i++) {
console.log('Creating rune', i + 1, 'of', quantity);
await createRuneOfLevel(level);
}
}
$(document).ready(() => {
unsafeWindow.MqoUtility.ButtonBar.addToButtonBar(combineRunesHtml);
});
unsafeWindow.MqoUtility.Runes = { combineRunesOfLevel, createRune, createMultipleRunesOfLevel };
})();
// Credit to Vibbles for the chat extender
// https://raw.githubusercontent.com/Vibblez/MidenQuest/master/MidenQuest.ChatExtender.user.js
const ChatExtender = (() => {
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
addGlobalStyle('#ZoneChat { height: 360px; } #ChatLog { height: 300px; }');
})();
const NavigationHelpers = (() => {
const addLinks = (id) => {
let side = $(`#${id}`);
let sideText = document.getElementById(id).innerHTML;
side.off();
if (/\w*\s\w*(Gamble)/g.test(sideText)) {
side.on("click", () => {
sendRequestContentFill("getNavigation.aspx?screen=2&gambling=1&null=");
});
} else if (/[1-9]\sDeals/g.test(sideText)) {
side.on("click", () => {
sendRequestContentFill("getNavigation.aspx?screen=2&market=1&null=");
});
} else if (/\sPerk\s(T|t)ime/g.test(sideText)) {
side.on("click", () => {
sendRequestContentFill("getInfoPerk.aspx?null=");
});
}
}
$(document).ready(() => {
const side1 = document.getElementById("SideAlert1");
const side2 = document.getElementById("SideAlert2");
const side3 = document.getElementById("SideAlert3");
const side4 = document.getElementById("SideAlert4");
/* Side bar event listeners */
side1.addEventListener("DOMSubtreeModified", () => addLinks("SideAlert1"));
side2.addEventListener("DOMSubtreeModified", () => addLinks("SideAlert2"));
side3.addEventListener("DOMSubtreeModified", () => addLinks("SideAlert3"));
side4.addEventListener("DOMSubtreeModified", () => addLinks("SideAlert4"));
/* Add initial sidebar links upon page load */
addLinks("SideAlert1");
addLinks("SideAlert2");
addLinks("SideAlert3");
addLinks("SideAlert4");
});
})();