Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

X Quick Block / X 一键屏蔽

简体中文 | English

A lightweight Tampermonkey userscript for X / Twitter that locally detects and hides likely spam, learns from user-confirmed Quick Blocks, and keeps account blocking strictly user-initiated.

一个用于 X / Twitter 的轻量级 Tampermonkey 用户脚本:本地识别并隐藏疑似垃圾内容,从用户主动确认的 Quick Block 中学习,同时确保真正的账号屏蔽始终由用户主动触发。


简体中文

项目简介

X / Twitter 简中评论区中经常存在大量重复广告、引流、色情推广和批量生成账号。

仅仅把原生屏蔽流程从:

点击 ⋯
→ 点击「屏蔽 @username」
→ 再次确认「屏蔽」

压缩成一次点击,仍然需要用户逐条发现和处理垃圾回复。

从 v0.4.0 开始,X Quick Block 将处理流程扩展为:

基础规则检测
      ↓
高置信疑似垃圾自动隐藏
      ↓
漏网内容由用户主动 Quick Block
      ↓
成功屏蔽后作为本地正样本
      ↓
学习相似垃圾模板
      ↓
之后自动隐藏相似内容

自动化只负责本地 DOM 隐藏

真正的账号级 Block / 屏蔽 操作仍然只能由用户主动点击目标 Tweet / Reply 的 后触发。


核心功能

本地垃圾检测

脚本会在浏览器本地对 Tweet / Reply 进行多特征评分,包括:

  • 自动生成式用户名形态
  • emoji 堆积或异常 emoji 行为
  • 高区分度色情 / 引流词
  • 搭讪和诱导语义
  • 短链与引流链接
  • 城市名批量堆叠
  • 联系方式 / 预约 / Telegram / QQ 等转化提示
  • @username 导流话术
  • 昵称装饰 emoji

基础检测达到阈值后,内容只会被隐藏,不会自动屏蔽账号。

Quick Block

当脚本存在漏网内容时,用户仍然可以:

  1. 点击目标 Tweet / Reply 右上角
  2. X Quick Block 校验目标账号
  3. 自动点击 屏蔽 @username / Block @username
  4. 自动点击最终确认按钮

整个账号级 Block 流程仍然由用户主动点击目标 发起。

本地学习

当一次 Quick Block 完成全部校验并执行最终确认后,该 Tweet / Reply 会成为本地正样本。

脚本使用:

文本正规化
→ 字符 3-gram
→ Dice similarity
→ 本地 Cluster

学习相似垃圾模板。

同类人工 Block 累积到足够数量后,对应 Cluster 会激活,之后高度相似的新内容可以直接在本地自动隐藏。

误判纠正

被自动隐藏的内容可以临时恢复显示。

恢复后会显示:

疑似广告 · 基础规则 · 7分

或:

疑似广告 · 学习规则 · 91%

并提供:

不是广告

按钮。

点击后:

  • 当前内容立即恢复
  • 保存本地负样本
  • 当前会话不再重新隐藏该条内容
  • 高度相似的负样本优先于基础检测和学习规则
  • 如果误判来自学习 Cluster,会降低该 Cluster 的有效性

悬浮开关

页面上会显示一个可拖动圆形按钮:

拦 OFF

单击切换:

拦 OFF ↔ 拦 ON

拦 OFF

脚本暂停所有干预:

  • 不执行垃圾识别
  • 不执行自动隐藏
  • 不接管
  • 不记录新的学习样本
  • 当前被隐藏的内容恢复显示

已保存的学习数据不会删除。

拦 ON

开启:

  • 基础垃圾检测
  • 本地学习规则检测
  • 高置信内容自动隐藏
  • Quick Block
  • Quick Block 成功后的本地学习
  • “不是广告”负反馈

悬浮按钮可以拖动,位置和 ON / OFF 状态都会自动保存。


隐藏 / 显示

当当前页面存在被脚本隐藏的内容时,主按钮附近会出现:

隐藏 N

点击后:

隐藏 N
→ 显示 N

所有由 X Quick Block 隐藏的内容会临时恢复,并显示命中原因和“不是广告”按钮。

再次点击即可重新隐藏。


自动学习机制

学习系统完全在浏览器本地运行。

文本正规化

脚本会对文本执行:

  • Unicode NFKC
  • 英文小写化
  • URL → <URL>
  • @username<MENTION>
  • 连续数字 → <NUM>
  • emoji → <EMOJI>
  • 空白合并

例如:

比她好看的没她骚比她骚的没她好看 @abc123 😏🙂9

会被正规化为更稳定的模板形式,从而降低随机账号、数字和 emoji 对相似度判断的影响。

Cluster

正样本加入 Cluster 的相似度阈值:

>= 0.72

Cluster 激活条件:

confirmed >= 3 + 2 * rejected

激活后的 Cluster 对新内容进行匹配,学习规则自动隐藏阈值:

>= 0.80

负样本 override 阈值:

>= 0.88

检测顺序固定为:

negative override
→ 基础检测
→ 激活 Cluster
→ 正常显示

隐私与账号安全

X Quick Block 不会:

  • 自动 Block
  • 批量 Block
  • 自动举报
  • 批量举报
  • 调用 X 内部 Block API
  • 使用 Bearer Token 执行账号操作
  • 读取 ct0 执行账号操作
  • 创建后台 Block 队列
  • 上传浏览记录
  • 上传 Tweet 内容
  • 上传账号信息
  • 发送统计信息
  • 使用第三方分析服务
  • 维护在线黑名单
  • 连接开发者自己的服务器

自动检测和学习只读取当前页面 DOM,并通过 CSS / DOM 状态隐藏内容。

真正的账号 Block 只会在用户主动点击目标 Tweet / Reply 的 后,由 Quick Block 链路执行。


安全与健壮性

X Quick Block 采用 fail-closed(失败关闭) 设计:

宁可某次自动操作失败,也不猜测并点击不确定的按钮。

Quick Block 会检查:

  • 用户是否真的主动点击
  • 点击目标是否属于 Tweet / Reply
  • 目标 @username
  • Block 菜单中的账号是否与目标一致
  • Block 菜单文本是否确实表示 屏蔽 / 封鎖 / Block
  • 最终确认按钮是否属于 Block 操作
  • 异步操作是否仍然属于当前操作

新操作会使旧操作失效,降低快速连续点击导致 DOM 状态串联的风险。


性能

脚本不使用高频 setInterval 轮询。

X 页面发生 DOM 更新后,使用:

MutationObserver
+
debounce
+
内容 signature

进行增量扫描。

未变化的 Tweet / Reply 不会反复执行完整检测。


本地存储

学习数据通过 Tampermonkey:

GM_getValue
GM_setValue

保存在浏览器本地。

当前容量限制:

  • 正样本:最多 300
  • 负样本:最多 200
  • Cluster:最多 100

超过容量后优先淘汰较旧数据。


安装

1. 安装用户脚本管理器

安装支持 Userscript 的浏览器扩展,例如 Tampermonkey。

2. 安装脚本

使用仓库中的:

x-quick-block.user.js

创建 / 更新 Tampermonkey 用户脚本。

也可以直接使用仓库 Raw 地址安装:

https://raw.githubusercontent.com/loopnull-com/x-quick-block/main/x-quick-block.user.js

3. 打开 X / Twitter

访问:

https://x.com/

或:

https://twitter.com/

看到:

拦 OFF

即表示脚本已经加载。


使用方法

推荐保持:

拦 ON

正常浏览。

脚本会自动隐藏高置信垃圾内容。

如果需要检查隐藏结果:

点击「隐藏 N」

如果发现误判:

点击「不是广告」

如果发现漏网垃圾:

点击该回复右上角 ⋯
→ Quick Block 自动完成后续屏蔽

这次人工 Block 会成为本地学习样本。


不包含的功能

为了保持行为可预测,本项目目前不会:

  • 自动屏蔽识别出的账号
  • 批量屏蔽账号
  • 自动举报
  • 使用在线共享黑名单
  • 使用 AI / 云端模型
  • 上传学习数据
  • 后台执行账号操作

X Quick Block 的设计目标不是:

自动替用户决定并执行账号处罚。

而是:

自动减少页面噪声,并从用户已经明确确认的屏蔽行为中学习。


兼容性

目标网站:

https://x.com/*
https://twitter.com/*

X / Twitter 是动态 Web 应用,其 DOM、data-testid 和交互逻辑可能随时变化。

如果 X 修改相关页面结构,脚本可能暂时失效,需要更新选择器或相关逻辑。


故障排查

如果脚本行为异常:

  1. 确认 Tampermonkey 中脚本已启用
  2. 刷新 X / Twitter
  3. 确认悬浮按钮状态
  4. 打开浏览器开发者工具:F12
  5. 进入 Console
  6. 查找以:
[X Quick Block]

开头的日志

提交 GitHub Issue 时建议包含:

  • 浏览器名称和版本
  • Tampermonkey 版本
  • X / Twitter 界面语言
  • 相关 Console 日志
  • 问题复现步骤

请不要提交 Cookie、Token、密码或其他登录凭据。


项目结构

x-quick-block/
├── x-quick-block.user.js
├── README.md
├── THIRD_PARTY_NOTICES.md
└── LICENSE

第三方代码

v0.4.0 的垃圾检测部分改编了:

x-spam-blocker

作者:vahnxu

项目:

https://github.com/vahnxu/x-spam-blocker

使用许可:MIT License

主要参考 / 改编内容包括:

  • 富文本和 emoji 提取
  • Tweet / User 数据提取
  • 多特征垃圾评分
  • 内容 signature
  • MutationObserver + debounce 扫描模式

未迁入:

  • 自动 Block API
  • 批量 Block
  • Block queue
  • Bearer Token 账号操作
  • cookie 驱动的账号操作
  • blocked-page collector

完整第三方版权和 MIT License 声明见:

THIRD_PARTY_NOTICES.md

开源协议

X Quick Block 整体采用:

GNU General Public License v3.0(GPL-3.0-only)

你可以使用、复制、修改和再分发本项目。

如果发布或分发修改后的版本,需要继续遵守 GPLv3,包括提供对应源代码、继续采用兼容的 GPL 条款,并保留适用的版权与许可证声明。

修改后的版本应明确说明已经进行过修改,不应冒充原作者发布的原始版本。

原项目:X Quick Block

原作者:LoopNull

GitHub:

https://github.com/loopnull-com

完整法律条款以仓库中的 LICENSE 为准。


免责声明

X Quick Block 是独立开发的第三方 userscript。

本项目与 X Corp.、Twitter 或 Tampermonkey 不存在隶属、授权、赞助或合作关系。

X / Twitter 可以随时修改网站结构,因此无法保证脚本永久兼容。

用户仍应自行决定需要真正屏蔽的账号。


English

Introduction

X / Twitter reply sections can contain large volumes of repetitive spam, promotional content, adult-service bait, referral posts, and automatically generated accounts.

Reducing the native blocking workflow from:

Click ⋯
→ Click "Block @username"
→ Confirm "Block"

to one click still requires the user to manually discover every unwanted reply.

Starting with v0.4.0, X Quick Block adds a local filtering and learning layer:

Base detector
      ↓
High-confidence spam is hidden locally
      ↓
Missed spam is manually Quick Blocked
      ↓
Confirmed Quick Blocks become local positive samples
      ↓
Similar spam templates are learned
      ↓
Future similar content can be hidden automatically

Automation is limited to local DOM hiding.

Actual account-level blocking is still triggered only after the user explicitly clicks the target post or reply's menu.


Core Features

Local Spam Detection

The script scores posts and replies using multiple local signals, including:

  • generated-looking handle patterns
  • unusual emoji accumulation
  • high-signal adult / referral phrases
  • bait and solicitation language
  • short or referral links
  • large city-name bursts
  • contact / booking / Telegram / QQ cues
  • @username referral patterns
  • decorative emoji in display names

A high-confidence match is hidden locally.

It is not automatically blocked.

Quick Block

For spam that the detector misses:

  1. Click the target post or reply's
  2. X Quick Block validates the target account
  3. It selects Block @username
  4. It validates and clicks the final confirmation

The user remains the initiator of every real Block action.

Local Learning

After a fully validated Quick Block reaches the final confirmation, the selected post or reply becomes a local positive sample.

The learning pipeline uses:

Text normalization
→ character 3-grams
→ Dice similarity
→ local clusters

Repeatedly confirmed similar templates can activate a local learned rule that hides future similar content.

False-Positive Correction

Hidden content can be temporarily revealed.

Revealed items show labels such as:

疑似广告 · 基础规则 · 7分

or:

疑似广告 · 学习规则 · 91%

and provide a:

不是广告

button.

Using it:

  • immediately restores the item
  • saves a local negative sample
  • prevents the current item from being hidden again during the session
  • gives highly similar negative samples priority over detectors
  • weakens a learned cluster when the false positive came from that cluster

Floating Toggle

The script displays a draggable floating button:

拦 OFF

Click it to switch:

拦 OFF ↔ 拦 ON

拦 OFF

All intervention is paused:

  • no spam detection
  • no automatic hiding
  • no Quick Block interception
  • no new learning samples
  • currently hidden posts are restored

Stored learning data is retained.

拦 ON

Enables:

  • base spam detection
  • local learned-rule detection
  • local automatic hiding
  • Quick Block
  • learning from successful Quick Blocks
  • false-positive feedback

The toggle position and ON / OFF state are persisted.


Hide / Reveal

When X Quick Block has hidden content on the current page, a small pill appears near the main toggle:

隐藏 N

Clicking it changes to:

显示 N

and temporarily reveals all content hidden by the script.

Revealed items show the detection source and a 不是广告 correction control.

Click the pill again to hide them again.


Learning Model

All learning happens locally in the browser.

Normalization

The script normalizes:

  • Unicode with NFKC
  • English to lowercase
  • URLs → <URL>
  • mentions → <MENTION>
  • number sequences → <NUM>
  • emoji → <EMOJI>
  • repeated whitespace

Clusters

Positive samples join an existing cluster when similarity is:

>= 0.72

A cluster becomes active when:

confirmed >= 3 + 2 * rejected

Active learned rules hide new content when similarity is:

>= 0.80

Negative-sample override activates at:

>= 0.88

Evaluation order is fixed:

negative override
→ base detector
→ active learned clusters
→ normal content

Privacy and Account Safety

X Quick Block does not:

  • automatically Block accounts
  • mass Block accounts
  • automatically report users
  • mass report users
  • call X's internal Block API
  • use a Bearer Token for account actions
  • use ct0 for account actions
  • create background Block queues
  • upload browsing history
  • upload post content
  • upload account information
  • send analytics
  • use third-party tracking
  • maintain an online blocklist
  • connect to a developer-operated server

Automatic detection and learning only inspect the current page DOM and change local display state.

A real account Block occurs only after the user explicitly clicks the target post or reply's menu.


Safety and Robustness

X Quick Block follows a fail-closed design:

It is better for an automatic action to fail than for the script to guess and click an uncertain control.

Quick Block validates:

  • genuine user interaction
  • the selected Tweet / Reply container
  • target @username
  • Block-menu account matching
  • Block-menu action text
  • final confirmation text
  • async operation identity

Starting a new operation invalidates older pending operations.


Performance

The script does not use high-frequency setInterval polling.

It uses:

MutationObserver
+
debounce
+
content signatures

to react to X's dynamic DOM updates.

Unchanged posts and replies avoid repeated full evaluation.


Local Storage

Learning data is stored through Tampermonkey:

GM_getValue
GM_setValue

Current limits:

  • positive samples: 300
  • negative samples: 200
  • clusters: 100

Older data is discarded first when limits are reached.


Installation

1. Install a Userscript Manager

Install a compatible userscript manager such as Tampermonkey.

2. Install X Quick Block

Use:

x-quick-block.user.js

from this repository.

You can also install from the repository Raw URL:

https://raw.githubusercontent.com/loopnull-com/x-quick-block/main/x-quick-block.user.js

3. Open X / Twitter

Visit:

https://x.com/

or:

https://twitter.com/

The floating:

拦 OFF

button indicates that the script has loaded.


Usage

For normal filtered browsing, enable:

拦 ON

High-confidence spam is hidden automatically.

To review hidden items:

Click "隐藏 N"

For false positives:

Click "不是广告"

For missed spam:

Click the reply's ⋯
→ Quick Block completes the remaining Block steps

That successful manual Block then becomes a local learning sample.


Non-Goals

To keep behavior predictable, X Quick Block currently does not:

  • automatically Block detected users
  • mass Block users
  • automatically report accounts
  • use shared online blocklists
  • use cloud AI / ML models
  • upload learning data
  • perform account actions in the background

The goal is not:

to automatically decide and execute account punishment.

The goal is:

to reduce page noise automatically while learning only from user-confirmed blocking actions.


Compatibility

Target websites:

https://x.com/*
https://twitter.com/*

X / Twitter is a dynamic web application.

Its DOM, data-testid attributes, and interaction behavior may change at any time, which can temporarily break compatibility.


Troubleshooting

If the script behaves unexpectedly:

  1. Make sure the userscript is enabled
  2. Refresh X / Twitter
  3. Check the floating toggle state
  4. Open Developer Tools with F12
  5. Open Console
  6. Look for messages beginning with:
[X Quick Block]

When opening a GitHub Issue, include:

  • browser and version
  • Tampermonkey version
  • X / Twitter interface language
  • relevant Console logs
  • reproduction steps

Do not include cookies, tokens, passwords, or other login credentials.


Repository Structure

x-quick-block/
├── x-quick-block.user.js
├── README.md
├── THIRD_PARTY_NOTICES.md
└── LICENSE

Third-Party Code

The spam-detection logic in v0.4.0 adapts parts of:

x-spam-blocker

Author: vahnxu

Repository:

https://github.com/vahnxu/x-spam-blocker

License: MIT License

Adapted areas include:

  • rich-text and emoji extraction
  • Tweet / User extraction
  • multi-feature spam scoring
  • content signatures
  • MutationObserver + debounce scanning

The following account-action features were not imported:

  • automatic Block API
  • batch Block
  • Block queues
  • Bearer Token account actions
  • cookie-based account actions
  • blocked-page collector

See:

THIRD_PARTY_NOTICES.md

for the full third-party copyright and MIT License notice.


License

X Quick Block as a whole is licensed under the:

GNU General Public License v3.0 (GPL-3.0-only)

You may use, copy, modify, and redistribute this project.

If you publish or distribute a modified version, you must continue to comply with GPLv3, including providing corresponding source code under compatible GPL terms and preserving applicable copyright and license notices.

Modified versions should clearly state that changes have been made and must not be represented as the original unmodified release by the original author.

Original project: X Quick Block

Original author: LoopNull

GitHub:

https://github.com/loopnull-com

See the repository's LICENSE file for the complete legal terms.


Disclaimer

X Quick Block is an independent third-party userscript.

It is not affiliated with, endorsed by, sponsored by, or associated with X Corp., Twitter, or Tampermonkey.

X / Twitter may change its website at any time, so permanent compatibility cannot be guaranteed.

Users remain responsible for deciding which accounts they actually block.

About

A lightweight Tampermonkey userscript for quick blocking on X / Twitter.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages