Hacker News new | ask | show | jobs
by nick_name 3761 days ago
If you don't want the browser to freeze ...

    var target = document.getElementById('n');
    function detect() {
      n = parseInt(target.firstChild.nodeValue);
      if (typeof n === 'number' && is_prime(n) === 'prime') {
        console.log('>> YES,' + n + ' is prime, clicking "yes" ...');
        document.getElementById('yes').click();
      } else {
        console.log('>> NO,' + n + ' is not prime, clicking "no" ...');
        document.getElementById('no').click();
      }
    }
    var observer = new MutationObserver(function (mutations) {
      mutations.forEach(function (mutation) {
        window.setTimeout(detect, 500);
      });
    });
    observer.observe(target, {
      attributes: true,
      childList: true,
      characterData: true
    });