Minecraft Helper

为 Minecraft 玩家定制的实用脚本

22.04.2023 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Minecraft Helper
// @namespace    http://tampermonkey.net/
// @version      0.3.1
// @description  为 Minecraft 玩家定制的实用脚本
// @author       PRO
// @license      gpl-3.0
// @match        https://www.minecraft.net/*
// @match        https://www.curseforge.com/*
// @match        https://modrinth.com/*
// @icon         https://www.minecraft.net/etc.clientlibs/minecraft/clientlibs/main/resources/img/minecraft-creeper-face.jpg
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    let config = {
        "general": {
            "timeout": 500              // 部分功能的延迟
        },
        "minecraft": {
            "auto-stay": true           // 自动点击“留在 Minecraft.net”
        },
        "curseforge": {
            "auto-mod": true,           // 首页自动转到 MC 模组界面
            "highlight-files": true,    // 突出显示 "Files" 项目
            "highlight-border": "rgb(241, 100, 54) 0.2em solid",
            "default-download": true    // 默认直接下载
        },
        "modrinth": {
            "auto-mod": true,           // 首页自动转到 MC 模组界面
            "shortcut": true            // 快捷键: <F>iles, <-, ->
        }
    };
    function try_click(selector) {
        let ele = document.querySelector(selector);
        if (ele) ele.click();
    }
    function cf_replace(menu) {
        menu.children[0].remove();
        let down = menu.querySelector("#contextMenu").children[1];
        let new_btn = document.createElement("button");
        new_btn.innerHTML = '<svg><use href="/images/sprite.svg#icon-download"></use></svg><span>Download</span>';
        new_btn.setAttribute("class", "btn-cta");
        new_btn.onclick = (e) => { window.location.href = down.children[0].href; };
        menu.insertBefore(new_btn, menu.children[0]);
    }
    switch (window.location.host) {
        case 'www.minecraft.net': {
            if (config.minecraft["auto-stay"])
                try_click("#popup-btn");
            break;
        }
        case 'www.curseforge.com': {
            if (config.curseforge["auto-mod"] && window.location.pathname == '/') {
                window.location.pathname = "/minecraft/mc-mods";
            }
            if (config.curseforge["highlight-files"] && window.location.pathname != "/") {
                let tabs = document.getElementsByClassName("tabs");
                if (tabs.length) {
                    tabs = tabs[0];
                    for (let tab of tabs.children) {
                        if (tab.textContent == "Files") {
                            tab.style.border = config.curseforge["highlight-border"];
                            break;
                        }
                    }
                }
            }
            if (config.curseforge["default-download"]) {
                let menu = document.querySelector("#menuButton");
                cf_replace(menu);
                let content = document.getElementsByClassName("tab-content")[0];
                let cfg = { attributes: false, childList: true, subtree: true };
                let callback = (mutations, observer) => {
                    for (let mutation of mutations) {
                        if (mutation.addedNodes.length && mutation.addedNodes[0].nodeName == "SECTION") {
                            let menu = mutation.addedNodes[0].querySelector("#menuButton");
                            if (menu) cf_replace(menu);
                        }
                    }
                };
                let observer = new MutationObserver(callback);
                observer.observe(content, cfg);
            }
            break;
        }
        case "modrinth.com": {
            if (window.location.pathname == "/" && config.modrinth["auto-mod"]) {
                try_click(".button-group > a");
            }
            if (config.modrinth.shortcut) {
                document.addEventListener("keydown", (e) => {
                    if (document.activeElement.nodeName != "INPUT") {
                        switch (e.key) {
                            case "ArrowLeft":
                                try_click(".left-arrow");
                                break;
                            case "ArrowRight":
                                try_click(".right-arrow");
                                break;
                            case "f":
                                try_click(".goto-link");
                                break;
                            case "s":
                                try_click(".navigation > a.nav-link");
                                window.setTimeout(() => {
                                    let search = document.getElementById("search");
                                    if (search) search.focus();
                                }, config.general.timeout);
                                e.preventDefault();
                                break;
                            default:
                                break;
                        }
                    }
                })
            }
            break;
        }
    }
})();