// ==UserScript== // @name MWI TaskManager // @namespace http://tampermonkey.net/ // @version 0.5 // @description sort all task in taskpanel // @author shykai // @match https://www.milkywayidle.com/* // @match https://test.milkywayidle.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=milkywayidle.com // @grant none // @downloadURL none // ==/UserScript== (function () { 'use strict'; const taskBattleIndex = 99; //Battle at bottom const taskOrderIndex = { Milking: 1, Foraging: 2, Woodcutting: 3, Cheesesmithing: 4, Crafting: 5, Tailoring: 6, Cooking: 7, Brewing: 8, Alchemy: 9, Enhancing: 10, Defeat: taskBattleIndex, //Battle at bottom }; const taskCNOrderIndex = { 挤奶: 1, 采摘: 2, 伐木: 3, 奶酪锻造: 4, 制作: 5, 缝纫: 6, 烹饪: 7, 冲泡: 8, 炼金: 9, 强化: 10, De击败feat: taskBattleIndex, //Battle at bottom }; /* 支持修改版汉化插件 */ function getOriTextFromElement(elem) { if (!elem) { //console.error("getTextFromElement null elem"); return ""; } const translatedfrom = elem.getAttribute("script_translatedfrom"); if (translatedfrom) { return translatedfrom; } return elem.textContent; } /* 兼容MWITools地图编号 */ function getMapIndexFromElement(elem) { var node = elem.querySelector("span.script_taskMapIndex"); if (!node) { return -1; } return Number(node.textContent.replace(/\D/ig, "")); } function getTaskOrderIndexByTaskName(taskName) { var taskType = -1; if (/^(.+) - .+$/.test(taskName)) { let res = /^(.+) - .+$/.exec(taskName); if (res[1] in taskOrderIndex) { taskType = taskOrderIndex[res[1]]; } else if (res[1] in taskCNOrderIndex) { taskType = taskCNOrderIndex[res[1]]; } } if (taskType == -1) console.log(taskName, taskType); return taskType; } function compareFn(a, b) { var a_name = getOriTextFromElement(a.querySelector("div.RandomTask_name__1hl1b")); var b_name = getOriTextFromElement(b.querySelector("div.RandomTask_name__1hl1b")); var a_index = getTaskOrderIndexByTaskName(a_name); var b_index = getTaskOrderIndexByTaskName(b_name); if (a_index === taskBattleIndex && b_index === taskBattleIndex) { var a_MapIndex = getMapIndexFromElement(a); var b_MapIndex = getMapIndexFromElement(b); if (a_MapIndex != b_MapIndex) { return (a_MapIndex > b_MapIndex ? 1 : -1); } } if (a_index == b_index) { return a_name == b_name ? 0 : (a_name > b_name ? 1 : -1); } return a_index > b_index ? 1 : -1; } function addButton() { const targetNode = document.querySelector("div.TasksPanel_taskSlotCount__nfhgS"); if (targetNode) { let sortButton = targetNode.querySelector("#TaskSort"); if (!sortButton) { sortButton = document.createElement("button"); sortButton.setAttribute("class", "Button_button__1Fe9z Button_small__3fqC7"); sortButton.id = "TaskSort"; sortButton.innerHTML = "TaskSort"; sortButton.addEventListener("click", function (evt) { const list = document.querySelector("div.TasksPanel_taskList__2xh4k"); [...list.querySelectorAll("div.RandomTask_randomTask__3B9fA")] .sort(compareFn) .forEach(node => list.appendChild(node)); }); targetNode.appendChild(sortButton); } } } const config = { attributes: true, childList: true, subtree: true }; const observer = new MutationObserver(function (mutationsList, observer) { addButton(); }); observer.observe(document, config); })();