Greasemonkey 不刷新页面?
Greasemonkey without refreshing the page?
嘿,我有这段代码可以通过 greasemonkey 自动回答问题,但它只在我刷新页面时有效。问题来自 AJAX,因此一旦页面刷新,整个游戏将无法运行,否则如果我保持这种方式而不刷新代码,则第二个三分之一等问题将无法运行。
所以我的问题是,是否可以在不不断刷新页面的情况下让 greasemonkey 正常工作?
See: http://jsfiddle.net/t2AzN/14/
你应该可以用 MutationObserver 来做到这一点。
如果您将回答问题的代码放入一个名为 answerQuestions
的函数中,那么这样的事情可能对您有用(改编自上面链接的示例):
// 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();
嘿,我有这段代码可以通过 greasemonkey 自动回答问题,但它只在我刷新页面时有效。问题来自 AJAX,因此一旦页面刷新,整个游戏将无法运行,否则如果我保持这种方式而不刷新代码,则第二个三分之一等问题将无法运行。
所以我的问题是,是否可以在不不断刷新页面的情况下让 greasemonkey 正常工作?
See: http://jsfiddle.net/t2AzN/14/
你应该可以用 MutationObserver 来做到这一点。
如果您将回答问题的代码放入一个名为 answerQuestions
的函数中,那么这样的事情可能对您有用(改编自上面链接的示例):
// 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();