MH - Map Helper

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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
});