I’m trying to write a script for Greasemonkey to modify Google Instant results. I have no problem modifying results for NORMAL Google search when it isn’t Instant, but when it IS instant, it’s difficult because the results are always changing. My problem is that I don’t know how to write the code to catch every time the page changes and then modify it—in a sensible manner.
My best option so far is to catch keyup events then modify the page after each event, but I would imagine that is a bit too strenuous. Is there a more efficient way of doing things?
Probably the most robust/simple way is to use the
waitForKeyElements()function like in this answer, this answer, or this answer.Note that this function requires jQuery in your script — which is a good idea anyway. To do that add this line to the Metadata Block of your script:
Other methods include: listening for
DOMSubtreeModifiedor intercepting AJAX calls. These would work but are overly complicated, in practice, especially on ever-changing Google pages.