Taking your question in the strict sense of the word is something like this:
$("YOUR SELECTOR").bind ("DOMSubtreeModified", HandleDOM_ChangeWithDelay);
var zGbl_DOM_ChangeTimer = null;
function HandleDOM_ChangeWithDelay (zEvent) {
if (typeof zGbl_DOM_ChangeTimer == "number") {
clearTimeout (zGbl_DOM_ChangeTimer);
zGbl_DOM_ChangeTimer = '';
}
zGbl_DOM_ChangeTimer = setTimeout (HandleDOM_Change, 333);
}
function HandleDOM_Change () {
}
Please note that you want an intermediate delay function because the changes will be in clusters of 10 to 100 events on a site such as Youtube or Google.
- , , .
:
, DOMSubtreeModified, . , , .
, Raynos, . , Firefox .
: script , , script /.
, ( ):
function HandleDOM_Change () {
}
fireOnDomChange ('YOUR JQUERY SELECTOR', HandleDOM_Change, 100);
function fireOnDomChange (selector, actionFunction, delay)
{
$(selector).bind ('DOMSubtreeModified', fireOnDelay);
function fireOnDelay () {
if (typeof this.Timer == "number") {
clearTimeout (this.Timer);
}
this.Timer = setTimeout ( function() { fireActionFunction (); },
delay ? delay : 333
);
}
function fireActionFunction () {
$(selector).unbind ('DOMSubtreeModified', fireOnDelay);
actionFunction ();
$(selector).bind ('DOMSubtreeModified', fireOnDelay);
}
}