From c7f4d8fa04f3df2c486f02d3684812ca7627863f Mon Sep 17 00:00:00 2001 From: Ozoniuss Date: Mon, 23 Dec 2024 00:22:22 +0200 Subject: [PATCH] Add hack for color find website --- colorfind-hack/README.md | 11 ++++++++ colorfind-hack/main.js | 60 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 colorfind-hack/README.md create mode 100644 colorfind-hack/main.js diff --git a/colorfind-hack/README.md b/colorfind-hack/README.md new file mode 100644 index 0000000..77bcc7c --- /dev/null +++ b/colorfind-hack/README.md @@ -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. diff --git a/colorfind-hack/main.js b/colorfind-hack/main.js new file mode 100644 index 0000000..ae7c18f --- /dev/null +++ b/colorfind-hack/main.js @@ -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()