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
});