我正在编写tampermonkey脚本,在这个脚本中,我想在一个网页上运行一个函数,该函数只有在脚本在body标签中添加html代码时才会运行。
它可以来自
$('body').append('<div>new html</div>'); //or document.getElementsByTagName('body')[0].innerHTML += '<div>new html</div>'; //or document.getElementsByTagName('body')[0]insertAdjacentHTML('afterend', '<div>new html</div>') //or from any other library现在在tampermonkey中我想运行脚本,它应该抓住/观察这些脚本并在其后运行我的自定义tampermonkey功能。
我已经在tampermonkey中使用unsafewindow访问网页javascript。
我问这个问题的原因是我没有找到像这样的相关事情。
我只需要一种方法来捕捉这些事件,而不是整个代码。
I'm writing tampermonkey script in which in a webpage I want to run a function which should only run whenever some script append html code in body tag.
it can be from
$('body').append('<div>new html</div>'); //or document.getElementsByTagName('body')[0].innerHTML += '<div>new html</div>'; //or document.getElementsByTagName('body')[0]insertAdjacentHTML('afterend', '<div>new html</div>') //or from any other libraryNow in tampermonkey I want run script which should catch/watch these and run my custom tampermonkey function after it.
I'm already using unsafewindow in tampermonkey to access webpages javascript.
The reason of me asking this question is that I failed to find anything related like this.
I only need a way to catch these events, not the whole code.
最满意答案
尝试使用MutationObserver 。
Have you tried using a MutationObserver?
更多推荐
发布评论