Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name v2ex 关键词屏蔽(强制隐藏或移除)
- // @namespace http://tampermonkey.net/
- // @version 0.4
- // @description 强制屏蔽标题中包含 “币” 或 “sol” 的帖子 —— 可选移除或 !important 隐藏。带日志辅助调试。忽略大小写。 。
- // @author YourName
- // @match https://www.v2ex.com/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- const keywords = ['币', 'sol'];
- const re = new RegExp(keywords.map(k => k.replace(/[-\/\\^$*+?.()|[\]{}]/g,'\\$&')).join('|'), 'i');
- function filterPosts() {
- document.querySelectorAll('div[class="cell item"]').forEach((div, idx) => {
- const link = div.querySelector('.item_title a.topic-link');
- if (!link) {
- console.log(`[过滤][${idx}] 无标题链接`);
- return;
- }
- const text = link.textContent.trim();
- const matched = re.test(text);
- console.log(`[过滤][${idx}] "${text}" => 匹配: ${matched}`);
- if (matched) {
- // —— 方案 A: 直接从 DOM 中移除 ——
- // div.remove();
- // console.log(`[过滤][${idx}] 已移除`);
- // —— 方案 B: 强制添加 !important 隐藏 ——
- div.style.setProperty('display', 'none', 'important');
- console.log(`[过滤][${idx}] 已隐藏(!important)`);
- }
- });
- }
- // 首次过滤
- filterPosts();
- // 监听异步加载
- new MutationObserver(muts => {
- muts.forEach(m => {
- if (m.addedNodes.length) {
- filterPosts();
- }
- });
- }).observe(document.body, { childList: true, subtree: true });
- })();
Add Comment
Please, Sign In to add comment