Google Search Injection
Hi I'm writing a chrome extension to inject information into google search results. The only problem is that searching is now done through ajax instead of http. This means my code is only being executed once. This is a problem becaus开发者_如何学Ce my script needs to render on each new page. The only way to make it work is by refreshing the page manually (automatic refresh is possible? but ugly).
How can I alert my code to execute anytime google tries to search or fecth the next page of results?
You might need to hook in a javascript for the search button to make it call your code as well as the AJAX code to do the Google search. You would have to search the DOM for the button and change the onClick action. Remember to call the original action! :)
Ancient question but...
I accomplished this using 'window.onhashchange'. Whenever Google search results are updated, the URL is adjusted to contain the new queries. I parse the URL every time it changes, whether visiting a new page or a hash change (generally the result of AJAX), check if it's a google search result page, then do my thing.
See also: On - window.location.hash - Change?
精彩评论