// ? Comment Abone, released under the GPL
// http://www.gnu.org/copyleft/gpl.html
//
// ==UserScript==
// @name           Hatena Comment Abone
// @description    Looks for comments that contains NG words, and makes them invisible.
// @include        http://d.hatena.ne.jp/*
// @include        http://*.g.hatena.ne.jp/*
// @include        http://b.hatena.ne.jp/*
// @include        http://i.hatena.ne.jp/*
// @include        http://q.hatena.ne.jp/*
// ==/UserScript==
//
// 2007-01-12 (v0.2) Added support for "list-plain nobg" (idea).
// 2006-03-20 (v0.1) Initial Version.

(function(){
  const comments = document.evaluate('(/descendant::DIV[@class="commentshort" or @class="commentbody"]/P|/descendant::DIV[@class="bookmarklist"][1]/UL/LI|/descendant::UL[@class="list-plain nobg"]/LI|/descendant::DIV[@class="comment-content" or @class="tb_excerpt"])', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

  var words = unescape(GM_getValue('words', ''));
  var after = unescape(GM_getValue('after', '%u306f%u3066%u30fc%u306a'));

  const regexpNG = new RegExp(words || '^$', '');

  for (var i = 0; i < comments.snapshotLength; ++i) {
    with (comments.snapshotItem(i)) {
      if (textContent.match(regexpNG)) {
        textContent = after;
      }
    }
  }

  GM_registerMenuCommand('NG\u30ef\u30fc\u30c9\u8a2d\u5b9a...', function () {
    var s = prompt('NG\u30d5\u30ec\u30fc\u30ba:', words);
    
    if (s !== null) {
      GM_setValue('words', escape(words = s));
    }
  }, 'n', 'control shift alt');
  
  GM_registerMenuCommand('\u7f6e\u63db\u6587\u5b57\u5217\u8a2d\u5b9a...', function () {
    var s = prompt('\u7f6e\u63db\u6587\u5b57\u5217:', after);
    
    if (s !== null) {
      GM_setValue('after', escape(after = s));
    }
  }, 'a', 'control shift alt');
})()

