惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
V
Visual Studio Blog
小众软件
小众软件
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
T
Tor Project blog
Jina AI
Jina AI
GbyAI
GbyAI
C
Comments on: Blog
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
A
Arctic Wolf
有赞技术团队
有赞技术团队
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
Webroot Blog
Webroot Blog
C
Cisco Blogs
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
H
Hacker News: Front Page
D
Darknet – Hacking Tools, Hacker News & Cyber Security
D
Docker
P
Palo Alto Networks Blog
The Register - Security
The Register - Security
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志

博客园 - 隐客

商品期权的保证金计算 获取个股信息的东财数据 AI量化qlib学习笔记四:测试模型 AI量化qlib学习笔记三:训练模型 AI量化qlib学习笔记二:转换数据 AI量化qlib学习笔记 一:清洗数据 python 打包工具 python: 与通达信联动 随手写了街机一键发招的代码 使用pybind11封装c++的dll,供python调用 用py-spy对python线程查看cpu等资源 占用和消耗 通过selenium获取性能日志中的response的body Windows Server 2012无法安装 .NET3.5-安装角色或功能失败,找不到源文件 vscode 扩展商店打不开的解决办法 通过1分钟生成其它线的bar配置文件 用numpy读取结构化二进制文件 微信pc防撤回修改笔记 关于在python中时间的转换 把本地vscode项目代码传到gitee上
写个chrome插件屏蔽某些视频,防止孩子看些不正常的视频
隐客 · 2025-12-01 · via 博客园 - 隐客

Posted on 2025-12-01 11:22  隐客  阅读(63)  评论()    收藏  举报

manifest.json

{
  "manifest_version": 3,
  "name": "抖音关键词屏蔽",
  "version": "1.0",
  "description": "屏蔽抖音视频标题中包含'xxxxxx'关键词的视频",
  "permissions": ["activeTab"],
  "content_scripts": [
    {
      "matches": ["*://*.douyin.com/*"],
      "js": ["content.js"],
      "run_at": "document_end"
    }
  ],
  "action": {
    "default_popup": "popup.html"
  }
}

 content.js

// ======== 用户配置 ========
const blockWords = ['惊悚', 'steam游戏', '画离弦', '猫meme', 'roblox'];
const jumpURL = 'about:blank';
// ==========================

const pattern = new RegExp(
  blockWords.map(w => w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|'),
  'i'
);

/* 1. 取“正在播放”的卡片节点 */
function getActiveCard() {
  // 正在播放的 <video> 必定带 autoplay 属性
  const activeVideo = document.querySelector('video[autoplay]');
  if (!activeVideo) return null;

  // 向上找最近的卡片容器
  return activeVideo.closest('[data-e2e="feed-item"], .dySwiperSlide');
}

/* 2. 在卡片内拿标题 + account,合并文本 */
function getCurrentText() {
  const card = getActiveCard();
  if (!card) return '';

  const desc = card.querySelector('div.title[data-e2e="video-desc"]');
  const acc  = card.querySelector('div.account');
  const t1 = desc ? desc.textContent.trim() : '';
  const t2 = acc  ? acc.textContent.trim()   : '';

  //console.log('[DBG] 当前卡片标题:', t1, '| account:', t2);
  return `${t1} ${t2}`.trim();
}

/* 3. 检查 + 跳转 */
function check() {
  const txt = getCurrentText();
  if (txt && pattern.test(txt)) {
    //console.log('[Block] 命中关键词,立即跳转 → ', txt);
    location.replace(jumpURL);
  }
}

/* 4. 监听:DOM 变化 / 路由变化 */
const observer = new MutationObserver(check);
observer.observe(document.body, {
  childList: true,
  subtree: true,
  attributes: true,
  attributeFilter: ['autoplay']   // <video autoplay> 出现就触发
});

/* 5. 路由变化也补一次 */
let lastHref = location.href;
setInterval(() => {
  if (location.href !== lastHref) {
    lastHref = location.href;
    setTimeout(check, 2000); // 等新卡片渲染完
  }
}, 2000);

/* 6. 首次运行 */
check();

popup.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"><!-- 关键:指定 UTF-8 -->
  <style>
    body { width: 200px; padding: 12px; font: 14px/1.4 sans-serif; }
    .ok { color: #4CAF50; font-weight: bold; }
  </style>
</head>
<body>
  <h3>抖音关键词屏蔽</h3>
  <p>状态: <span class="ok">运行中</span></p>
  <p>屏蔽关键词: xxx </p>
</body>
</html>