Skip to content

Commit

Permalink
Add hack for color find website
Browse files Browse the repository at this point in the history
  • Loading branch information
Ozoniuss committed Dec 22, 2024
1 parent 7fedb41 commit c7f4d8f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
11 changes: 11 additions & 0 deletions colorfind-hack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
A very simple hack for https://5jqdmjxdwavv.trickle.host/

All developer tools shortcuts have probably been bound to different functions,
as they don't seem to work. You need to open them manually from your browser.
Also, set the debugger's "Pause on debugger statement" setting to off, otherwise
opening the tools would trigger the debugger.

For more, search for `detectDevTools` in the source.

Script will detect the square that has a different color and print the distance
between it and the other colors.
60 changes: 60 additions & 0 deletions colorfind-hack/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function distance(s1, s2) {
const l1 = s1.indexOf('(')
const r1 = s1.indexOf(')')
const ss1 = s1.slice(l1+1, r1)

const l2 = s2.indexOf('(')
const r2 = s2.indexOf(')')
const ss2 = s2.slice(l2+1, r2)



const p1 = ss1.split(", ")
const p2 = ss2.split(", ")

return Math.sqrt(
(parseFloat(p1[0]) - parseFloat(p2[0])) * (parseFloat(p1[0]) - parseFloat(p2[0])) +
(parseFloat(p1[1]) - parseFloat(p2[1])) * (parseFloat(p1[1]) - parseFloat(p2[1])) +
(parseFloat(p1[2]) - parseFloat(p2[2])) * (parseFloat(p1[2]) - parseFloat(p2[2]))
)
}
async function findUnique() {
const cells = document.getElementsByClassName("grid-cell")
const colorCount = {}

for (const c of cells) {
const bgColor = c.style["background-color"]
colorCount[bgColor] = (colorCount[bgColor] || 0) + 1
}

let same = null
let different = null
for (const color in colorCount) {
if (colorCount[color] === 1) {
different = color
} else {
same = color
}
}
console.log("distance", distance(same, different))

let toclick = null
for (const c of cells) {
if (c.style["background-color"] === different) {
toclick = c
break
}
}

toclick.click()
await new Promise(resolve => setTimeout(resolve, 100))
}

async function run() {
const n = 1_000_000
for (let i = 0; i < n; i++) {
await findUnique()
}
}

// run()

0 comments on commit c7f4d8f

Please sign in to comment.