// ==UserScript== // @name 净化汽车之家论坛 // @namespace https://gitee.com/miniknife/JingTanShiZhe // @version 0.1 // @description 根据用户黑名单和内容关键字过滤帖子内容,还我干净的汽车之家论坛。 // @author MiniKnife // @match *://club.autohome.com.cn/bbs/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 用户黑名单列表 var USER_BLACKLIST = ['华尔街在哪', '青之十亩之外', '请把牛逼还给BYD', '榴莲汽车', '我最爱比亚迪', '黑车我矫情', 'loujilin', '我想玩火', 'lukenm', 'hjgailh', 'SS001869', '北京华彬', '范尼_雷克萨斯', '我祖先', '无聊的蝙蝠', 'LZYYF', 'eHudu', '龙行W风云']; // 帖子标题要过滤的关键字 var TITLE_FILTER_KEYWORDS = ['雷克']; // 帖子回复内容要过滤的关键字 var REPLY_FILTER_KEYWORDS = ['雷克', '本楼已被自动过滤系统删除', '本楼已被管理员删除']; function trimString(str) { if (str) { return str.trim(); } else { return ''; } } function listPosts() { var postList = []; $('#subcontent > dl.list_dl').each(function(i) { var postEle = $(this); var title = postEle.find('dt > a.a_topic').text(); title = trimString(title); var author = postEle.find('dd:first > a').text(); author = trimString(author); if (title && author) { postList.push({ title: title, author: author, jQElement: postEle }); } }); return postList; } function listReplies() { var replyList = []; $('#maxwrap-reply > div').each(function(i) { var replyEle = $(this); var content = replyEle.find('div.x-reply').text(); content = trimString(content); var author = replyEle.find('div.conleft a[xname=uname]').text(); author = trimString(author); var replyForAuthor = replyEle.find('div.x-reply div.relyhfcon > p:first > a:first').text(); replyForAuthor = trimString(replyForAuthor); var replyForContent = replyEle.find('div.x-reply div.relyhfcon > p.rrlycontxt').text(); replyForContent = trimString(replyForContent); if (content && author) { replyList.push({ content: content, author: author, replyForAuthor: replyForAuthor, replyForContent: replyForContent, jQElement: replyEle }); } }); return replyList; } function getAuthorBlacklist() { return USER_BLACKLIST; } function getTitleFilterKeywords() { return TITLE_FILTER_KEYWORDS; } function getContentFilterKeywords() { return REPLY_FILTER_KEYWORDS; } function filterByBlacklist(dataList, filterAttrName, filterBlacklist) { for (var i = 0; i < dataList.length; ++i) { var dataItem = dataList[i]; var attrValue = dataItem[filterAttrName]; if (attrValue && filterBlacklist.indexOf(attrValue) != -1) { console.log('hide value with ' + attrValue); dataItem['jQElement'].hide(); } } } function filterByKeywords(dataList, filterAttrName, filterKeywords) { for (var i = 0; i < dataList.length; ++i) { var dataItem = dataList[i]; var attrValue = dataItem[filterAttrName]; if (attrValue) { for (var ki = 0; ki < filterKeywords.length; ++ki) { var keywords = filterKeywords[ki]; if (attrValue.indexOf(keywords) != -1) { console.log('hide value with ' + attrValue); dataItem['jQElement'].hide(); break; } } } } } function filterPosts() { var postList = listPosts(); var authorBlacklist = getAuthorBlacklist(); var titleFilterKeywords = getTitleFilterKeywords(); filterByBlacklist(postList, 'author', authorBlacklist); filterByKeywords(postList, 'title', titleFilterKeywords); } function filterReplies() { var replyList = listReplies(); var authorBlacklist = getAuthorBlacklist(); var contentFilterKeywords = getContentFilterKeywords(); filterByBlacklist(replyList, 'author', authorBlacklist); filterByBlacklist(replyList, 'replyForAuthor', authorBlacklist); filterByKeywords(replyList, 'content', contentFilterKeywords); filterByKeywords(replyList, 'replyForContent', contentFilterKeywords); } function filterAds() { $('div.navarea > ul').hide(); $('div.area > dl').hide(); $('#__recom').hide(); } filterAds(); filterPosts(); filterReplies(); })();