MH - Map Helper

Map Helper: Get all mice or loots informations from MHCT in any treasure map in a click!

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         MH - Map Helper
// @description  Map Helper: Get all mice or loots informations from MHCT in any treasure map in a click!
// @author       Snowbits
// @version      1.0.0
// @match        https://www.mousehuntgame.com/*
// @match        https://apps.facebook.com/mousehunt/*
// @icon         https://www.google.com/s2/favicons?domain=mousehuntgame.com
// @namespace    https://greasyfork.org/users/1140737
// @license      MIT
// ==/UserScript==

function injectButton() {

    if (document.querySelector('#mh-map-helper-btn')) {
        return;
    }

    const originalButton = document.querySelector(
        '.mousehuntActionButton.treasureMapView-previewRewardsButton'
    );

    if (!originalButton) {
        return;
    }

    const targetContainer = document.querySelector('.treasureMapRootView-subTabRow');

    const newButton = originalButton.cloneNode(true);

    newButton.id = 'mh-map-helper-btn';
    newButton.title = 'Map Helper Button';
    newButton.style.marginLeft = '10px';
    newButton.classList.remove('lightBlue');

    const span = newButton.querySelector('span');

    if (span) {
        span.textContent = 'Map Helper';
    }

    newButton.addEventListener('click', () => {

        const inputNames = getInputNames();

        const mapName = document
            .querySelector('.mh-ui-map-name')
            ?.textContent
            .trim() || '';

        const isScavengerMap = mapName.includes('Hunt');

        const url = isScavengerMap
            ? 'https://www.mhct.win/scavhelper.php'
            : 'https://www.mhct.win/maphelper.php';

        const form = document.createElement('form');

        form.method = 'POST';
        form.action = url;
        form.target = '_blank';

        const input = document.createElement('input');

        input.type = 'hidden';
        input.name = isScavengerMap ? 'items' : 'mice';
        input.value = inputNames;

        form.appendChild(input);

        document.body.appendChild(form);

        form.submit();

        form.remove();
    });

    targetContainer.insertBefore(newButton,null);
}

function getInputNames() {

    const inputs = {};

    document.querySelectorAll(
        '.treasureMapView-goals-group-goal:not(.complete) .treasureMapView-goals-group-goal-name span'
    ).forEach(span => {

        const name = span.textContent.trim();

        if (name) {
            inputs[name] = name;
        }
    });

    return Object.values(inputs).join('\n');
}

const observer = new MutationObserver(() => {

    const popup = document.querySelector('.treasureMapView');

    if (!popup) {
        return;
    }

    injectButton();
});

observer.observe(document.body, {
    childList: true,
    subtree: true
});