Google の検索結果の絞り込み条件に 3 ヶ月 と 6 ヶ月を追加する Google Chrome 拡張機能のソースコードを Github で公開しました

大した処理はしてませんがソースコードGithub で公開しておきます。

Github
https://github.com/suzuki86/AddSearchOptions

Chromeウェブストア
https://chrome.google.com/webstore/detail/add-search-options/kaifgnoibnjldmdkkfogenbfbfgcbiao?hl=ja

作ったうえで得られた知識

DOM の変更を検知する

Google の検索結果は Javascript を使って動的に DOM を書き換えて検索結果絞り込みの部分を表示しているようでしたので MutationObserver という DOM の変更を検知してくれるオブジェクトを使いました。

window.onload = function(){
  var observer = new MutationObserver(function(mutations){
    if(!document.getElementById('qdr_m3')){
      addThreeMonth();
    }
    if(!document.getElementById('qdr_m6')){
      addSixMonth();
    }
  });
  var options = { subtree: true, childList: true, characterData: true }
  observer.observe(document.body, options);
}