Melvor Idle Change Game Mode

Adds a button to the settings page to allow the user to change their game mode at will

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Melvor Idle Change Game Mode
// @description Adds a button to the settings page to allow the user to change their game mode at will
// @version     1.0
// @namespace   Silber
// @match       https://melvoridle.com/*
// @match       https://www.melvoridle.com/*
// @match       https://test.melvoridle.com/*
// @noframes
// @grant        none
// ==/UserScript==
/* jshint esversion: 6 */

((main) => {
    var script = document.createElement('script');
    script.textContent = `try { (${main})(); } catch (e) { console.log(e); }`;
    document.body.appendChild(script).parentNode.removeChild(script);
})(() => {
    'use strict';

    function injectSettingsChangeMode() {
        // function for dropdown to use
        window.changeGameMode = function (modeId) {
            modeId = parseInt(modeId);
            if (currentGamemode != modeId) {
                currentGamemode = modeId;
                saveData();
                location.href='index.php';
            }
        }

        // injecting button into the settings UI
        if ($("#settings-container")){
            var settingsContainer = $("#settings-container");
            var values = ["Standard", "Hardcore", "Adventure", "Chaos (Not Supported)", "Hardcore Adventure (Not Supported)", "Internal Suffering Speedrun"];
 
            settingsContainer.find(".block-content")
                .append($(document.createElement('h2'))
                    .html('Script Settings'))
                .append($(document.createElement('div'))
                    .append(
                        $(document.createElement('label')).prop({
                            for: 'gameMode'
                        }).html('Choose your game mode: ')
                    )
                    .append(
                        $(document.createElement('select')).prop({
                            id: 'gameMode',
                            name: 'gameMode'
                        })
                    )
                )
            
            var index = 0;
            for (const val of values) {
                $('#gameMode').append($(document.createElement('option')).prop({
                    value: index,
                    text: val.charAt(0).toUpperCase() + val.slice(1)
                }))
                index++;
            }

            $("#gameMode").change(function () {
                changeGameMode($(this).val());
            })
        }
    }

    function loadScript() {
        if (typeof confirmedLoaded !== 'undefined' && confirmedLoaded) {
            clearInterval(interval);
            console.log('Loading Melvor Idle Change Game Mode script');
            injectSettingsChangeMode();
        }
    }

    const interval = setInterval(loadScript, 500);
});