Hack #57. Remember Recent Google Searches
Track what you search for and which search results you follow.
Google recently added yet another beta service: My Search History (http://www.google.com/searchhistory/). In a nutshell, you log into your Google account, and My Search History remembers which keywords you search for and which search results you end up following. A nice idea, but it has some limitations that disappointed me when I tried it. My Search History isn't immediately available on the Google home page. Also, clicking a previous search simply reexecutes the search, instead of actually taking me to the result I followed last time. How is that useful? I remember what I searched for; what I want to know is what I found!
This hack lets me do what I had hoped the "My Search History" tool would do.
The Code
This user script runs on all Google pages. The code itself breaks down into three distinct parts:
The
SavedSearches
function and associated prototype methods are used to create a persistent array—i.e., anArray
class that saves its data to the Firefox preferences database.The
getCurrentSearchText
,addCurrentSearch
,clearSavedSearches
, andinjectRecentSearches
functions handle the basic operations of the script. Whenever you execute a Google search, the script adds your keywords to its persistent array, and then alters the search results page to include a list of your recent searches.The
trackClick
function is where the real magic happens. On search result pages, we register ...
Get Greasemonkey Hacks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.