Checkbox Olympics
checkboxolympics.com
checkboxolympics.com
In a weird way this reminds me of the old 80s "epyx" sports game which seemed to involve typeing keys as fast as you can.
var simulateClick = function (elem) {
// Create our event (with options)
var evt = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
// If cancelled, don't dispatch our event
var canceled = !elem.dispatchEvent(evt);
};
var run = () => {
var el = document.querySelector('input[type=checkbox]:not(:checked)')
simulateClick(el)
}
setInterval(run, 100) let setGo = document.querySelector(".setGo");
let observer = new MutationObserver(mutations => {
if (setGo.classList.contains("going")) {
for (const { target } of mutations) {
if (target.checked == target.disabled) {
target.click();
}
}
}
});
observer.observe(setGo, {attributes: true});
document.querySelectorAll(".theSport input").forEach(checkbox => {
observer.observe(checkbox, {attributes: true});
});
Explanation: instead of messing about with timers, it asks to be informed when any attribute changes (could use attributeFilter to only hear about "class" for setGo and "disabled" for checkboxes, but I didn’t bother). This is faster than can be acheived with setTimeout, setInterval or requestAnimationFrame, as timers are deliberately speed-capped. (Whereas mutation observers create microtasks, so we can go through this whole thing in one frame.)When the observer gets notified (in a microtask), it checks if we’re going (in order to avoid false starts), and then goes through the checkboxes it’s been told just changed, and checks if they’re enabled and unchecked, and clicks them. In practice, the first mutation will come in with mutation records for setGo and the first checkbox, which we’ll click, which will trigger an event (a task) from the page code which enables the second checkbox, which will trigger an immediate mutation notification (a microtask), &c. until it’s all done, without ever rendering a frame in the meantime.
var boxes = document.querySelectorAll("#root > div > div.sportsWrapper > div.theSport > div:nth-child(2) > input[type=checkbox]")
Then "start", wait for go signal while getting the code below ready on console. on go run the code: boxes.forEach(b => b.click())
Got: Time: 0.268Your speedrun code can be reduced to this:
setInterval(() => document.querySelector('input[type=checkbox]:not(:checked)').click(), 100)
It would be significantly improved by the addition of :enabled and then reduction of interval time. document.querySelector('.readyButton').click();
waitForStart();
function waitForStart() {
if (document.querySelector('.setGo').classList.value.includes("going")) {
for(x=0; x<document.querySelectorAll('input[type="checkbox"]').length; x++) { document.querySelectorAll('input[type="checkbox"]')[x].click(); }
}
else { setTimeout(waitForStart, 2); }
} document.querySelector(".time").innerHTML = '<b>Time:</b> 0.0001';
Array.from(document.querySelectorAll(".theSport input[type='checkbox']"))
.forEach(e => { e.disabled = false; e.checked = true; }); $('.readyButton').click(); setTimeout(()=> [...document.querySelectorAll('input[type="checkbox"]')].map(cb => cb.click()), 3000)
This gives me 0.143 in Safari which is just a proof that DOM is freaking slow haha! (() => {
const targ = $(".setGo");
const targ2 = $(".theSport > div:nth-child(2)");
const observer = new MutationObserver((mutations, observer) => {
if (mutations[0]?.target?.classList.contains('going')) {
targ2.childNodes.forEach(c => c.click());
}
});
observer.observe(targ, {
subtree: false,
attributes: true
});
$('.readyButton').click()
})();
This gives me consistent Time: 0.001 in FF. "Time: not yet set" in Edge/Chrome.I wonder if he renews them on the cheap somehow, either way there are some really funny ones in there
import pyautogui as m
from fastgrab import screenshot
m.PAUSE = 0
while 1:
x, y = m.position()
r, g, b, _ = screenshot.Screenshot().capture((x, y, 1, 1))[0][0]
if (r, g, b) in ((50, 205, 50), (127, 224, 127)):
break
m.moveRel(-35, 105)
for _ in range(27):
m.click()
m.moveRel(23, 0)
m.click()
My record is 0.03 in FFEDIT: 0.02 in Chromium
But yeah you are right.
let observer = new MutationObserver(mutations => {
for (const { target } of mutations) {
if (target.checked == target.disabled) {
target.click();
}
}
});
document.querySelectorAll("[type=checkbox]").forEach(checkbox => {
observer.observe(checkbox, {attributes: true});
});
Then click on the first checkbox and it’ll do all of the rest. Time varies a bit, best I’ve done in a couple of dozen attempts is 00:00:03.I'm using a Sanwa Supply one now
Looks like it might be a ploopy with BTS instead of their rollerbearings.
Because once a minesweeper addict has reached a certain base level of skill, the strategy part stops to be about where the mines are, it becomes all about reordering the click queue for speed. (don't ask me how I know)
110 Meter Hurdles 18.85
Total Time: 37.359
with a mouse on desktop chrome.
- https://news.ycombinator.com/item?id=30517626
Under normal circumstances I don't like websites to try to mess with selection, copynpaste, ... but in this case it would be both helpful and justified.
edit 1: 9.004 at my pixel, i am mobile gamer now! pog
edit 2: 6.446 on phone !
1) the hit area of native checkboxes should be larger, and
2) fieldsets with checkboxes should come with a native "Toggle All" button
That's me knocked out in the qualifying rounds of the checkbox olympics ;-)