- Published on
Google検索履歴を自動で保存するJavaScript
- Authors
- Name
- Shou Arisaka / 有坂翔
Google検索したキーワードの履歴を自動でローカルストレージに保存するソフトウェア・拡張機能を書いたので、tampermonkeyユーザースクリプトで使えるJavaScriptスクリプトをシェアします。

書きました。ローカルストレージ便利です。最近indexd DBなるものも発見してそれも気になってます。
// ==UserScript==
// @name store google search queries
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author tmp
// @match https://www.google.co.jp/search?*
// @grant none
// ==/UserScript==
if (localStorage.getItem('_storeQueries') == null) {
localStorage.setItem('_storeQueries' , '') ;
}
localStorage.setItem('_storeQueries', localStorage.getItem('_storeQueries') + '"' + document.querySelector('#lst-ib').value + '"' + ',' + '"' + new Date().toISOString() + '"' + "\n" ) ;
このスクリプトは、サイトが更新されるたびに(=アクセスするたびに)起動するというtampermonkeyユーザースクリプトの特徴を前提として書いています。
ローカルストレージストレージの確認方法は、F12キーでデベロッパーツールを開いて Application > localStorage > _storeQueries
で見れます。