// ==UserScript== // @name 我的文字修仙全靠刷之随身老爷爷 // @namespace Violentmonkey Scripts // @match https://xiuxian.jntm.cool/ // @grant none // @version 1.0 // @author - // @description 2024/7/31 10:36:02 // @license MIT // @downloadURL none // ==/UserScript== (function () { 'use strict'; class Interval { constructor(fun, speed) { this.fun = fun this.speed = speed this.id = null this.runing = false } start () { console.log('start') if (this.id) { return } this.runing = true this.id = setInterval(this.fun, this.speed) } stop () { console.log('Interval.stop()') if (this.id) { this.runing = false clearInterval(this.id) console.log(`Interval.stop() : clearInterval(${this.id})`) this.id = null } } } class LinkInterval extends Interval { constructor(linkList, speed, one = true, startClickButtonList = [], endClickButtonList = []) { super(null, speed) this._run = this._run.bind(this) super.fun = this._run this.startClickButtonList = startClickButtonList this.startClickButtonListLength = startClickButtonList.length this.startClickButtonListIndex = 0 this.endClickButtonList = endClickButtonList this.endClickButtonListLength = endClickButtonList.length this.endClickButtonListIndex = 0 this.linkList = linkList this.linkListLength = linkList.length this.one = one this.linkListIndex = 0 this.next = null this._handleAfter = () => { } this.excNext = true } setHandleAfter (fun) { this._handleAfter = fun this._handleAfter = this._handleAfter.bind(this) } start (excNext = true) { this.excNext = excNext this.startClickButtonListIndex = 0 this.endClickButtonListIndex = 0 this.linkListIndex = 0 super.start() } stop () { console.log('LinkInterval.stop()') if (this.endClickButtonListIndex < this.endClickButtonListLength) { this.runing = false return } super.stop() if (this.next && this.next.runing) { this.next.stop() } } linkNext (next) { this.next = next return this } nextInterval () { console.log(`执行下一定时器${this.next}`) this.stop() if (!super.runing && this.next) { this.next.start() } } _run () { if (!this.runing && this.endClickButtonListIndex >= this.endClickButtonListLength) { super.stop() return } let item = null, curIndex = 0 if (!this.runing && this.endClickButtonListIndex < this.endClickButtonListLength) { curIndex = this.endClickButtonListIndex++ item = this.endClickButtonList[curIndex] } else if (this.startClickButtonListIndex < this.startClickButtonListLength) { curIndex = this.startClickButtonListIndex++ item = this.startClickButtonList[curIndex] } else { curIndex = (this.linkListIndex++) % this.linkListLength console.log(`当前次数:${this.linkListIndex}`) item = this.linkList[curIndex] } let cbs = findClickButton(item) if (cbs) { for (const cb of cbs) { console.log(`[${item}]元素点击。`) cb.click() } } else { console.warn(`未找到[${item}]元素。`) } this._handleAfter(this.linkListLength, this.linkListIndex) if (this.one == true && curIndex === (this.linkListLength - 1)) { if (this.excNext) { this.nextInterval() } else { this.stop() this.excNext = true } } } } const cultivateClickButtonList = [ 'it>开始修炼', 'it>继续修炼', 'it>突破境界' ] const batchClickButtonList = [ 'it>探索秘境', 'it>发起战斗', 'it>继续探索' ] const sellClickButtonList = [ '.setting', 'it>出售装备', 'body > div.game-container-wrapper > div:nth-child(4) > div > div.el-dialog__body > div.dialog-footer > button', 'body > div.game-container-wrapper > div:nth-child(4) > div > div.el-dialog__header > button' ] let speed = 1000 let sellFrequency = 1024 const cultivateInterval = new LinkInterval(cultivateClickButtonList, speed, false) const autoInterval = new LinkInterval(batchClickButtonList, speed, false) const sellInterval = new LinkInterval(sellClickButtonList, speed) autoInterval.linkNext(sellInterval) sellInterval.linkNext(autoInterval) autoInterval.setHandleAfter((linkListLength, linkListIndex) => { if (linkListIndex % (linkListLength * sellFrequency) === 0) { autoInterval.nextInterval() } }) class GroupLinkInterval { constructor(speed) { this.map = {} this.clickButtonList = [ 'it>点击炼器', 'it>确定以及肯定' ] this.endClickButtonList = ['#el-drawer__title > button'] this.frequency = 64 this.speed = speed } add (key, startClickButtonList = []) { let interval = new LinkInterval(this.clickButtonList, this.speed, false, startClickButtonList, this.endClickButtonList) interval.setHandleAfter((linkListLength, linkListIndex) => { if (linkListIndex != 0 && linkListIndex % (linkListLength * this.frequency) == 0) { this.map[key].stop() } }) this.map[key] = interval } start (key) { this.map[key].start() } setSpeed (speed) { this.speed = speed for (const key in this.map) { this.map[key].speed = this.speed } } } setTimeout(() => { let groupLinkInterval = new GroupLinkInterval(speed) let divBox = document.createElement('div') addInput(divBox, '总速度', speed, (event) => { speed = Number(event.target.value) cultivateInterval.speed = speed autoInterval.speed = speed sellInterval.speed = speed groupLinkInterval.setSpeed(speed) }) addInput(divBox, '出售频率', sellFrequency, (event) => { sellFrequency = Number(event.target.value) }) addInput(divBox, '升级装备次数', groupLinkInterval.frequency, (event) => { groupLinkInterval.frequency = Number(event.target.value) }) // 自动探索按钮 const cultivateButtonText = ['开始自动修炼', '停止自动修炼'] const cultivateButton = addButton(divBox, cultivateButtonText[0], ['el-button'], () => { if (cultivateButton.innerText === cultivateButtonText[0]) { cultivateInterval.start() cultivateButton.innerText = cultivateButtonText[1] return } cultivateInterval.stop() cultivateButton.innerText = cultivateButtonText[0] }) // 自动探索按钮 const buttonText = ['开始自动探索', '停止自动探索'] const autoButton = addButton(divBox, buttonText[0], ['el-button'], () => { if (autoButton.innerText === buttonText[0]) { autoInterval.start() autoButton.innerText = buttonText[1] return } autoInterval.stop() autoButton.innerText = buttonText[0] }) // 出售按钮 addButton(divBox, '快捷出售', ['el-button'], () => { sellInterval.start(false) }) let groupButtonList = [ { key: '升级神兵', rule: [ 'body > div > div.game-container > div.game-box > div > div.equip-box > div:nth-child(1) > span:nth-child(1) > span.el-tag.el-tag--danger.el-tag--light' ] }, { key: '升级护甲', rule: [ 'body > div > div.game-container > div.game-box > div > div.equip-box > div:nth-child(1) > span:nth-child(2) > span.el-tag.el-tag--danger.el-tag--light' ] }, { key: '升级灵宝', rule: [ 'body > div > div.game-container > div.game-box > div > div.equip-box > div:nth-child(2) > span:nth-child(1) > span.el-tag.el-tag--danger.el-tag--light' ] }, { key: '升级法器', rule: [ 'body > div > div.game-container > div.game-box > div > div.equip-box > div:nth-child(2) > span:nth-child(2) > span.el-tag.el-tag--danger.el-tag--light' ] } ] for (const groupButton of groupButtonList) { groupLinkInterval.add(groupButton.key, groupButton.rule) addButton(divBox, groupButton.key, ['el-button'], (event) => { groupLinkInterval.start(groupButton.key) }) } const gameBox = document.querySelector('.game-box') let firstChild = gameBox.firstChild gameBox.insertBefore(divBox, firstChild) }, 1000) function findClickButton (clickButton) { if (clickButton.startsWith('it>')) { clickButton = clickButton.replace('it>', '') let buttonList = document.querySelectorAll('.el-button') for (const node of buttonList) { if (node.innerText.replaceAll(' ', '') === clickButton) { return [node] } } return null } return document.querySelectorAll(clickButton) } function addButton (box, name, classNames, onClick) { let button = document.createElement("button") button.style = 'margin-left: 4px; padding-left: 18px; padding-right: 18px; margin-top: 6px' button.classList.add(classNames) button.innerText = name button.addEventListener('click', onClick) box.appendChild(button) return button } function addInput (box, name, val, onInput) { let span = document.createElement("span") span.style = 'margin-left: 4px; margin-right: 4px; margin-top: 6px' span.innerHTML = name let input = document.createElement("input") input.style = 'height: 21px; width: 8%; text-align: center; margin-top: 6px' input.value = val input.addEventListener('input', onInput) box.appendChild(span) box.appendChild(input) return input } })();