// ==UserScript== // @name 豆瓣小组功能增强 // @version 0.1.3 // @license MIT // @namespace https://tcatche.github.io/ // @description 豆瓣小组展示功能增强:高亮包含指定关键字的帖子;隐藏包含指定关键字的帖子;去除标题省略号,展示全部文本;新标签页打开帖子;展示是否是楼主的标识;展示楼层号 // @author tcatche // @match https://www.douban.com/group/* // @require https://code.jquery.com/jquery-3.3.1.min.js // @homepageURL https://github.com/tcatche/douban-group-enhance // @supportURL https://github.com/tcatche/douban-group-enhance/issues // @grant none // @downloadURL none // ==/UserScript== (function() { // save user config const saveConfig = config => { const configString = JSON.stringify(config); localStorage.setItem('douban_group_enhance_config', configString); } // load user config const getConfig = () => { const configString = localStorage.getItem('douban_group_enhance_config'); const odlConfigString = localStorage.getItem('douban_group_filter_config'); try { const config = JSON.parse(configString || odlConfigString); return config; } catch (e) { return {}; } } // run user filters const runFilter = (config, self) => { const title = self.attr('title') || ''; const isInInclude = title => (config.include || []).filter(v => !!v).find(keyword => title.indexOf(keyword) >= 0); const isInDeclude = title => (config.declude || []).filter(v => !!v).find(keyword => title.indexOf(keyword) >= 0); const isTitleInInclude = isInInclude(title); const isTitleInDeclude = isInDeclude(title); if (isTitleInInclude && !isTitleInDeclude) { self.css({background: 'green', color: '#fff'}); } if (isInDeclude(title)) { self.parents('tr').hide(); } } // open in new tab const runOpenInNewTab = (config, self) => { if (config.openInNewTab) { self.attr('target', '_blank'); } } // show full title without cliped! const runShowFullTitle = (config, self) => { if (config.showFullTitle) { const title = self.attr('title') || self.text(); self.text(title); } } // show reply number const runShowReplyNumber = (options, self, index) => { if (options.config.showReplyNumber) { const replyHead = self.find('h4')[0]; const isInserted = $(replyHead).find('.douban_group_enhance_replay_number').length > 0; if (!isInserted) { const start = +(options.params.start || 0); const replayNumber = start + 1 + index; $(replyHead).append('' + replayNumber +'楼'); } } } // show if is topic owner const runShowOwnerTag = (options, self) => { if (options.config.showOwnerTag) { const replyHead = self.find('h4')[0]; const isInserted = $(replyHead).find('.douban_group_enhance_owner_tag').length > 0; if (!isInserted) { const replyerName = self.find('h4 a').text().trim(); if (replyerName === options.topicUser) { $(replyHead).append('楼主'); } } } } const runEnhancer = config => { const isTopicDetailPage = location.pathname.indexOf('/group/topic/') >= 0; const search = location.search ? location.search.substr(1) : ''; const params = {}; search.split('&').filter(v => !!v).map(item => { const items = item.split('='); if (items.length >= 1) { params[items[0]] = items[1]; } }); const global = { config: config, params: params, }; if (isTopicDetailPage) { // 帖子内容 $('#comments li').each(function(index) { global.topicUser = $('.topic-doc .from > a').text().trim(); const $this = $(this); runShowReplyNumber(global, $this, index); runShowOwnerTag(global, $this); }); } else { // 帖子列表 $('.topics tr .td-subject a, .title a').each(function() { const $this = $(this); runFilter(config, $this); runOpenInNewTab(config, $this); runShowFullTitle(config, $this); }); } } // init config dom let configDivHtml = `