CookieClicker自动点击脚本

CookieClicker自动点击脚本

Artificial-Fool Lv3

因为一直等实在太折磨了,所以写了一个自动脚本。

可以自动连点cookie、随机升建筑和升级(不过暂时没有智能),还可以狙击幸运饼干。

1.0:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 2024-12-14
// @description try to take over the world!
// @author You
// @match https://orteil.dashnet.org/cookieclicker/
// @icon https://www.google.com/s2/favicons?sz=64&domain=dashnet.org
// @grant none
// ==/UserScript==

(function() {
'use strict';
// 提供一个简单的界面来启动/停止自动点击
(function() {
const button = document.createElement('button');
button.innerText = '启动自动点击';
button.style.position = 'fixed';
button.style.top = '33px';
button.style.right = '17px';
button.style.zIndex = '10001';

button.addEventListener('click', () => {
if (isClicking) {
stopAutoClick();
button.innerText = '启动自动点击';
button.style.background='';
button.style.color = ''

} else {
startAutoClick();
button.innerText = '停止自动点击';
button.style.background='black';
button.style.color = 'rgb(0,255,0)'
}
});

const button_A = document.createElement('button');
button_A.innerText = 'A';
button_A.style.position = 'fixed';
button_A.style.top = '57px';
button_A.style.right = '97px';
button_A.style.width = '12px';
button_A.style.padding = '1px';
button_A.style.zIndex = '10001';

button_A.addEventListener('click', () => {
if (isClickingA) {
isClickingA = false;
button_A.style.background = '';
button_A.style.color = '';
} else {
isClickingA = true;
button_A.style.background = 'black';
button_A.style.color = 'rgb(0,255,0)';
}
});

const input = document.createElement('input');
input.type = 'number';
input.id='inputNumber';
input.style.position = 'fixed';
input.style.top = '55px';
input.style.right = '17px';
input.style.zIndex = '10000';
input.style.width='35px';
input.style.background='#ffffff';
input.placeholder = 'index..';
input.value = localStorage.getItem('inputNum');
input.min = '1';

const input_side = document.createElement('input');
input_side.type = 'number';
input_side.id = 'inputNumberSide';
input_side.style.position = 'fixed';
input_side.style.top = '55px';
input_side.style.right = '58px';
input_side.style.zIndex = '10000';
input_side.style.width = '30px';
input_side.style.background = '#ffffff';
input_side.placeholder = 'n..';
input_side.value = localStorage.getItem('inputNumSide');
input_side.min = '1';

document.body.appendChild(button);
document.body.appendChild(button_A);
document.body.appendChild(input);
document.body.appendChild(input_side);
})();
// 定义一个函数来启动/停止自动点击
let intervalId;
let isClicking = false;
let isClickingA = false;
let input =document.getElementById('inputNumber');
let input_side =document.getElementById('inputNumberSide')

function startAutoClick() {
if (isClicking) return; // 如果已经在点击,直接返回

isClicking = true;
intervalId = setInterval(() => {
const inputNum = input.valueAsNumber;
const inputNumSide = input_side.valueAsNumber;
localStorage.setItem('inputNum', `${inputNum}`);
localStorage.setItem('inputNumSide', `${inputNumSide}`);
const productId = `product${Math.trunc(Math.random()*inputNumSide)+inputNum-1}`;
console.log(inputNum,productId);
document.getElementById('bigCookie').click();
document.getElementById(productId).click();
if (isClickingA) document.getElementById('upgrade0').click();
const shimmer = document.querySelector('.shimmer');
if (shimmer !== null) {
shimmer.click();
console.log('shimmer found!');
}
}, 100); // 每 100 毫秒点击一次
}

function stopAutoClick() {
if (!isClicking) return; // 如果没有在点击,直接返回

clearInterval(intervalId);
isClicking = false;
console.log('停止了自动点击');
}



// Your code here...
})();

这下可以自动farm了…

2.0

#有bug

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 2024-12-14
// @description try to take over the world!
// @author You
// @match https://orteil.dashnet.org/cookieclicker/
// @icon https://www.google.com/s2/favicons?sz=64&domain=dashnet.org
// @grant none
// ==/UserScript==

(function () {
('use strict');
(function () {
const button = document.createElement('button');
button.innerText = '启动自动点击';
button.style.position = 'fixed';
button.style.top = '33px';
button.style.right = '17px';
button.style.zIndex = '10001';

button.addEventListener('click', () => {
if (isClicking) {
stopAutoClick();
button.innerText = '启动自动点击';
button.style.background = '';
button.style.color = '';
} else {
startAutoClick();
button.innerText = '停止自动点击';
button.style.background = 'black';
button.style.color = 'rgb(0,255,0)';
}
});

const button_A = document.createElement('button');
button_A.innerText = 'A';
button_A.style.position = 'fixed';
button_A.style.top = '57px';
button_A.style.right = '97px';
button_A.style.width = '12px';
button_A.style.padding = '1px';
button_A.style.zIndex = '10001';

button_A.addEventListener('click', () => {
if (isClickingA) {
isClickingA = false;
button_A.style.background = '';
button_A.style.color = '';
} else {
isClickingA = true;
button_A.style.background = 'black';
button_A.style.color = 'rgb(0,255,0)';
}
});

const input = document.createElement('input');
input.type = 'number';
input.id = 'inputNumber';
input.style.position = 'fixed';
input.style.top = '55px';
input.style.right = '17px';
input.style.zIndex = '10000';
input.style.width = '35px';
input.style.background = '#ffffff';
input.placeholder = 'index..';
input.value = localStorage.getItem('inputNum');
input.min = '0';
input.max = '19';

const input_side = document.createElement('input');
input_side.type = 'number';
input_side.id = 'inputSideNumber';
input_side.style.position = 'fixed';
input_side.style.top = '55px';
input_side.style.right = '58px';
input_side.style.zIndex = '10000';
input_side.style.width = '30px';
input_side.style.background = '#ffffff';
input_side.placeholder = 'n..';
input_side.value = localStorage.getItem('inputNumSide');
input_side.min = '0';
input_side.max = '19';

document.body.appendChild(button);
document.body.appendChild(button_A);
document.body.appendChild(input);
document.body.appendChild(input_side);
})();

let intervalId;
let isClicking = false;
let isClickingA = false;
let input = document.getElementById('inputNumber');
let input_side = document.getElementById('inputSideNumber');

function parseLargeNumberString(str) {
// 定义单位映射,支持更大的单位
const unitMap = {
thousand: 1e3, // 1,000
million: 1e6, // 1,000,000
billion: 1e9, // 1,000,000,000
trillion: 1e12, // 1,000,000,000,000
quadrillion: 1e15, // 1,000,000,000,000,000
quintillion: 1e18, // 1,000,000,000,000,000,000
sextillion: 1e21, // 1,000,000,000,000,000,000,000
septillion: 1e24, // 1,000,000,000,000,000,000,000,000
octillion: 1e27, // 1,000,000,000,000,000,000,000,000,000
nonillion: 1e30, // 1,000,000,000,000,000,000,000,000,000,000
decillion: 1e33, // 1,000,000,000,000,000,000,000,000,000,000,000
};

// 将字符串转换为小写并去除首尾空格
str = str.toLowerCase().trim();

// 匹配更复杂的数字格式(允许逗号分隔符、负数、小数)
const match = str.match(/^(-?\d+(\.\d+)?|\.\d+)\s*(\w+)?$/);

if (!match) {
throw new Error('Invalid input format');
}

// 提取数字和单位
const [_, numberStr, , unit] = match;

// 去除逗号
const cleanNumberStr = numberStr.replace(/,/g, '');

// 将字符串转换为数值
const number = parseFloat(cleanNumberStr);

// 如果没有单位,默认返回数字本身
if (!unit || unit === '') {
return number;
}

// 检查单位是否有效(仅包含字母)
if (!/^[a-z]+$/.test(unit)) {
throw new Error(`Invalid unit: ${unit}`);
}

// 检查单位是否存在于映射中
if (!(unit in unitMap)) {
throw new Error(`Unknown unit: ${unit}`);
}

// 计算最终值
const result = number * unitMap[unit];

return result;
}

function startAutoClick() {
if (isClicking) return;
isClicking = true;
intervalId = setInterval(() => {
let productPriceArray = [];
const inputNum = input.valueAsNumber;
const inputNumSide = input_side.valueAsNumber;
localStorage.setItem('inputNum', `${inputNum}`);
localStorage.setItem('inputNumSide', `${inputNumSide}`);

if (inputNumSide > inputNum) input.value = inputNumSide;

for (let i = inputNum; i >= inputNumSide; i--) {
productPriceArray.unshift(
BigInt(
parseLargeNumberString(
document.getElementById(`productPrice${i}`).textContent
)
)
);
}
for (let i = 0; i < productPriceArray.length; i++) {
console.log(
productPriceArray[i] /
BigInt(2 ** i) /
(productPriceArray[productPriceArray.length - 1] /
BigInt(2 ** (productPriceArray.length - 1)))
);
productPriceArray[i] =
productPriceArray[i] / BigInt(2 ** i) <
productPriceArray[productPriceArray.length - 1] /
BigInt(2 ** (productPriceArray.length - 1));
}
console.log(productPriceArray);
for (let i = inputNum; i >= inputNumSide; i--) {
if (productPriceArray[i + inputNumSide]) {
document.getElementById(`product${i}`).click();
console.log(`点击了product${i}`);
break;
}
//console.log(productId);
}
//const productId = `product${Math.trunc(Math.random()*inputNumSide)+inputNum}`;
//console.log(inputNum,productId);
document.getElementById('bigCookie').click();
if (isClickingA) document.getElementById('upgrade0').click();
const shimmer = document.querySelector('.shimmer');
if (shimmer !== null) {
shimmer.click();
console.log('shimmer found!');
}
}, 100);
}

function stopAutoClick() {
if (!isClicking) return;

clearInterval(intervalId);
isClicking = false;
console.log('停止了自动点击');
}
})();

  • Title: CookieClicker自动点击脚本
  • Author: Artificial-Fool
  • Created at : 2024-12-14 22:41:43
  • Updated at : 2024-12-17 10:14:25
  • Link: https://space.bilibili.com/636023121/2024/12/14/cookieclicker/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
CookieClicker自动点击脚本