HideComment

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

Verze ze dne 19. 12. 2014. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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