Skip to content

Commit faaf685

Browse files
committed
Support: Scavenger Hunt on MHCT Map Helper (auto)
1 parent 06ec8d0 commit faaf685

File tree

6 files changed

+131
-48
lines changed

6 files changed

+131
-48
lines changed

package-lock.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"build": "webpack --config webpack/webpack.prod.js",
4444
"build:dev": "webpack --config webpack/webpack.dev.js",
4545
"build:watch": "webpack --config webpack/webpack.dev.js --watch",
46-
"dev": "npm run build:dev && concurrently \"npm run web-run\" \"npm run build:watch\"",
47-
"dev:firefox": "npm run build:dev && concurrently \"npm run web-run:firefox\" \"npm run build:watch\"",
46+
"dev": "cross-env TARGET=chrome npm run build:dev && concurrently \"npm run web-run\" \"cross-env TARGET=chrome npm run build:watch\"",
47+
"dev:firefox": "cross-env TARGET=firefox npm run build:dev && concurrently \"npm run web-run:firefox\" \"cross-env TARGET=firefox npm run build:watch\"",
4848
"lint": "eslint .",
4949
"test": "jest"
5050
},
@@ -59,6 +59,7 @@
5959
"@typescript-eslint/parser": "^5.59.8",
6060
"concurrently": "^8.0.1",
6161
"copy-webpack-plugin": "^11.0.0",
62+
"cross-env": "^7.0.3",
6263
"eslint": "^8.41.0",
6364
"fork-ts-checker-webpack-plugin": "^8.0.0",
6465
"got-cjs": "^12.5.4",

src/manifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"default_popup": "popup.html"
1616
},
1717

18+
"incognito": "split",
19+
1820
"permissions": [
1921
"tabs",
2022
"*://www.mousehuntgame.com/*",

src/scripts/main.js

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as detailingFuncs from './modules/details/legacy';
1313
'use strict';
1414

1515
let base_domain_url = "https://www.mhct.win";
16-
let main_intake_url, map_intake_url, convertible_intake_url, map_helper_url, rh_intake_url, rejection_intake_url;
16+
let main_intake_url, map_intake_url, convertible_intake_url, map_helper_url, rh_intake_url, rejection_intake_url,scav_helper_url;
1717

1818
let mhhh_version = 0;
1919
let hunter_id_hash = '0';
@@ -110,6 +110,7 @@ import * as detailingFuncs from './modules/details/legacy';
110110
map_helper_url = base_domain_url + "/maphelper.php";
111111
rh_intake_url = base_domain_url + "/rh_intake.php";
112112
rejection_intake_url = base_domain_url + "/rejection_intake.php";
113+
scav_helper_url = base_domain_url + "/scavhelper.php";
113114

114115
await createHunterIdHash();
115116
}
@@ -192,61 +193,86 @@ import * as detailingFuncs from './modules/details/legacy';
192193
let glue = '';
193194
let method = '';
194195
let input_name ='';
195-
if (solver === 'mhmh') {
196-
url = map_helper_url;
197-
glue = '\n';
198-
method = 'POST';
199-
input_name = 'mice';
200-
} else if (solver === 'ryonn') {
201-
url = 'http://dbgames.info/mousehunt/tavern';
202-
glue = ';';
203-
method = 'GET';
204-
input_name = 'q';
205-
} else {
196+
197+
if(!['mhmh', 'ryonn'].includes(solver)) return;
198+
199+
let treasure_map = user.quests.QuestRelicHunter.maps;
200+
201+
if(!treasure_map.length) {
202+
alert('Please make sure you are logged in into MH and are currently member of a treasure map.');
206203
return;
207204
}
208205

209-
const payload = {
210-
map_id: user.quests.QuestRelicHunter.default_map_id,
211-
action: "map_info",
212-
uh: user.unique_hash,
213-
last_read_journal_entry_id: lastReadJournalEntryId,
214-
};
215-
$.post('https://www.mousehuntgame.com/managers/ajax/users/treasuremap.php', payload, null, 'json')
216-
.done(data => {
217-
if (data) {
218-
if (!data.treasure_map || data.treasure_map.view_state === "noMap") {
219-
alert('Please make sure you are logged in into MH and are currently member of a treasure map.');
220-
return;
221-
}
222-
if (!['treasure', 'event'].includes(data.treasure_map.map_class)) {
223-
alert('This seems to be a new kind of map and not yet supported.');
224-
return;
206+
treasure_map = treasure_map.filter(map => ['treasure', 'event'].includes(map.map_class));
207+
208+
if(!treasure_map.length) {
209+
alert('This seems to be a new kind of map and not yet supported.');
210+
return;
211+
}
212+
213+
214+
for(const i in treasure_map) {
215+
216+
const payload = {
217+
map_id: treasure_map[i].map_id,
218+
action: "map_info",
219+
uh: user.unique_hash,
220+
last_read_journal_entry_id: lastReadJournalEntryId,
221+
};
222+
223+
$.post('https://www.mousehuntgame.com/managers/ajax/users/treasuremap.php', payload, null, 'json')
224+
.done(data => {
225+
if (data) {
226+
227+
if(solver === 'mhmh') {
228+
url = data.treasure_map.is_scavenger_hunt? scav_helper_url : map_helper_url;
229+
glue = '\n';
230+
method = 'POST';
231+
input_name = data.treasure_map.is_scavenger_hunt? 'items' : 'mice';
232+
}
233+
234+
if(solver === 'ryonn') {
235+
url = 'http://dbgames.info/mousehunt/tavern';
236+
glue = ';';
237+
method = 'GET';
238+
input_name = 'q';
239+
}
240+
241+
const goals = getMapGoals(data, true);
242+
243+
$('<form method="' + method + '" action="' + url + '" target="_blank">' +
244+
'<input type="hidden" name="' + input_name + '" value="' + goals.join(glue) +
245+
'"></form>').appendTo('body').submit().remove();
225246
}
226-
const mice = getMapMice(data, true);
227-
$('<form method="' + method + '" action="' + url + '" target="_blank">' +
228-
'<input type="hidden" name="' + input_name + '" value="' + mice.join(glue) +
229-
'"></form>').appendTo('body').submit().remove();
230-
}
231-
});
247+
});
248+
}
249+
250+
232251
}
233252

234-
// Extract map mice from a map
235-
function getMapMice(data, uncaught_only) {
236-
const mice = {};
237-
$.each(data.treasure_map.goals.mouse, (key, mouse) => {
238-
mice[mouse.unique_id] = mouse.name;
253+
/**
254+
* Extract goals from map (can be scav or treasure)
255+
* @param {Object} data Data response from managers/ajax/users/treasuremap.php
256+
* @param {boolean} remaining_only Boolean, if true, to filter out completed goals
257+
* @returns {string[]} Goal names. If on treasure map, it will be mice names and if
258+
* on scavenger it will be item names.
259+
*/
260+
function getMapGoals(data, remaining_only) {
261+
const goalCategory = data.treasure_map.is_scavenger_hunt ? 'item' : 'mouse';
262+
const goals = {};
263+
$.each(data.treasure_map.goals[goalCategory], (key, goal) => {
264+
goals[goal.unique_id] = goal.name;
239265
});
240266

241-
if (uncaught_only) {
267+
if (remaining_only) {
242268
$.each(data.treasure_map.hunters, (key, hunter) => {
243-
$.each(hunter.completed_goal_ids.mouse, (key, mouse_id) => {
244-
delete mice[mouse_id];
269+
$.each(hunter.completed_goal_ids[goalCategory], (key, goal_id) => {
270+
delete goals[goal_id];
245271
});
246272
});
247273
}
248274

249-
return Object.values(mice);
275+
return Object.values(goals);
250276
}
251277

252278
/**
@@ -496,7 +522,7 @@ import * as detailingFuncs from './modules/details/legacy';
496522
return;
497523
}
498524
const map = {
499-
mice: getMapMice(resp),
525+
mice: getMapGoals(resp),
500526
id: map_id,
501527
name: name.replace(/ treasure/i, '')
502528
.replace(/rare /i, '')

src/scripts/popup.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
function findOpenMHTab(callback, button_id, silent) {
99
chrome.tabs.query({'url': ['*://www.mousehuntgame.com/*', '*://apps.facebook.com/mousehunt/*']}, tabs => {
1010
if (tabs.length > 0) {
11-
callback(tabs[0].id, button_id);
11+
const isPrivate = typeof browser !== 'undefined' ? browser.extension.inIncognitoContext : chrome.extension.inIncognitoContext;
12+
const tf = tabs.filter(t => t.incognito === isPrivate);
13+
callback(tf[0].id, button_id);
1214
}
1315
else if (!silent) {
1416
displayErrorPopup("Please navigate to MouseHunt page first.");

webpack/webpack.common.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ const RemoteDownloadFileWebpackPlugin = require('./RemoteDownloadFileWebpackPlug
66
const srcScripts = path.resolve(__dirname, '../src/scripts/');
77
const outpath = path.resolve(__dirname, '../dist/');
88

9+
function modify(buffer) {
10+
// copy-webpack-plugin passes a buffer
11+
var manifest = JSON.parse(buffer.toString());
12+
13+
// make any modifications you like, such as
14+
// manifest.version = package.version;
15+
if(process.env.TARGET == 'firefox') {
16+
delete manifest.incognito;
17+
}
18+
19+
// pretty print to JSON with two spaces
20+
manifest_JSON = JSON.stringify(manifest, null, 2);
21+
22+
return manifest_JSON;
23+
}
24+
925
module.exports = {
1026
entry: {
1127
background: path.join(srcScripts, 'background.js'),
@@ -43,10 +59,18 @@ module.exports = {
4359
from: './',
4460
to: outpath,
4561
globOptions: {
46-
ignore: ['**/scripts'],
62+
ignore: ['**/scripts', '**/manifest.json'],
4763
},
4864
context: 'src/',
4965
},
66+
{
67+
from: "./manifest.json",
68+
to: outpath,
69+
transform(content, absoluteFrom) {
70+
return modify(content);
71+
},
72+
context: 'src/',
73+
},
5074
],
5175
}),
5276
new RemoteDownloadFileWebpackPlugin([

0 commit comments

Comments
 (0)