// ==UserScript==
// @name        hide uncreated Hatena Keyword on Google
// @namespace   http://inasphere.net/
// @description Google検索結果から未作成のキーワードページを除去する
// @include     http://www.google.co.jp/search*
// @author      inamenai
// @license     MIT License
// @version     0.3
// ==/UserScript==

// 配布場所
//     http://d.hatena.ne.jp/inamenai/20090324/p1
// 変更履歴
//     2009/11/27 0.3 ニコニコ大百科を除外
//     2009/03/25 0.2 複数サイト対応化、@PEDIA・ニコニコ大百科・FC2blogを追加
//     2009/03/24 0.1 リリース

(function() {

    var siteArray = [
        { url : /^http:\/\/d\.hatena\.ne\.jp\/keyword\/.+/i, text : /このキーワードはまだ作成されていません。/ },  // はてな
        { url : /^http:\/\/atpedia\.jp\/word\/.+/i, text: /はまだ編集されていません。/ },  // @PEDIA
        { url : /^http:\/\/blog\.fc2\.com\/tag\//i, text: /.*/ }  // FC2blog タグページ
    ];

    var result = document.evaluate('//a[@class="l"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

    for (var i = 0; i < result.snapshotLength; i++) {
        for (var j = 0; j < siteArray.length; j++) {

            if (!siteArray[j].url.test(result.snapshotItem(i).getAttribute("href"))) {
                continue;
            }

            (function(x, y) {
                GM_xmlhttpRequest({
                    method: "GET",
                    url: result.snapshotItem(x).getAttribute("href"),
                    onload: function(response) {
                        if (siteArray[y].text.test(response.responseText)) {
                            result.snapshotItem(x).parentNode.parentNode.setAttribute("style", "display: none;");
                        }
                    }
                });
            })(i, j);
        }
    }
})();

