HideComment

скрипт ведения игнор-листа на ИноСМИ

2014-12-19 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @id             InoSMI_HideComments
// @name           HideComment
// @version        1.01
// @namespace      MIT
// @author         
// @description    скрипт ведения игнор-листа на ИноСМИ
// @include        http://inosmi.ru/*
// @require        http://code.jquery.com/jquery.min.js
// @grant          FUNCTION
// ==/UserScript==

//прототип очистки массива
Array.prototype.clean = function() {
	// сортировка массива
	this.sort();
	// очистка массива от пустых переменных
	for (var i = this.length - 1; i > 0; i--) {
		if (this[i] == "")
			this.splice( i, 1);
	}
	// очистка массива от повторяющихся элементов
	for (var i = this.length - 1; i > 0; i--) {
		if (this[i] == this[i-1])
			this.splice( i, 1);
	}
	return this;
};

var to_hide = new Array();

$(document).ready(function() {
	//инициируем и считываем массив игноров
	if (localStorage.getItem('to_hide')) {
		to_hide = localStorage.getItem('to_hide').split(",");
	}
	else {
		to_hide.push('u_193012875');
		to_hide.push('u_207772399');
	}
	to_hide.clean();

	//скрываем комментарии после загрузки страницы
	DoHideComment();
});

//отслеживаем событие добавления нового контента (разворачивание веток)
$("li[id*='comment_']").bind("DOMSubtreeModified", DoHideComment);

//функция скрытия комментариев
function DoHideComment() {
	if (to_hide.length != 0) {
		$.each(to_hide,  function() {		
			var obj = $("span[id*="+this+"]").parent();
			obj.html('Комментарий "'+$("span[id*="+this+"]").html()+'" скрыт скриптом');
			obj.append('<br><a class="unhide" id="'+this+'">Снять игнор</a>');
			obj.next().hide();
			obj.next().next().hide();
		});
	}
	//снимаем событие "click" с элементов
	$("span[id*='u_']").unbind("click");
	$(".unhide").unbind("click");
	//отслеживаем клик по нику для добавления в игнор
	$("span[id*='u_']").click(function() {
		var obj = $(this).attr("id").substr(0,11);
		if (confirm('Добавить пользователя ID='+obj+' в игнор-лист?')) {
			to_hide.push(obj);
			localStorage.setItem('to_hide', to_hide);
			DoHideComment();
		}
	});
	//остлеживаем событие снятия игнора
	$(".unhide").one("click", function() {
		var obj = $(this).attr("id");
		if (confirm('Вы действительно хотите снять игнор c пользователя?')) {
			to_hide.splice($.inArray(obj, to_hide), 1);
			localStorage.setItem('to_hide', to_hide);
			location.reload();
		}
	});
}