HideComment

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

Versione datata 19/12/2014. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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();
		}
	});
}