// ==UserScript== // @name COLG功能增强 // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author Aur3l14no // @match https://bbs.colg.cn/* // @require https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js // @grant none // @downloadURL https://update.greasyfork.icu/scripts/421875/COLG%E5%8A%9F%E8%83%BD%E5%A2%9E%E5%BC%BA.user.js // @updateURL https://update.greasyfork.icu/scripts/421875/COLG%E5%8A%9F%E8%83%BD%E5%A2%9E%E5%BC%BA.meta.js // ==/UserScript== (function ($, undefined) { $(function () { //Your code here; const utils = { // save user config saveConfig: config => { const configString = JSON.stringify(config); localStorage.setItem('colg_enhance_config', configString); }, // load user config getConfig: () => { const configString = localStorage.getItem('colg_enhance_config'); const oldConfigString = localStorage.getItem('colg_filter_config'); try { const config = JSON.parse(configString || oldConfigString); return config; } catch (e) { return {}; } }, bindedEles: [], bindClick: function (selector, callback) { this.bindedEles.push(selector); $(selector).click(callback); }, unbindClick: (selector) => { $(selector).unbind(); }, unbindAllClick: function () { this.bindedEles.forEach(selector => { $(selector).click(callback); }) } } const createEnhancer = () => { // run user filters const runFilter = (config, self) => { const title = self.find('a.s.xst').text(); const user = self.find('td.by > cite > a').text(); const isNewUserThread = self.find('img[alt="新人帖"]').length > 0; const containsAnyKeyword = (text, keywords) => (keywords || []).find(keyword => text.indexOf(keyword) >= 0); const matchesAnyKeyword = (text, keywords) => (keywords || []).find(keyword => text === keyword); const isTitleIncluded = containsAnyKeyword(title, config.includedKeywords); const isTitleExcluded = containsAnyKeyword(title, config.excludedKeywords); const isUserExcluded = matchesAnyKeyword(user, config.excludedUsers); if (isTitleExcluded || isUserExcluded || (true && isNewUserThread)) { self.hide(); } else if (isTitleIncluded) { self.find('a.s.xst').addClass('colg_enhance_highlight'); } } const runEnhancer = () => { const config = utils.getConfig(); const isThreadDetailPage = location.pathname.indexOf('/thread-') >= 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 (isThreadDetailPage) { // 先什么都不做 } else { // 帖子列表 $('tbody[id^="normalthread_"]').each(function () { const $this = $(this); runFilter(config, $this); }); } } // init form elements const initDom = () => { // init config dom let configDivHtml = `