LoginSignup
2
0

More than 3 years have passed since last update.

Chromeの履歴をAWSから護る(chrome-extension)

Posted at

背景

今日調べたアレどこだったかな~

履歴に残ってるハズだよね、、、

unnamed.jpg

、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、 、

awsコンソールばっかり!

履歴をまったく残さないわけにもいかないし、要らない履歴は消したいし、
そうだ!京都へ行こう chrome-extensionを作ろう

仕様

  • 指定したURLだけ履歴から消す
  • ワイルドカード指定を可能にする

ブレスト

とくになし。設定画面が面倒くさそう ← 実際そのとおりだった

ファイル構成

前回の反省を活かし、min化しない

root_folder
│ manifest.json
│ options.html

├─img
│ icon-128x128.png
│ icon-16x16.png
│ icon-48x48.png

├─js
│ background.js
│ jquery-3.4.1.min.js
│ script.js

└─css
chromeapp.js

ソース

  • manifest.json

履歴を削除する権限がhistory
設定をローカルストレージに保存する権限がstorage
多言語対応はめんどくさい:sweat:

manifest.json
{
  "name": "off-the-record History",
  "version": "1.0.0",
  "manifest_version": 2,
  "description": "off-the-record history",
  "permissions": [
    "history",
    "storage"
  ],  
  "background": {
    "scripts": ["js/background.js"]
  },
  "icons": {
    "128": "img/icon-128x128.png",
    "48": "img/icon-48x48.png",
    "16": "img/icon-16x16.png"
  },
  "options_ui": {
    "page": "options.html",
    "chrome_style": false
  }
}
  • script.js

設定画面のjsなので省略:sweat:
jquery-3.4.1.min.js も設定画面用

  • background.js

設定とmatchしたら、chrome.history.deleteUrl するだけ。
イベントはconsole.logで確認し、onVisited のみにした。
matchしたらすぐに処理を終えたいので for (var i=0;・・・ を使用した。forEachはbreakできないそうな。

background.js
chrome.history.onVisited.addListener(function(history_item) {

    chrome.storage.sync.get([chrome.runtime.id], function(val){

      var jsonstr = val[chrome.runtime.id];
      if (!jsonstr) {
        return;
      } 
      var patterns = JSON.parse(jsonstr);
      if (0 == patterns.length) {
        return;
      } 

      for (var i=0; i<patterns.length; i++) {
        var pattern = patterns[i];
        if (!pattern.checked) {
          continue;
        }

        if (history_item.url.match(pattern.regexp)) {
          chrome.history.deleteUrl({url: history_item.url});
          break;
        }
      }
    });

});

注意点

前回の注意点と同じ

公開

off-the-record History

自分で言うのもなんですが、便利です。
今のところ以下の4つを指定しています。

履歴除外設定

https://*.slack.com/
https://*.aws.amazon.com/
https://*.heroku.com/
https://photos.google.com/

課題

  • 設定をインポート&エクスポートできると便利

めんどくさいので万年課題。ユーザー数が1000超えたら考えるということで:sweat:

懸念事項

  • 設定URLが増えたときのパフォーマンス。遅いようなら上限数を設ける
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0