如何在tampermonkey中捕捉/观看javascript追加触发器?(how to catch/watch append trigger in javascript in tampermonke

编程入门 行业动态 更新时间:2024-10-25 06:25:11
如何在tampermonkey中捕捉/观看javascript追加触发器?(how to catch/watch append trigger in javascript in tampermonkey?)

我正在编写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 library

Now 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?

更多推荐

本文发布于:2023-08-06 20:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1455412.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   如何在   javascript   tampermonkey   trigger

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!