You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过AdBlock过滤器永久屏蔽页面--no-select属性实现代码复制

永久禁用页面--no-select禁止复制属性的方案

存在可永久生效的禁用方法,也可以通过AdBlock类扩展(uBlock Origin、AdGuard等常见广告过滤工具均支持)添加自定义规则实现,针对你给出的带s1-description-code--no-select类的代码块,具体操作方法如下:

AdBlock/广告过滤扩展实现方式

这类扩展不止能拦截广告,还支持自定义页面元素修改、样式注入,配置一次即可永久生效:

  • 打开扩展的「自定义过滤器」配置页面
  • 添加对应规则:如果仅需要在当前访问的编程学习站点生效,把规则里的example.com替换成对应站点域名;如果需要全局所有站点生效,把域名位置替换为*:
! 移除代码块上的禁止选择类名
example.com##.s1-description-code--no-select:remove-class(s1-description-code--no-select)
! 兜底强制所有元素允许文本选中,覆盖页面禁止选择的CSS规则
example.com##*:style(user-select: text !important; -webkit-user-select: text !important; -moz-user-select: text !important;)

添加保存后刷新页面,代码块即可正常选中复制。

稳定性更高的替代方案

如果站点后续修改类名、或者新增JS拦截复制/右键的逻辑,AdBlock规则可能失效,可以选择下面两种一劳永逸的方法:

  • 使用Stylus类用户样式扩展注入全局自定义CSS,强制覆盖所有禁止选择的样式,不受页面类名修改影响:
* {
  user-select: text !important;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
}
  • 使用油猴(Tampermonkey/Violentmonkey)注入脚本,除了覆盖样式,还能直接拦截页面阻止复制、右键、选中文本的JS事件,适配绝大多数防复制场景,核心代码如下:
// 移除现有代码块的禁止选择类
document.querySelectorAll('.s1-description-code--no-select').forEach(el => {
  el.classList.remove('s1-description-code--no-select')
})
// 全局开启文本选中
document.body.style.cssText += 'user-select:text !important;-webkit-user-select:text !important;'
// 拦截页面阻止复制、右键、选中文本的事件监听
['copy', 'contextmenu', 'selectstart', 'mousedown', 'keydown'].forEach(eventName => {
  document.addEventListener(eventName, e => e.stopImmediatePropagation(), true)
})

如果只是临时需要复制一次代码,无需安装任何扩展:按F12打开开发者工具,用元素选择器点中无法复制的代码块,在元素面板找到对应div的class属性,删掉s1-description-code--no-select字段,即可立刻正常选中复制。

内容的提问来源于stack exchange,提问作者DScounterGO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.31 08:24:21