Skip to content

Commit b47af66

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

File tree

6 files changed

+112
-35
lines changed

6 files changed

+112
-35
lines changed

package-lock.json

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
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

+2
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

+51-31
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,80 @@ 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.');
203+
return;
204+
}
205+
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.');
206210
return;
207211
}
208212

209213
const payload = {
210-
map_id: user.quests.QuestRelicHunter.default_map_id,
214+
map_id: treasure_map[0].map_id,
211215
action: "map_info",
212216
uh: user.unique_hash,
213217
last_read_journal_entry_id: lastReadJournalEntryId,
214218
};
219+
215220
$.post('https://www.mousehuntgame.com/managers/ajax/users/treasuremap.php', payload, null, 'json')
216221
.done(data => {
217222
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;
223+
224+
if(solver === 'mhmh') {
225+
url = data.treasure_map.is_scavenger_hunt? scav_helper_url : map_helper_url;
226+
glue = '\n';
227+
method = 'POST';
228+
input_name = data.treasure_map.is_scavenger_hunt? 'items' : 'mice';
221229
}
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;
230+
231+
if(solver === 'ryonn') {
232+
url = 'http://dbgames.info/mousehunt/tavern';
233+
glue = ';';
234+
method = 'GET';
235+
input_name = 'q';
225236
}
226-
const mice = getMapMice(data, true);
237+
238+
const goals = getMapGoals(data, true);
239+
227240
$('<form method="' + method + '" action="' + url + '" target="_blank">' +
228-
'<input type="hidden" name="' + input_name + '" value="' + mice.join(glue) +
241+
'<input type="hidden" name="' + input_name + '" value="' + goals.join(glue) +
229242
'"></form>').appendTo('body').submit().remove();
230243
}
231244
});
232245
}
233246

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;
247+
/**
248+
* Extract goals from map (can be scav or treasure)
249+
* @param {Object} data Data response from managers/ajax/users/treasuremap.php
250+
* @param {boolean} remaining_only Boolean, if true, to filter out completed goals
251+
* @returns {string[]} Goal names. If on treasure map, it will be mice names and if
252+
* on scavenger it will be item names.
253+
*/
254+
function getMapGoals(data, remaining_only) {
255+
const goalCategory = data.treasure_map.is_scavenger_hunt ? 'item' : 'mouse';
256+
const goals = {};
257+
$.each(data.treasure_map.goals[goalCategory], (key, goal) => {
258+
goals[goal.unique_id] = goal.name;
239259
});
240260

241-
if (uncaught_only) {
261+
if (remaining_only) {
242262
$.each(data.treasure_map.hunters, (key, hunter) => {
243-
$.each(hunter.completed_goal_ids.mouse, (key, mouse_id) => {
244-
delete mice[mouse_id];
263+
$.each(hunter.completed_goal_ids[goalCategory], (key, goal_id) => {
264+
delete goals[goal_id];
245265
});
246266
});
247267
}
248268

249-
return Object.values(mice);
269+
return Object.values(goals);
250270
}
251271

252272
/**
@@ -496,7 +516,7 @@ import * as detailingFuncs from './modules/details/legacy';
496516
return;
497517
}
498518
const map = {
499-
mice: getMapMice(resp),
519+
mice: getMapGoals(resp),
500520
id: map_id,
501521
name: name.replace(/ treasure/i, '')
502522
.replace(/rare /i, '')

src/scripts/popup.js

+3-1
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

+25-1
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)