I'm writing a bookmarklet that simply removes some content from a specific webpage.
Now the thing is the webpage has "neverending scroll" pagination and you need to click the bookmarklet again and again after each page loads.
Is it possible to catch web-page content update with a bookmarklet?
According to http://en.wikipedia.org/wiki/DOM_events#Common.2FW3C_events DOM mutation events are deprecated so it seems there is no cross browser way to catch an event on page-content update.
phari posted a link to the new DOM mutation events API which seems to be supported in all modern browsers. Example usage code from that page:
// select the target node
var target = document.querySelector('#some-id');
// create an observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.type);
});
});
// 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();
If you need support for older browsers, you may probably try jquery-observe which has fallback for older browsers. Or write it yourself, i.e. like here https://stackoverflow.com/a/14570614/4712360
The other option is to inspect source code of the website, maybe you can find some event fired there, after the web content is updated. Or you can hook some function which is called after content is updated, or, as a last resort, you can simply set-up interval with function which will check if anything on the page has changed.