PukiWikiで古いコメントを非表示にするグリースモンキースクリプト
タイトルの通り PukiWiki の pcomment モジュールを使っている場合に新着マーク New! がついていない古いコメントを、非表示にするグリースモンキースクリプトです。
pcomment を使って大量にコメントをやりとりしている場合に、古いコメントに返信が来たのが分かりづらいので古いコメントを消してくれます。
短時間で適当に作ったので動作がおかしかったらコメント等でお知らせください。
グリースモンキーなんて知らないよという人ははてなグリースモンキーあたりを読むと分かるかも。
ダウンロード「PukiWikiShowNewCommentsOnly.user.js」
ソースは
// Copyright (C) 2006, higepon // Released under the GPL license // http://www.gnu.org/copyleft/gpl.html // // ==UserScript== // @name Pukiwiki Show Only New Comments // @include http://wiki.monaos.org/* // ==/UserScript== // (function() { function fetchCommentDateSpans(root) { var spans = document.evaluate( './/span[@class="comment_date"]', root, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ); return spans; } function isOldComment(comment_date) { return !comment_date.hasChildNodes() || comment_date.firstChild.nextSibling.className != "new1"; } function hasNewCommentChildren(parent) { var children = fetchCommentDateSpans(parent); var childrenLength = children.snapshotLength; for (var i = 0; i < childrenLength; i++) { var c = children.snapshotItem(i); if (!isOldComment(c)) { return true; } } return false; } function hideOldComments() { var spans = fetchCommentDateSpans(document.body); var spansLength = spans.snapshotLength; for (var i = 0; i < spansLength; i++) { var comment_date = spans.snapshotItem(i); var parent = comment_date.parentNode; if (isOldComment(comment_date) && !hasNewCommentChildren(parent)) { parent.style.display = 'none'; } } } hideOldComments(); })();