自制插件扩宽“文章区间“样式插件
看文章宽度不够宽,那就加宽一点
开启插件后,显示文章仅居中
显示宽度1300
加载解压扩展程序,请直接选择该“文件夹”就行(文件夹路径)
一共3个文件
文件夹:csdn-style-modifier
csdn-style-modifier\content.js
csdn-style-modifier\manifest.json
csdn-style-modifier\styles.css
csdn-style-modifier\content.js
// 匹配所有 /article/details/ 路径的页面
const isTargetPage = () => /\/article\/details\/\d+/.test(window.location.pathname);
// 暴力清除浮动
const nukeFloatingAds = () => {
document.querySelectorAll('.csdn-side-toolbar, .passport-login-container').forEach(el => {
el.remove();
});
};
// 强制锁定滚动条到主体内容
const lockScrollToMain = () => {
const main = document.querySelector('main');
if (!main) return;
// 禁用页面级滚动(保留惯性滚动)
document.documentElement.style.overflow = 'hidden';
document.body.style.overflow = 'hidden';
// 启用main元素量子纠缠滚动
main.style.overflowY = 'auto';
main.style.height = '100vh'; // 视口高度
main.style.overscrollBehavior = 'contain'; // 防止穿透
// 动态补偿内容高度
const resizeHandler = () => {
main.style.minHeight = `${document.documentElement.clientHeight}px`;
};
window.addEventListener('resize', resizeHandler);
resizeHandler();
};
// 核心执行函数
function nuclearOption() {
if (!isTargetPage()) return;
// 首次加载立即执行
nukeFloatingAds();
lockScrollToMain();
// 每500ms检查一次新出现的广告(对抗动态加载)
setInterval(() => {
nukeFloatingAds();
}, 500);
// 监听SPA路由变化
let currentURL = window.location.href;
setInterval(() => {
if (window.location.href !== currentURL) {
currentURL = window.location.href;
location.reload(); // 暴力刷新确保样式生效
}
}, 1000);
}
// 创建量子态观察者
const nuclearObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.addedNodes.length) {
// 对新增节点进行降维打击
mutation.addedNodes.forEach(node => {
if (node.id === 'rightAside' || node.classList?.contains('recommend-right')) {
node.remove();
}
});
}
});
});
// 启动全域监控
nuclearObserver.observe(document.body, {
childList: true,
subtree: true,
attributes: false,
characterData: false
});
// 添加内容完整性检查
let contentLoadAttempts = 0;
const checkContentIntegrity = () => {
const article = document.querySelector('.article-content');
if (!article || article.clientHeight < 500) {
if (contentLoadAttempts++ < 5) {
setTimeout(() => {
// 触发强制重排
article?.style.display = 'none';
article?.offsetHeight;
article?.style.display = 'block';
}, 500 * contentLoadAttempts);
}
}
};
// 在nuclearOption中调用
function nuclearOption() {
// ...原有代码...
checkContentIntegrity();
}
// 启动核打击
window.addEventListener('load', nuclearOption);
// 目标选择器
const targetSelector = '#mainBox';
// 修改目标元素的 class 属性
function modifyMainBox() {
const mainBox = document.querySelector(targetSelector);
if (mainBox) {
// 移除所有 class
mainBox.className = '';
console.log('✅ mainBox 的 class 已成功移除');
} else {
console.log('❌ 未找到目标元素 #mainBox');
}
}
// 监听页面加载完成
window.addEventListener('load', modifyMainBox);
// 监听动态内容加载(适用于单页应用或异步加载)
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'childList' && document.querySelector(targetSelector)) {
modifyMainBox();
}
});
});
// 启动观察者
observer.observe(document.body, {
childList: true,
subtree: true,
});
csdn-style-modifier\styles.css
/* 移除左右侧边栏 */
.aside-box,
.report-box,
.tool-box,
.blog_container_aside,
.csdn-side-toolbar {
display: none !important;
}
/* 隐藏顶部导航栏 */
.blog-navbar,
.header-box {
display: none !important;
}
/* 强制页面全屏显示主体内容 */
body {
padding: 0 !important;
margin: 0 !important;
overflow-x: hidden !important;
}
/* 修复滚动失效 */
main {
width: 1300px !important;
overflow-anchor: none !important; /* 禁用浏览器自动滚动锚定 */
scroll-behavior: smooth !important;
-webkit-overflow-scrolling: touch !important; /* 启用iOS惯性滚动 */
}
/* 防止内容截断 */
.blog-content-box {
min-height: calc(100vh + 100px) !important; /* 预留缓冲 */
padding-bottom: 50px !important; /* 底部留白 */
}
/* 隐藏所有非 <main> 的直接子元素 */
body > *:not(main) {
display: none !important;
}
/* 保留必要的文章容器(根据实际DOM结构调整) */
.blog-content-box,
.article-content {
width: 100% !important;
margin: 0 !important;
padding: 0 20px !important; /* 左右边距20px */
}
/* 新增右侧推荐栏清除 */
#rightAside,
div[data-type="recommend"],
.aside-content,
.recommend-right {
display: none !important;
width: 0 !important;
height: 0 !important;
opacity: 0 !important;
pointer-events: none !important;
}
/* 确保父容器宽度释放 */
.main-content {
width: 100% !important;
margin-right: 0 !important;
}
.mainBox {
width: 1200px !important;
}
.container clearfix{
width: 1200px !important;
}
csdn-style-modifier\manifest.json
{
"manifest_version": 3,
"name": "xxxx 极简阅读器",
"version": "2.0",
"description": "让 xxxx 文章页变成干净的阅读模式",
"content_scripts": [{
"matches": ["*://*.xxxx.net/article/details/*"],
"css": ["styles.css"],
"js": ["content.js"],
"run_at": "document_end"
}],
"host_permissions": ["*://*.csdn.net/*"]
}
请设置好你需要的网址
如xxxx.net
"matches": ["*://*.xxxx.net/article/details/*"],
"host_permissions": ["*://*.xxxx.net/*"]