MH - Map Helper

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

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل 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
});