3 ms·
My "speedrun": var simulateClick = function (elem) { // Create our event (with options) var evt = new MouseEvent('click', { bubbles: true, canc
by klenwell 4y ago
My "speedrun":
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)
- chrismorgan 4y agoMy tool-assisted speedrun (0.001s): 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.
- dhab 4y agoI went with a manual-mix approach: 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.268
- chrismorgan 4y agoDunno quite what your idea was with canceled: your comment doesn’t match behaviour at all. As for dispatching a click event, you can just use .click(). Your 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.
- ssharp 4y agoBrute approach (This doesn't account for whether a checkbox is checked or not so I don't actually know if the game prevents everything getting checked programmatically all at once. I had to set the setTimeout to "2" instead of "1" so it would actually record some 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); } }
- jxcole 4y agoIf you're going to cheat why not all the way: 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; });