我有一个为某些网站编写的greasemonkey/user.js 脚本。该网站有一个表,可以时不时地输出信息;它通过添加一个包含信息的新表格行来实现这一点。
目前我只是检查定时循环中是否有新内容。但我可以做不同的事情吗?我可以添加一个监听器,每当出现带有信息的新表行时就会触发该监听器吗?如果是这样怎么办?
编辑:我想检查的表仅包含表行。每次显示新信息时,都会添加一个新行,其中包含一些文本。该表似乎有最大长度。因此,如果它是一个完整的表,最旧的 tr 将被删除。把它想象成一个聊天框,它非常相似。
我当前的定时循环检查该表中未标记的表行,从中获取信息并标记它们。所以它只检查未标记的。
以及这些表行之一的示例:
我感兴趣的一些信息
i have this greasemonkey/user.js script written for some website. that website has a table which outputs info every now and then; it does so by adding a new tablerow with the info.
at the moment i just check in a timed loop if there is something new in there. But can i do this different? could i add a listener that will fire whenever a new table row with info appears? if so how?
EDIT: the table i wanna check on consists of only table rows. each time new info is presented a new row is added with some text inside it. the table seems to have a maximum length. so if it's a full table the oldest tr is removed. Think of it as a chatbox, it's quite similar.
my current timed loop checks for untagged table rows in that table, gets the info out of them and tags them. so it checks only untagged ones.
and example of one of those tablerows:
<tr class="tagged">
<td align="left" style="vertical-align: top;">
<div class="someClass" style="width: 100%;">
some info i'm interested in
</div>
</td>
</tr>
发布评论
评论(2)
有 Mutation Events,也许你可以使用 <有新行时出现 href="http://www.w3.org/TR/DOM-Level-3-Events/#event-type-DOMNodeInserted" rel="nofollow">DOMNodeInserted 事件插入。
There is Mutation Events, maybe you can use DOMNodeInserted event as there's new rows inserted.
@wong2 好电话。这适用于 IE9、FF4、Chrome 6 中的我(在用户脚本之外):
@wong2 Good call. This works for me (outside of a userscript) in IE9, FF4, Chrome 6: