I came here looking how to do it, can't find how. So I made it for myself.
This function is for running the loop in order (Thanks to Ivo Wetzel for his answer here):
function asyncLoop(iterations, func, callback) {
var index = 0;
var done = false;
var loop = {
next: function() {
if (done) {
return;
}
if (index < iterations) {
index++;
func(loop);
} else {
done = true;
callback();
}
},
iteration: function() {
return index - 1;
},
break: function() {
done = true;
callback();
}
};
loop.next();
return loop;
}
This other is for emulate click in the links (can't remember where I see it):
function hacerClic(obj, callback) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
var canceled = !obj.dispatchEvent(evt);
callback();
}
Last, we have two runs for asyncLoop, one for expand the answers:
var verRespuestas = document.getElementsByClassName("UFIReplySocialSentenceLinkText");
var i = 0;
asyncLoop(verRespuestas.length, function(loop) {
hacerClic(verRespuestas[i], function(result) {
loop.next();
i++;
})
}, function() {});
And other for expand the 'see more':
var verMas = document.getElementsByClassName("_5v47");
var j = 0;
asyncLoop(verMas.length, function(loop) {
hacerClic(verMas[j], function(result) {
loop.next();
j++;
})
}, function() {});
NOTE: If the 'see more' loop gives error is probably because DOM isn't fully loeaded yet.