Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I went all the way, simulated keydowns and all. (Thanks, http://stackoverflow.com/questions/4158847/is-there-a-way-to...)

var element = document.getElementById('answer');var y = document.getElementById('question');var dispatchKeyboardEvent = function(target, initKeyboradEvent_args) {var e = document.createEvent("KeyboardEvents");e.initKeyboardEvent.apply(e, Array.prototype.slice.call(arguments, 1));target.dispatchEvent(e);};var dispatchTextEvent = function(target, initTextEvent_args) {var e = document.createEvent("TextEvent");e.initTextEvent.apply(e, Array.prototype.slice.call(arguments, 1));target.dispatchEvent(e);};var dispatchSimpleEvent = function(target, type, canBubble, cancelable) {var e = document.createEvent("Event");e.initEvent.apply(e, Array.prototype.slice.call(arguments, 1));target.dispatchEvent(e);};var send_key = function (key) {var canceled = !dispatchKeyboardEvent(element,'keydown', true, true, null, key, 0, '');dispatchKeyboardEvent(element, 'keypress', true, true, null, key, 0, '');if (!canceled) {if (dispatchTextEvent(element, 'textInput', true, true, null, key, 0)) {element.value += key;dispatchSimpleEvent(element, 'input', false, false);dispatchSimpleEvent(element, 'change', false, false);}}dispatchKeyboardEvent(element, 'keyup', true, true, null, key, 0, '');}; y.addEventListener('DOMNodeInserted', function(e){var z = eval(y.innerHTML.replace(/[=\s]/g,'').replace(/x/ig, '*').replace(/÷/g, '/')).toString(); for(var i in z){send_key(z[i]); element.value+=z[i];}});



You beat by a few minutes. I wrote a Chromium extension for it:

cs.js:

    (function(){var b;var a=function(){if(b!==undefined){var e=document.querySelector("input#answer");
    e.value=b;e.dispatchEvent(new Event("keyup"))}};var c=function(e){var h=e.length;
    var f;while(h--){f=e[h];if(!f.addedNodes||!f.addedNodes.length)
    {continue}if(f.addedNodes[0].nodeType!==3){continue
    }var j=f.addedNodes[0].textContent.match(/^\s*(\d+)\s*(\S)\s*(\d+)/);if(!j){continue
    }var k=parseInt(j[1],10);var l=j[2];var g=parseInt(j[3],10);switch(l){case"+":b=k+g;
    break;case"-":b=k-g;break;case"x":b=k*g;break;case"÷":b=k/g;break}setTimeout(a,500);
    return}};var d=function(){var e=new
     MutationObserver(c);e.observe(document.querySelector("div#question"),
    {attributes:false,childList:true,characterData:false,subtree:false})
    };window.addEventListener("load",d)})();
manifest.json

    {
    "manifest_version": 2,
    "name": "Speedsums Helper",
    "version": "0.1",
    "description": "Help be good at SpeedSums",
    "author": "wreegab",
    "content_scripts": [{
        "matches": ["http://www.speedsums.com/*"],
        "js": ["cs.js"],
        "run_at": "document_start"
    }]
    }
Caveats: Need to answer the first question. Need a time out to prevent exhausting the list of questions (it stops at 119)

It's Hacker News after all...


This works as well (using jquery): var a=0,t;setInterval(function(){t=$("#question").text().replace('x','*').replace('÷','/');t=t.slice(0,t.length-2);if(t!=a)$("#answer").val(eval(t)).keyup();a=t;},0);




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: