-
Notifications
You must be signed in to change notification settings - Fork 1
/
elemental4.js
203 lines (162 loc) · 5.15 KB
/
elemental4.js
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
/******************************************
Never gonna give you up!
Never gonna let you down!
Never gonna turn around and... desert you!
Ha :)
---------------------------
Creates new elements for you by brute force. See https://elemental4.net/
1. Create a new save. (optional)
2. (ctrl+shift+i opens the console in my browser)
Open the console in the elemental4 tab.
Copy and paste all of the code in that console.
Note: generally copying and pasting code is dangerous.
For example, _you_ can access your password... and code has the ability to click...
3. Anyways, after that, type _one_ of the following:
step()
stepForever()
1b: There's also a handy function for that:
createNewSave()
*/
// You can change this! However if the number is too low (say, 0ms), the browser just replaces it with a minimum.
let delay = 10 // milliseconds
function getElements () {
return Array.from(document.querySelectorAll('#element-game-root .elem'))
}
function getNewElements () {
return getElements().filter(element => !seen.has(element))
}
function click (something) {
let clickEvent = new MouseEvent('click')
something.dispatchEvent(clickEvent)
}
function slowDown () {
return new Promise(finish =>
setTimeout(finish, delay)
)
}
async function tryCombination (elem1, elem2) {
// Unselect any elements
click(document.body)
// Then click elem1 and elem2
click(elem1)
click(elem2)
}
async function closeSuggestionBoxIfAny () {
const suggestionClose = document.querySelector('#suggest .suggest-close')
if (suggestionClose !== null) {
click(suggestionClose)
}
}
let seen = new Set(getElements())
let tiers = [getElements()]
let currentStep = [0, 0] // tier 0 vs tier 0
function howManyCombinations () {
if (currentStep[0] !== currentStep[1]) {
return tiers[currentStep[0]].length *
tiers[currentStep[1]].length
} else {
// If they're the same, you don't need to check both A vs B and B vs A
// No optimization if they're different though
return (
tiers[currentStep[0]].length *
(tiers[currentStep[0]].length + 1)
) / 2
}
}
let _stop = false
async function step () {
if (currentStep[1] >= tiers.length || _stop) {
_stop = true
return;
}
console.group(`"Tier" ${currentStep[0]} vs ${currentStep[1]}`)
console.log(`${howManyCombinations()} combinations`)
for (const element1 of tiers[currentStep[0]]) {
for (const element2 of tiers[currentStep[1]]) {
if (_stop) {
return
}
if (currentStep[0] === currentStep[1]) {
// Don't need to check both (A vs B) and (B vs A)
if (tiers[currentStep[0]].indexOf(element1) > tiers[currentStep[1]].indexOf(element2)) {
continue;
}
}
// only slowdown half the time
if (Math.random() < 0.5) {
await slowDown()
}
await tryCombination(element1, element2)
await closeSuggestionBoxIfAny()
}
}
// Update current step
// Does combos like this:
/*
* 0 0
* 0 1
* 1 1
* 0 2
* 1 2
* 2 2
* 0 3
* 1 3
* 2 3
* 3 3
* 0 4
* etc
*/
if (currentStep[0] === currentStep[1]) {
currentStep = [0, currentStep[1] + 1]
} else {
currentStep[0]++
}
let newElements = getNewElements()
if (newElements.length) {
for (const element of newElements) {
seen.add(element)
}
tiers.push(newElements)
}
console.log(`Created ${newElements.length} new elements (Tier ${tiers.length - 1})`)
console.groupEnd()
}
async function stepForever () {
_stop = false
while (!_stop) {
await step()
}
}
function stop () {_stop = true}
function lastOf (something) {
return something[something.length - 1]
}
async function createNewSave () {
delay = 1000
// Click menu
click(document.querySelector('.top-bar > .top-bar-button'))
await slowDown()
// Click 3rd option (index 2; computers count from 0)
click(document.querySelector('.settings-categories').children[2])
await slowDown()
// Create new file
// 1. Change option to "create"
document.getElementById('modify-savefile').selectedIndex =
[].indexOf.call(
document.getElementById('modify-savefile').children,
document.getElementById('modify-savefile-create')
)
document.getElementById('modify-savefile').dispatchEvent(new Event('change'))
await slowDown()
// 2. Change name, click "Ok" or something
document.querySelector('.dialog-form input').value += ': brute force!!!'
click(document.querySelector('.dialog-buttons').children[0])
await slowDown()
// Then change file to new file just created
document.getElementById('change-savefile').selectedIndex = document.getElementById('change-savefile').options.length - 1
document.getElementById('change-savefile').dispatchEvent(new Event('change'))
await slowDown()
// Exit the menu
click(lastOf(document.querySelector('.settings-categories').children))
delay = 10
}