// ==UserScript==
// @name Length filter for Habrahabr comments
// @author Kapustos
// @include http://*habrahabr.ru/blog*
// ==/UserScript==
// if the browser doesn't support the GM functions
if ( typeof (GM_getValue) == 'undefined' ) var GM_getValue = function () {
return false ;
};
if ( typeof (GM_setValue) == 'undefined' ) var GM_setValue = function () {};
if ( typeof (GM_registerMenuCommand) == 'undefined' ) var GM_registerMenuCommand = function () {};
// ---- Config -----
// hide comments with less words then CF_wordThreshold
var CF_wordThreshold = 20;
// --- /Config -----
window.addEventListener( 'load' ,
function ( event ) {
var comments = document .getElementById( 'comments' );
if (comments != 'undefined' ) {
var tempCommentsCloud = document .evaluate( "//ul[@class='hentry']/li/div[@class='entry-content'][1]" , comments, null , XPathResult.ANY_TYPE, null );
var commentsCloud = new Array();
while (temp = tempCommentsCloud.iterateNext()) {
commentsCloud.push(temp);
}
var comment;
while (comment = commentsCloud.pop()) {
if (comment.getElementsByTagName( "div" ).length < 1 ) {
var commentText = comment.textContent;
var words = commentText.split( ' ' ).length;
if (words < CF_wordThreshold) {
var commentDiv = comment.cloneNode( true );
commentDiv.className = '' ;
commentDiv.style.display = 'none' ;
comment.textContent = "" ;
comment.appendChild(commentDiv);
var appendText = document .createTextNode( ' ' );
var appendLink = document .createElement( 'a' );
appendLink.href = '#' ;
appendLink.addEventListener( 'click' , CF_showComment, false );
appendLink.appendChild(appendText);
comment.appendChild(appendLink);
}
}
}
}
},
false );
function CF_showComment( event ) {
com = event .target.parentNode.getElementsByTagName( "div" );
event .target.className = 'hidden' ;
com[0].style.display = 'block' ;
event .stopPropagation();
event .preventDefault();
return false ;
}
Source: https://habr.com/ru/post/39672/
All Articles