当前位置: 首页 > news >正文

油猴简书净化 - 冷夜

// ==UserScript==
// @name 简书文章页右侧广告屏蔽
// @namespace http://tampermonkey.net/
// @version 1.3.0
// @description 屏蔽简书文章页面右侧的广告和推广内容
// @author MiMo
// @match https://www.jianshu.com/p/db955a810a2e
// @match https://www.jianshu.com/p/*
// @match https://jianshu.com/p/*
// @grant none
// @run-at document-end
// ==/UserScript==

(function() {
'use strict';

// 等待页面加载完成
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}

function init() {
console.log('简书广告屏蔽脚本已启动,当前页面:' + location.href);

// 初始屏蔽
hideAds();

// 使用MutationObserver监听动态内容
const observer = new MutationObserver(function(mutations) {
let shouldHide = false;
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length > 0) {
shouldHide = true;
}
});
if (shouldHide) {
setTimeout(hideAds, 100);
}
});

observer.observe(document.body, {
childList: true,
subtree: true
});

// 定期检查,确保广告被屏蔽
setInterval(hideAds, 3000);
}

function hideAds() {
// 隐藏右侧侧边栏广告
const selectors = [
'div._1pUUKr',
// 侧边栏容器
'.aside',
'.sidebar',
'aside',
'[class*="sidebar"]',
'[class*="aside"]',

// 推荐作者/关注区域
'.recommended-authors',
'.recommendation',
'.follow-list',
'.note-list',

// 下载APP相关
'.download-app',
'.qrcode',
'.app-download',
'[class*="download"]',

// 广告容器
'.ad-container',
'.ad-banner',
'.ad-wrapper',
'[class*="ad"]',
'[class*="banner"]',
'[class*="promo"]',

// 通过内容判断
'div:contains("下载APP")',
'div:contains("扫码")',
'div:contains("推荐作者")',
'div:contains("广告")',
'div:contains("推广")'
];

selectors.forEach(selector => {
try {
const elements = document.querySelectorAll(selector);
elements.forEach(el => {
const text = el.textContent || el.innerText || '';
const className = el.className || '';

// 检查是否包含广告相关关键词
const hasAdKeywords = /广告|推广|下载APP|扫码|推荐作者|关注/i.test(text);

// 侧边栏相关类名
const isSidebarRelated = /sidebar|aside|recommend/i.test(className);

if (hasAdKeywords || isSidebarRelated) {
el.style.display = 'none';
el.style.visibility = 'hidden';
el.style.opacity = '0';
el.style.height = '0';
el.style.minHeight = '0';
el.style.maxHeight = '0';
el.style.overflow = 'hidden';
el.style.position = 'absolute';
el.style.zIndex = '-9999';
}
});

//左侧点赞
const targetElements = document.querySelectorAll('div._1pUUKr');
targetElements.forEach(element => {
element.style.display = 'none';
//console.log('已屏蔽元素: div._1pUUKr');
});

} catch (e) {
// 忽略选择器错误
}
});

// 特殊处理:检查页面右侧栏
const rightSidebar = document.querySelector('.aside, .sidebar, aside');
if (rightSidebar) {
const sidebarText = rightSidebar.textContent || '';
const hasAdContent = /广告|推广|下载|扫码|推荐/i.test(sidebarText);

if (hasAdContent) {
rightSidebar.style.display = 'none';
rightSidebar.style.visibility = 'hidden';
rightSidebar.style.width = '0';
rightSidebar.style.minWidth = '0';
rightSidebar.style.maxWidth = '0';
}
}

// 处理文章页的推荐文章区域
const noteList = document.querySelector('.note-list');
if (noteList) {
const parent = noteList.parentElement;
if (parent && /aside|sidebar/i.test(parent.className || '')) {
parent.style.display = 'none';
parent.style.visibility = 'hidden';
}
}

// 隐藏所有包含广告文字的元素
const allElements = document.querySelectorAll('div, section, aside');
allElements.forEach(el => {
const text = el.textContent || '';
if (text.length < 200 && /广告|推广|下载APP|扫码|给文章点赞/i.test(text)) {
el.style.display = 'none';
el.style.visibility = 'hidden';
}
});
}

// 添加CSS样式确保广告被完全隐藏
const style = document.createElement('style');
style.textContent = `
/* 隐藏简书右侧侧边栏 */
.aside, .sidebar, aside,
[class*="sidebar"], [class*="aside"] {
display: none !important;
visibility: hidden !important;
width: 0 !important;
min-width: 0 !important;
max-width: 0 !important;
height: 0 !important;
min-height: 0 !important;
max-height: 0 !important;
overflow: hidden !important;
position: absolute !important;
left: -9999px !important;
}

/* 隐藏推荐作者 */
.recommended-authors,
.recommendation,
.follow-list {
display: none !important;
visibility: hidden !important;
}

/* 隐藏下载APP相关 */
.download-app,
.qrcode,
.app-download {
display: none !important;
visibility: hidden !important;
}

/* 隐藏广告容器 */
.ad-container,
.ad-banner,
.ad-wrapper {
display: none !important;
visibility: hidden !important;
}

/* 扩展主内容区域 */
.main-container,
.article-content,
.content-area,
[class*="main"],
[class*="content"] {
width: 100% !important;
max-width: 100% !important;
margin-right: 0 !important;
padding-right: 0 !important;
}

/* 确保文章内容居中显示 */
.post,
.article,
[class*="post"],
[class*="article"] {
max-width: 100% !important;
}
`;
document.head.appendChild(style);

// 控制台日志
console.log('简书右侧广告屏蔽插件已启用');
})();

http://www.jsqmd.com/news/778268/

相关文章:

  • 提示工程实战指南:从核心原则到高级应用场景解析
  • YOLO训练翻车实录:从‘dog’和‘man’数据集到工业缺陷检测的实战避坑指南
  • Armv9-A架构扩展与嵌入式追踪技术解析
  • AI 内容导出乱、格式崩、公式变?我开发了这只鸭子帮我全解决了(三)** AI导出鸭 专写学生篇:从课堂笔记到毕业论文,AI 导出的那些坑
  • 基于SwiftUI与Combine的AR眼镜AI语音助手开发实战
  • 企业边缘计算设备INA1607:硬件架构与应用解析
  • 2026 年郑州首选:百莱创汽车贴膜工厂店靠谱揭秘 - 贴膜攒钱买霍希
  • 机器人通信的通信渠道
  • AI 内容导出乱、格式崩、公式变?我开发了这只鸭子帮我全解决了(五)** AI导出鸭 专写开发者篇:技术文档、代码导出、API文档,那些细节决定成败
  • 2026宁波婚纱摄影口碑排名:从客户真实评价数据,看宁波婚纱照哪家好 - charlieruizvin
  • Z-Image开源工具用户反馈实录:AI工程师如何用Z-Image-LM提升调试效率3倍
  • 从OpenClaw到Bramble:构建可破解、安全可控的AI代理框架实践
  • 别再写流水账了!用这个在线电影管理系统用例规约模板,3分钟搞定核心业务逻辑
  • CTFshow文件上传刷题
  • TypeORM游标分页库实战:解决大数据量分页的性能与一致性难题
  • 国内CNAS检测机构排行:权威合规与服务能力对比 - 奔跑123
  • AI设计:零基础用稿定设计+AI提示词快速生成技术封面与海报
  • 基于MCP协议构建本地AI文档解析服务器:rendoc-mcp-server实战指南
  • Chaterm:AI原生终端如何重塑运维工作流与团队协作
  • Vue+React混合架构实战:构建AI地图搜索与地理CRM应用
  • 从混淆矩阵到AUC:5分钟搞懂P-R曲线和ROC曲线的区别与联系
  • CircuitPython串口终端ANSI转义序列应用:彩色调试与动态界面实现
  • 【FourAndSix.2.01渗透测试手把手超详细教程附下载链接】
  • 真机调试实践
  • 西安商务KTV排行推荐:5家正规高端场地哪家好 口碑好 - 奔跑123
  • OpenClaw项目解析:Python自动化爬虫框架架构与实战应用
  • 户外工地长效防晒霜,硬核防晒不翻车,亲测好用的6款防晒 - 全网最美
  • vurb.ts:现代前端状态管理的可组合与类型安全实践
  • 别再死记硬背了!用eNSP模拟真实公司网络,5分钟搞懂交换机Trunk口到底怎么配
  • 2026年玉溪古法黄金品牌测评:三大维度甄选 - charlieruizvin