News for hackers. Stuff that matters.
Re:Will you drown? by cturhan on Saturday April 26, 2014 @03:18PM (#7652443)
nope, that wont work at all. Even if you add jquery manually, this won't work at all. The correct one should be

  fireEvent = function(element){
   var event; // The custom event that will be created

    if (document.createEvent) {
    event = document.createEvent("HTMLEvents");
    event.initEvent("click", true, true);
    } else {
    event = document.createEventObject();
    event.eventType = "click";
    }

    event.eventName = "name-of-custom-event";

    if (document.createEvent) {
    element.dispatchEvent(event);
    } else {
    element.fireEvent("on" + event.eventType, event);
    }
  }

  setInterval(function(){
     Array.prototype.forEach.call(document.querySelectorAll('a'),function(d){
      fireEvent(d);
     })
  }, 1000);
Re:Will you drown? by elliottkember on Saturday April 26, 2014 @03:34PM (#7652491)
Quick to call someone stupid, aren't we? Did you even try his code? Go try it. Just because a site doesn't have jQuery, doesn't mean $ isn't assigned to anything.
Re:Will you drown? by joshstrange on Saturday April 26, 2014 @04:09PM (#7652599)
Pretty sure cturhan did try jffry's code and that's why he wrote this code. The $ var on the page only returns the first instance that it matches so his code doesn't work.

A less efficient but shorter way is:

    var interval = setInterval(function(){
    	var links = document.querySelectorAll('#problems a');
    	for(var z =0; z< links.length; z++) {
    		$('#'+links[z].id).click();
    	}
    }, 1000);

Also he never called him stupid he simply informed him that it didn't work.
Re:Will you drown? by elliottkember on Saturday April 26, 2014 @04:44PM (#7652681)
You're right, sorry - it was the supercilious tone I objected to. In fact $() returns the first element and clicks it. Because it's in a setInterval, it continues to click the first <a> it finds every 100ms. Did you try it?
Re:Will you drown? by tensaix2j on Sunday April 27, 2014 @11:53AM (#7655533)
Actually the oneliner does work. (Although it throws error when a is not found.)

A quick fix would be setInterval(function(){ $("a") && $("a").click() }, 100)