-
-
Save ETiV/6130886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name CleanComments | |
// @namespace ForBetterJanDan | |
// @description 眼不见心不烦, 删除煎蛋多说"吐槽"中某些人的评论 | |
// @include http://jandan.net/pic* | |
// @include http://jandan.net/ooxx* | |
// @version 2 | |
// ==/UserScript== | |
if ($ != undefined) { | |
(function(window){ | |
// 本地存储域 | |
var localStorageDomain = 'GM_JanDan_Net_DuoShuo_Deny'; | |
var subDomainUID = localStorageDomain + ':UID' | |
, subDomainURL = localStorageDomain + ':URL'; | |
/** | |
* 如何重置屏蔽关键字? | |
* 删除如下两行前面的双斜线, 而后重新访问一次煎蛋页面 | |
* 然后记得将刚刚删掉的双斜线重新添加回来 | |
*/ | |
// delete window.localStorage[subDomainUID]; | |
// delete window.localStorage[subDomainURL]; | |
// localStorage 相关操作 | |
var ls_read_array = function(key){ | |
return JSON.parse(window.localStorage[key] || '[]'); | |
}; | |
var ls_save_array = function(key, arr){ | |
window.localStorage[key] = JSON.stringify(arr); | |
return arr; | |
}; | |
var ls_array_insert = function(key, val){ | |
var arr = ls_read_array(key); | |
if (arr == undefined || arr.length == undefined) { | |
arr = []; | |
} | |
if (arr.indexOf(val) == -1) { | |
arr.push(val); | |
} | |
ls_save_array(key, arr); | |
}; | |
var ls_array_delete = function(key, val){ | |
var arr = ls_read_array(key); | |
if (arr == undefined || arr.length == undefined) { | |
arr = []; | |
} | |
var i = arr.indexOf(val); | |
if (i > -1) { | |
arr.splice(i, 1); | |
} | |
ls_save_array(key, arr); | |
}; | |
// 重置按钮. 这个实在不知道放在哪里好, 所以塞到了分页链接的右侧 | |
// 当然, 只有在你已经有设置过屏蔽字的情况下这个按钮才会出现 | |
// 如果你不喜欢经常看到那个按钮, 可以将"下面这行", 跟"下下面那行"前面的双斜线交换一下 | |
// if (false && (ls_read_array(subDomainUID) && ls_read_array(subDomainUID).length > 0) || | |
if ((ls_read_array(subDomainUID) && ls_read_array(subDomainUID).length > 0) || | |
(ls_read_array(subDomainURL) && ls_read_array(subDomainURL).length > 0)) { | |
var $reset_html = $('<button style="float:right;font-size:12px;padding:5px 8px;">重置吐槽屏蔽字</button>'); | |
$reset_html.bind('click', function(){ | |
var $self = $(this); | |
delete window.localStorage[subDomainUID]; | |
delete window.localStorage[subDomainURL]; | |
$self.text('已重置').attr('disabled', 'disabled'); | |
setTimeout(function(){ | |
$self.fadeOut(500); | |
}, 1000); | |
return false; | |
}); | |
$('.cp-pagenavi').append($reset_html); | |
} | |
// 当然也可以注释掉整段代码. 注释截至到这里就可以了. | |
// 而后, 如果以后需要重置屏蔽关键字, 你可以按照第 #18 行下面描述的操作进行 | |
// 屏蔽关键字列表, 内容为多说的UserID | |
// 根据吐槽列表中发帖人的多说UserID进行过滤, 登录后的用户才有. | |
var denyUserIDList = ls_read_array(subDomainUID) || ls_save_array(subDomainUID, []); | |
// 屏蔽关键字列表, 内容为用户自己填写的URL | |
// 根据吐槽列表中发帖人的URL进行过滤, 广告的通常手段. | |
var denyURLList = ls_read_array(subDomainURL) || ls_save_array(subDomainURL, []); | |
// 功能实现 | |
document.addEventListener('DOMNodeInserted',function(event){ | |
var $thread = $(event.target); | |
if (event.target.tagName && | |
event.target.tagName.toLowerCase() == 'ul' && | |
$($thread.find('li')[0]).hasClass('ds-post') ) { | |
// 根据用户ID删除 | |
denyUserIDList.forEach(function(e){ | |
if (!e) return; | |
var $el = $thread.find('.ds-avatar[data-user-id="'+e+'"]'); | |
if ($el) $el.parent().parent().remove(); | |
}); | |
// 根据用户URL删除 | |
denyURLList.forEach(function(e){ | |
if (!e) return; | |
var $el = $thread.find('a[href="'+e+'"]'); | |
if ($el) $el.parent().parent().parent().remove(); | |
}); | |
// 添加屏蔽关键字 | |
$thread.find('li.ds-post').each(function(){ | |
var $self = $(this) | |
, user_id = $self.find('div[data-user-id]').attr('data-user-id') | |
, user_url = $self.find('.ds-comment-header a').attr('href') | |
, $html = null; | |
if (user_id) { | |
$html = $('<a href="javascript:void(0);" title="屏蔽UID: ['+user_id+']" class="ds-post-deny">屏蔽UID</a>'); | |
$html.bind('click', function(){ | |
if (confirm('确定屏蔽吗?')) { | |
ls_array_insert(subDomainUID, user_id); | |
$('li[data-post-id="'+$self.attr('data-post-id')+'"]').slideUp(); | |
} | |
}); | |
$self.find('.ds-comment-actions a.ds-post-report').before($html); | |
} | |
if (user_url) { | |
$html = $('<a href="javascript:void(0);" title="屏蔽URL: ['+user_url+']" class="ds-post-deny">屏蔽URL</a>'); | |
$html.bind('click', function(){ | |
if (confirm('确定屏蔽吗?')) { | |
ls_array_insert(subDomainURL, user_url); | |
$('li[data-post-id="'+$self.attr('data-post-id')+'"]').slideUp(); | |
} | |
}); | |
$self.find('.ds-comment-actions a.ds-post-report').before($html); | |
} | |
}); | |
} | |
}, false); | |
})(window); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment