// ==UserScript== // @name 猫国建设者挂机插件 // @namespace https://github.com/jiang-ruo/moescript // @description 游戏《猫国建设者/喵国建设者/Kittens Game》网页自动化插件(就是外挂),可以在页面->选项->MoeScript中开启/关闭自动化功能 // @version 0.14.5 // @author jiang // @author visnz // @match https://likexia.gitee.io/cat-zh/* // @match https://zhaolinxu.github.io/cat-zh/* // @grant GM_addStyle // @license GPL-3.0 // // @downloadURL https://update.greasyfork.icu/scripts/523304/%E7%8C%AB%E5%9B%BD%E5%BB%BA%E8%AE%BE%E8%80%85%E6%8C%82%E6%9C%BA%E6%8F%92%E4%BB%B6.user.js // @updateURL https://update.greasyfork.icu/scripts/523304/%E7%8C%AB%E5%9B%BD%E5%BB%BA%E8%AE%BE%E8%80%85%E6%8C%82%E6%9C%BA%E6%8F%92%E4%BB%B6.meta.js // ==/UserScript== // // 因为使用了中文作为函数名,在脚本这边只使用经过优化处理的js代码。 // 源码可以直接访问上方 @namespace 地址 // frok from: https://github.com/visnz/moescript // 基于@visnz的版本进行了二开,做一些符合个人喜好的改动,以及适配新的网址 // // 下面是声明变量: // $ - jquery的简写 - 页面自带jquery,不知道原作者为什么要引入,这里将@require中的jquery移除,使用页面中的jquery // gamePage - 页面中自带的gamePage对象 /* global $ */ /* global gamePage */ var __defProp = Object.defineProperty; var __typeError = (msg) => { throw TypeError(msg); }; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); var _ratio, _ratio2, _to; const RESOURCE_INITIAL_INFO = [ { "name": "catnip", "title": "猫薄荷", "type": "common" }, { "name": "wood", "title": "木材", "type": "common" }, { "name": "minerals", "title": "矿物", "type": "common" }, { "name": "coal", "title": "煤", "type": "common" }, { "name": "iron", "title": "铁", "type": "common" }, { "name": "titanium", "title": "钛", "type": "common" }, { "name": "gold", "title": "黄金", "type": "common" }, { "name": "oil", "title": "石油", "type": "common" }, { "name": "uranium", "title": "铀", "type": "common" }, { "name": "unobtainium", "title": "难得素", "type": "common" }, { "name": "antimatter", "title": "反物质", "type": "common" }, { "name": "manpower", "title": "喵力", "type": "common" }, { "name": "science", "title": "科学", "type": "common" }, { "name": "culture", "title": "文化", "type": "common" }, { "name": "faith", "title": "信仰", "type": "common" }, { "name": "kittens", "title": "猫口", "type": "common" }, { "name": "zebras", "title": "斑马", "type": "common" }, { "name": "starchart", "title": "星图", "type": "common" }, { "name": "temporalFlux", "title": "时间通量", "type": "common" }, { "name": "gflops", "title": "浮点", "type": "common" }, { "name": "hashrates", "title": "哈希率", "type": "common" }, { "name": "furs", "title": "毛皮", "type": "uncommon" }, { "name": "ivory", "title": "象牙", "type": "uncommon" }, { "name": "spice", "title": "香料", "type": "uncommon" }, { "name": "unicorns", "title": "独角兽", "type": "rare" }, { "name": "alicorn", "title": "天角兽", "type": "rare" }, { "name": "necrocorn", "title": "死灵兽", "type": "rare" }, { "name": "tears", "title": "眼泪", "type": "rare" }, { "name": "karma", "title": "业", "type": "rare" }, { "name": "paragon", "title": "领导力", "type": "common" }, { "name": "burnedParagon", "title": "燃烧领导力", "type": "common" }, { "name": "timeCrystal", "title": "时间水晶", "type": "common" }, { "name": "sorrow", "title": "悲伤", "type": "common" }, { "name": "relic", "title": "遗物", "type": "exotic" }, { "name": "void", "title": "虚空", "type": "exotic" }, { "name": "elderBox", "title": "礼物盒", "type": "exotic" }, { "name": "wrappingPaper", "title": "包装纸", "type": "exotic" }, { "name": "blackcoin", "title": "黑币", "type": "exotic" }, { "name": "bloodstone", "title": "血石", "type": "exotic" }, { "name": "tMythril", "title": "T秘银", "type": "exotic" }, { "name": "beam", "title": "木梁", "type": "common" }, { "name": "slab", "title": "石板", "type": "common" }, { "name": "plate", "title": "金属板", "type": "common" }, { "name": "steel", "title": "钢", "type": "common" }, { "name": "concrate", "title": "混凝土", "type": "common" }, { "name": "gear", "title": "齿轮", "type": "common" }, { "name": "alloy", "title": "合金", "type": "common" }, { "name": "eludium", "title": "E合金", "type": "common" }, { "name": "scaffold", "title": "脚手架", "type": "common" }, { "name": "ship", "title": "船", "type": "common" }, { "name": "tanker", "title": "油轮", "type": "common" }, { "name": "kerosene", "title": "煤油", "type": "common" }, { "name": "parchment", "title": "羊皮纸", "type": "common" }, { "name": "manuscript", "title": "手稿", "type": "common" }, { "name": "compedium", "title": "概要", "type": "common" }, { "name": "blueprint", "title": "蓝图", "type": "common" }, { "name": "thorium", "title": "钍", "type": "common" }, { "name": "megalith", "title": "巨石", "type": "common" } ]; const resourceMap = {}; for (const value of RESOURCE_INITIAL_INFO) { resourceMap[value.title] = { name: value.name, title: value.title, type: value.type, class: `resource_${value.name}` }; } var GenerateType = /* @__PURE__ */ ((GenerateType2) => { GenerateType2["GT1"] = "craft-1pc"; GenerateType2["GT5"] = "craft-5pc"; GenerateType2["GT10"] = "craft-10pc"; GenerateType2["GT_ALL"] = "all"; return GenerateType2; })(GenerateType || {}); var operate; ((operate2) => { function getResourceInfo(resource) { const game = moe.game(); if (!game) return; const base = resourceMap[resource]; if (!base) { moe.log.console(`资源【${resource}】不存在`); return; } const res = game.resPool.resourceMap[base.name]; if (!res) { moe.log.console(`资源【${resource}】不存在`); return; } return { resource, value: res.value, maxValue: res.maxValue, tickCached: res.perTickCached }; } operate2.getResourceInfo = getResourceInfo; function getResourceRatio(resource) { const ri = getResourceInfo(resource); if (!ri) return NaN; return ri.value / ri.maxValue; } operate2.getResourceRatio = getResourceRatio; function generateResource(resource, type) { const base = resourceMap[resource]; if (!base) { moe.log.console(`资源【${resource}】不存在`); return; } $(`div.craft.${base.class} .${type}`).click(); } operate2.generateResource = generateResource; function getActiveTab() { return $(".activeTab").parent().children(".activeTab").index() + 1; } operate2.getActiveTab = getActiveTab; function changeTab(tab) { $(`a.tab:nth-child(${tab})`)[0].click(); } operate2.changeTab = changeTab; function 提拔小猫() { const game = moe.game(); game == null ? void 0 : game.village.promoteKittens(); } operate2.提拔小猫 = 提拔小猫; ((SpecialEnum2) => { SpecialEnum2[SpecialEnum2["蜥蜴"] = 0] = "蜥蜴"; SpecialEnum2[SpecialEnum2["鲨鱼"] = 1] = "鲨鱼"; SpecialEnum2[SpecialEnum2["狮鹫"] = 2] = "狮鹫"; SpecialEnum2[SpecialEnum2["娜迦"] = 3] = "娜迦"; SpecialEnum2[SpecialEnum2["斑马"] = 4] = "斑马"; })(operate2.SpecialEnum || (operate2.SpecialEnum = {})); function specialName(special) { switch (special) { case 0: return "蜥蜴"; case 1: return "鲨鱼"; case 2: return "狮鹫"; case 3: return "娜迦"; case 4: return "斑马"; default: throw new Error("未知的特殊种族"); } } operate2.specialName = specialName; function trade(special) { const game = moe.game(); game == null ? void 0 : game.diplomacy.trade(game.diplomacyTab.racePanels[special].race); } operate2.trade = trade; function tradeAll(special) { const game = moe.game(); game == null ? void 0 : game.diplomacy.tradeAll(game.diplomacyTab.racePanels[special].race); } operate2.tradeAll = tradeAll; })(operate || (operate = {})); const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); const options = {}; let verifyOptions = function() { return true; }; var option$a; ((option2) => { const sec = (s) => s * 1e3; const min = (m) => m * sec(60); const hour = (h) => h * min(60); ((Period2) => { Period2[Period2["S0立即执行"] = sec(0)] = "S0立即执行"; Period2[Period2["S5秒"] = sec(5)] = "S5秒"; Period2[Period2["S15秒"] = sec(15)] = "S15秒"; Period2[Period2["S30秒"] = sec(30)] = "S30秒"; Period2[Period2["M1分钟"] = min(1)] = "M1分钟"; Period2[Period2["M5分钟"] = min(5)] = "M5分钟"; Period2[Period2["M10分钟"] = min(10)] = "M10分钟"; Period2[Period2["H1小时"] = hour(1)] = "H1小时"; })(option2.Period || (option2.Period = {})); function regiterOption(option3) { if (options[option3.flag]) { verifyOptions = function() { alert(`${moe.log.PREFIX}无法运行,因为定义了重复的缓存键: ${option3.flag}`); return false; }; } else { options[option3.flag] = option3; } } option2.regiterOption = regiterOption; })(option$a || (option$a = {})); let config; function loadConfig() { const configStr = localStorage.getItem(moe.STORAGE_KEY); config = configStr ? JSON.parse(configStr) : {}; for (const key in config) { if (!options[key]) setConfig(false, key); } } const events = {}; function interval(period) { const gp = moe.game(); if (!gp || gp.isPaused) return; const opts = events[period]; if (!opts) return; for (const option2 of opts) { option2.script(true, { ...options }, { ...config }); } } function setConfig(isSet, flag2) { if (isSet) { config[flag2] = true; } else { delete config[flag2]; } localStorage.setItem(moe.STORAGE_KEY, JSON.stringify(config)); } async function setEvent(isSet, option2) { try { if (option2.period === moe.option.Period.S0立即执行) { let game = moe.game(); if (!game) await moe.waitInit(); game = moe.game(); if (!game) { alert(`${moe.log.PREFIX}无法完成初始化,因为游戏在10s内未加载完成。请排查网络或禁用该插件`); return; } option2.script(isSet, { ...options }, { ...config }); return; } if (isSet) { if (!events[option2.period]) { events[option2.period] = []; moe.log.console(`设置周期为${option2.period}的事件`); setInterval(() => { interval(option2.period); }, option2.period); } events[option2.period].push(option2); } else { const index = events[option2.period].findIndex((o) => o === option2); if (index >= 0) { events[option2.period].splice(index, 1); } } } finally { setConfig(isSet, option2.flag); } } function optionSelect(e) { const target = e.currentTarget; const flag2 = target.id.replace("moe-", ""); const option2 = options[flag2]; if (target.checked) { setEvent(true, option2); moe.log.game(`开启选项【${option2.name}】${option2.description.activate}`); } else { setEvent(false, option2); moe.log.game(`关闭选项【${option2.name}】${option2.description.deactivate}`); } } function moeHtml() { const OPTION_STYLES = ` .moe-tabs-header { border-bottom: 1px solid #999; margin-bottom: 15px; } .moe-tab { display: inline-block; padding: 5px 15px; margin-right: 5px; text-decoration: none; color: inherit; } .moe-tab.moe-active { border: 1px solid #999; border-bottom: none; background: #fff; } `; GM_addStyle(OPTION_STYLES); const groupedOptions = {}; for (const key in options) { const option2 = options[key]; if (groupedOptions[option2.panel]) { groupedOptions[option2.panel].push(option2); } else { groupedOptions[option2.panel] = [option2]; } } const allOperators = []; for (const panel in groupedOptions) { allOperators.push({ panel, list: groupedOptions[panel] }); } const bindClick = []; const optionHtml = allOperators.map((operator) => { operator.list.sort((a, b) => { return (a.index || 9999) - (b.index || 9999); }); const optionsHtml = operator.list.map((option2) => { const id = `moe-${option2.flag}`; bindClick.push(() => { $(`#${id}`).on("click", optionSelect); if (config[option2.flag]) $(`#${id}`).click(); }); return ` ${option2.name} `; }).join(""); return `