Автоматизация печенек

mail@pastecode.io avatar
unknown
javascript
7 months ago
5.3 kB
1
Indexable
Never
// Настройки скрипта
const speed = 1000 // 1000 = 1 секунда, 2000 = 2 секунды и т.д. рекомендуется не менее 200мс
const startCookieLevel = 1 // Начальный уровень печенья
const finalCookieLevel = 50 // Конечный уровень печенья (это печенье будет удалено в конце цикла)
const repeatTimes = 10 // Сколько раз вы хотите выполнить задание

// Service variables (DO NOT CHANGE)
let iteration = 1;

// Buy new cookies (DO NOT CHANGE)
async function shop() {
    return new Promise((resolve) => {
        const cookies = document.querySelectorAll('.menu-shop-item img:not([src^="data:"])')
        const numbers = []
        console.log('Processing buy new cookies...')

        for (let i = startCookieLevel - 1; i < finalCookieLevel; i++) {
            const cookie = cookies[i]
            const imageUrl = cookie.src
            const regex = /\/(\d+)\./
            const match = imageUrl.match(regex ?? 'null')
            const number = match ? match[1] : null

            if (number) {
                numbers.push(number)
            }
        }

        console.log('Buy new cookies: ', numbers)
        // Start buying (DO NOT CHANGE)
        numbers.forEach((number, index) => {
            const element = document.querySelector(`img[src*="/${number}."]`)
            // First level biscuit clicked twice (DO NOT CHANGE)
            if (parseInt(number) === startCookieLevel) {
                setTimeout(() => {
                    element.click()
                    setTimeout(() => {
                        element.click()
                    }, speed)
                }, index * speed)
            } else {
                setTimeout(() => {
                    element.click()
                }, index * speed)
            }
        })

        setTimeout(() => {
            resolve()
            console.log(`Iteration #${iteration} completed`)
            console.log('='.repeat(50))
        }, numbers.length * speed)
    })
}

// Call the function several times
(async function () {
    for (let i = 0; i < repeatTimes; i++) {
        await shop()
        iteration++
    }

    console.log('All iterations completed')
})()

// Union all and delete final biscuit
async function swipeBiscuits() {

    const biscuits = document.querySelectorAll('.biscuit-item')

    biscuits.forEach((biscuit) => {
        const biscuitNumber = extractBiscuitNumber(biscuit)

        if (biscuitNumber) {
            const targetBiscuitNumber = biscuitNumber
            const targetBiscuit = document.querySelector(`.biscuit-icon-type-${targetBiscuitNumber}`)
            if (targetBiscuit) {
                const biscuitRect = biscuit.getBoundingClientRect()
                const biscuitCenterX = biscuitRect.left + biscuitRect.width / 2
                const biscuitCenterY = biscuitRect.top + biscuitRect.height / 2

                const targetRect = targetBiscuit.getBoundingClientRect()
                const targetCenterX = targetRect.left + targetRect.width / 2
                const targetCenterY = targetRect.top + targetRect.height / 2

                biscuit.dispatchEvent(
                    new MouseEvent('mousedown', {
                        bubbles: true,
                        cancelable: true,
                        clientX: biscuitCenterX,
                        clientY: biscuitCenterY,
                    })
                )

                biscuit.dispatchEvent(
                    new MouseEvent('mousemove', {
                        bubbles: true,
                        cancelable: true,
                        clientX: targetCenterX,
                        clientY: targetCenterY,
                    })
                )

                if (biscuitNumber === finalCookieLevel) {
                    const garbage = document.querySelector('#garbage.garbage-area')
                    if (garbage) {
                        const garbageRect = garbage.getBoundingClientRect()
                        const garbageCenterX = garbageRect.left + garbageRect.width / 2
                        const garbageCenterY = garbageRect.top + garbageRect.height / 2

                        biscuit.dispatchEvent(
                            new MouseEvent('mousemove', {
                                bubbles: true,
                                cancelable: true,
                                clientX: garbageCenterX,
                                clientY: garbageCenterY,
                            })
                        )
                    }
                }

                targetBiscuit.dispatchEvent(
                    new MouseEvent('mouseup', {
                        bubbles: true,
                        cancelable: true,
                        clientX: targetCenterX,
                        clientY: targetCenterY,
                    })
                )
            }
        }
    })
}


function extractBiscuitNumber(biscuit) {
    const className = biscuit.className
    const numberRegex = /biscuit-icon-type-(\d+)/
    const match = className.match(numberRegex)
    if (match) {
        return parseInt(match[1])
    }
    return null
}

setInterval(swipeBiscuits, speed)
Leave a Comment