// ==UserScript==
// @name dd-ignore-tempermonkey
// @version 0.2
// @description Hide blacklisted users and their data.
// @include http://www.darkdiary.ru/
// @include http://darkdiary.ru/
// @include darkdiary.ru/
// @include http://www.darkdiary.ru/?page=*
// @include http://darkdiary.ru/?page=*
// @include darkdiary.ru/?page=*
// @include http://www.darkdiary.ru/users/*
// @include http://darkdiary.ru/users/*
// @include darkdiary.ru/users/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_log
// @namespace https://gf.qytechs.cn/users/6880
// ==/UserScript==
var antimagic = function(event){
var nick = $(this).siblings("a[href $= '/profile']").attr("href").replace("/users/","").replace("/profile","");
removeFromList(nick);
event.preventDefault();
};
var toggle = function(event){
var pObjects=$(this).parents("article").children().siblings("[class!='notice']");
var strStyle=pObjects.attr("style");
//GM_log(strStyle);
var strQ="Скрыть?"
if(strStyle=="display:none"){
pObjects.attr("style","padding-bottom:3px")
}else{
pObjects.attr("style","display:none")
strQ="Показать?"
}
$(this).parents("article").find("a[class='igShow']").html(strQ);
event.preventDefault();
};
var hide = function(ignoreList){
ignoreList.forEach(function(value, index, array){
$('a[title^="Профиль пользователя"][href="/users/' + value + '/profile"] + a + a').closest("div[class='userlistRow']").attr("style","display:none");
var pToHide=$('a[title^="Профиль пользователя"][href="/users/' + value + '/profile"] + a + a').attr("title", "Скрыть").unbind("click").bind("click", toggle)
.after(" <a title='Амнистировать' class='forgive friendreqButton' href = '#'></a>")
.closest("article[class^='block comment']");
var strPrevEl="div[class!='notice']";
if(pToHide.size()<1){
pToHide=$('a[title^="Профиль пользователя"][href="/users/' + value + '/profile"] + a + a')
.closest("article[class^='block entry']");
strPrevEl="div[class^='rightPane']";
}
//if(pToHide.length<1) continue;
pToHide.children().siblings("[class!='notice']").attr("style","display:none").siblings(strPrevEl)
.after("<section class='notice' style='" + noticeStyle + "'><div class='textBg' data-user='" + value +
"' style='border:solid 1px #ddddcc; padding-left: 120px'>Пользователь <b>" +
value + "</b> написал какую-то глупость. <a class='igShow' href='#'>Показать?</a></div></section>");
GM_log(pToHide);
});
$("a.igShow").unbind("click").bind("click", toggle);
$("a.forgive").unbind("click").bind("click", antimagic);
};
var magic = function(event){
var nick = $(this).siblings("a[href $= '/profile']").attr("href").replace("/users/","").replace("/profile","");
GM_setValue("dd_ignore", GM_getValue("dd_ignore", " ").replace(" " + nick + " ", " ") + nick + " ");
fillList(GM_getValue("dd_ignore", " ").split(" "));
hide([nick]);
event.preventDefault();
};
var antimagicByName = function(event){
var nick= $(this).closest("div").prev().attr("href").replace("/users/","").replace("/profile","").replace("/","");
removeFromList(nick);
event.preventDefault();
};
var removeFromList = function(nick){
GM_setValue("dd_ignore", GM_getValue("dd_ignore", " ").replace(" " + nick+" ", " "));
fillList(GM_getValue("dd_ignore", " ").split(" "));
$("div[data-user = '" + nick + "']").parent().siblings().attr("style","").siblings("div[class!='leftPane'][class!='rightPane rightPaneOffset']").attr("style","clear:both;");
$("div[data-user = '" + nick + "']").parent().remove();
$('a[title^="Профиль"][href="/users/' + nick + '/profile"] + a + a').attr("title", "В игнор").unbind("click").bind("click", magic).next().remove();
$('a[title^="Профиль пользователя"][href="/users/' + value + '/profile"] + a + a').closest("div[class='userlistRow']").attr("style","");
};
var fillList = function(ignoreList){
ignoreListContainer.html("<h1 class='section'>Список игнора</h1>");
ignoreListContainer.next().remove();
var tmpList="<div>";
ignoreList.forEach(function(value, index, array){
if(value!="")tmpList+='<div class="userlistRow"><a href="/users/'+value+'/">'+value+'</a>'+
'<div class="controls"><a title="Амнистировать" class="forgiveFromList friendreqButton" href = "#"></a></div></div>'
});
tmpList+="</div>";
ignoreListContainer.after(tmpList);
$("a.forgiveFromList").unbind("click").bind("click", antimagicByName);
};
var showIgnore = function(event){
ignoreListStyle=(ignoreListStyle=="display:none"?"padding-bottom:3px":"display:none");
ignoreListContainer.closest("h1").parent().attr("style", ignoreListStyle);
$(this).text(ignoreListStyle=="display:none"?"Показать список":"Скрыть список");
GM_setValue("ignoreListStyle", ignoreListStyle);
fillList(GM_getValue("dd_ignore", " ").split(" "));
event.preventDefault();
};
var toggleNotices = function(event){
if( $(this).text() == "Скрыть оповещения"){
noticeStyle = "display:none";
$(this).text("Показать оповещения");
$(".notice").attr("style", noticeStyle);
}else{
noticeStyle = "padding-bottom:3px";
$(this).text("Скрыть оповещения");
$(".notice[style='display:none']").attr("style", noticeStyle);
}
GM_setValue("noticeStyle", noticeStyle);
event.preventDefault();
};
var noticeStyle = GM_getValue("noticeStyle", "padding-bottom:3px");
var ignoreListStyle = GM_getValue("ignoreListStyle", "display:none");
var ignoreListContainerType=0;
var ignoreListContainer;
var ignoreListContainerHolder=$("h1.section:contains('Наши интересы')").parent().parent();
if(ignoreListContainerHolder.prop("baseURI")==undefined){
ignoreListContainerType=1;
ignoreListContainerHolder=$("h1.section:contains('Мои теги')").parent().parent();
if(ignoreListContainerHolder.prop("baseURI")==undefined){
ignoreListContainerHolder=$("h1.section:contains(' друзья')").parent().parent();
if(ignoreListContainerHolder.prop("baseURI")==undefined){
ignoreListContainerType=-1;
}
}
}
if(ignoreListContainerType>=0){
var sHTMLTemplate='<div class="block"><h1 class="section">1</h1></div>';
ignoreListContainerHolder.children().last().after(sHTMLTemplate);
ignoreListContainer=ignoreListContainerHolder.find("h1.section").last();
}
ignoreListContainer.closest("h1").parent().attr("style", ignoreListStyle);
fillList(GM_getValue("dd_ignore", " ").split(" "));
$("a[class ^= 'profileButton'][href $= '/profile'] + a").after(" <a title='В игнор' class = 'clIgnore deleteButton inline' href = '#'></a>");
$(".clIgnore").bind("click", magic);
$("div.section:contains('Мой дневник')").parent().after("<nav class='block leftMenu'><div class='section'>Игнор</div>"+
"<a id='showIgnoreList' href='#'>" +
(ignoreListStyle == "display:none" ? "Показать список" : "Скрыть список")+"</a><a id='toggleNotices' href='#'>" +
(noticeStyle == "display:none" ? "Показать оповещения" : "Скрыть оповещения")+"</a></nav>");
$("#showIgnoreList").bind("click", showIgnore);
$("#toggleNotices").bind("click", toggleNotices);
hide(GM_getValue("dd_ignore", " ").split(" "));