Hey I have got this code that answers questions autimatically via greasemonkey but it only works when I refresh the page. The questions are coming by AJAX so as soon as the page refreshes the whole game does not work otherwise if I keep it this way without refreshing the code does not work on the second third etc. questions.
So my question is is it possible to keep greasemonkey working without refreshing the page constantly ?
See: http://jsfiddle.net/t2AzN/14/
You should be able to do this with a MutationObserver.
If you put the code that answers the question into a function called answerQuestions
, then something like this might work for you (adapted from the example linked above):
// select the target node
var target = document.getElementById('question-container');
// create an observer instance
var observer = new MutationObserver(function(mutations) {
answerQuestions();
});
// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
// later, you can stop observing
observer.disconnect();