// ==UserScript==
// @name 资讯阅读器
// @namespace https://bbs.tampermonkey.net.cn/
// @version 1.4.0
// @description 对多个新闻网站进行宽版处理,隐藏干扰元素,提升阅读体验
// @author ZZW
// @match https://*.tophub.today/*
// @match https://www.guancha.cn/*
// @match https://*.163.com/*
// @match https://*.sina.com.cn/*
// @match https://*.news.sina.com.cn/*
// @match https://www.toutiao.com/article/*
// @match https://www.thepaper.cn/*
// @match https://www.36kr.com/*
// @match https://36kr.com/*
// @match https://news.qq.com/rain/a/*
// @match https://www.ithome.com/*
// @match https://www.sohu.com/*
// @match https://www.guokr.com/article/*
// @match https://www.xinhuanet.com/*
// @match https://*.news.cn/*
// @match https://*.ifeng.com/*
// @match https://*.msn.cn/*
// @require https://lib.baomitu.com/jquery/3.5.0/jquery.min.js
// @grant GM_addStyle
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
/* global $ */
// ==================== 网站配置 ====================
const siteConfig = {
// 今日热榜
tophub: {
match: /https:\/\/(.*\.)?tophub\.today(\/.*)?$/,
styles: `
.cq, .alert-warning, .bb-TT,
#page > div.c-d.c-d-e > div.abcdefg {
display: none !important;
}
body {
max-width: 80% !important;
margin: auto !important;
}
.mp .aa .tt, .cc-cd-cb .cc-cd-cb-l .cc-cd-cb-ll {
font-size: 14px !important;
}
#scroll-sidebar {
position: fixed !important;
top: 64px !important;
left: 0 !important;
width: 130px !important;
height: calc(100vh - 64px) !important;
background: rgba(255,255,255,0.98) !important;
display: flex !important;
flex-direction: column !important;
padding: 12px 0 !important;
z-index: 99999 !important;
overflow-y: auto !important;
box-shadow: 2px 0 5px rgba(0,0,0,0.1) !important;
}
#scroll-sidebar button {
flex: 0 0 auto !important;
width: 100% !important;
padding: 12px 0 !important;
border: none !important;
border-bottom: 1px solid #f0f0f0 !important;
cursor: pointer !important;
background: transparent !important;
text-align: center !important;
font-size: 14px !important;
transition: background 0.3s !important;
outline: none !important;
}
#scroll-sidebar button:hover {
background: #f8f9fa !important;
}
`,
handler: () => {
const isHomePage = window.location.host === 'tophub.today' &&
window.location.pathname === '/';
if (isHomePage) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
addTophubSidebar();
});
} else {
addTophubSidebar();
}
}
}
},
// 观察者网
guancha: {
match: /https:\/\/www\.guancha\.cn\/.*/,
exclude: [
"https://www.guancha.cn/economy?s=dhcaijing",
"https://www.guancha.cn/chanjing?s=dhchanjing",
"https://www.guancha.cn/gongye%C2%B7keji?s=dhgongye%C2%B7keji",
"https://www.guancha.cn/ChengShi"
],
styles: `
body > div.content > div.main.content-main > ul > li.left.left-main {
width: 1100px;
}
.search.fix, .content-topnews-box-neo, .content-headline,
.head-inpost, .fenwen24, .latest-video,
.module-news-2, .kuaixun-new, .content-bottom-ad {
display: none !important;
}
`,
handler: () => {
const isExcluded = siteConfig.guancha.exclude
.some(url => location.href === url);
if (!isExcluded) {
GM_addStyle(`
.new-left-list { display: none !important; }
`);
}
}
},
// 网易
netease: {
match: /https:\/\/.*\.163\.com\/.*/,
exclude: /https:\/\/music\.163\.com\/.*/,
styles: `
div.post_side,
div.right_box,
div.post_next,
body > a.newsapp-qrcode,
body > a.newsapp-qrcode > img,
#contain > a.newsapp-qrcode,
#index2016_wrap > div.ns_sidebar.none > div.ns_side_qrcode,
div.qrcode,
div.ns-side-qrcode > i.ic_qrcode,
div.ic_qrcode,
div.sidebar_qrcode,
div.ns_side_qrcode > i.ft_icons.ic_qrcode,
div.post_recommends.js-tab-mod,
div.ad-left-bottom,
div.ad-right-bottom,
div.mod_js_ad,
div.post_area.post_columnad_top,
div.post_area.post_columnad_btm,
div.animation-box {
display: none !important;
}
/* 确保父容器有足够宽度以允许子元素居中 */
#container > div.post_main,
#contain > div.post_main,
body > div.page_wrap > div.container.clearfix > div.left_box.clearfix > div.title_wrap {
width: 100% !important;
box-sizing: border-box !important;
}
body > div.page_wrap > div.container.clearfix > div.left_box.clearfix,
body > div.page_wrap > div.container.clearfix > div.left_box.clearfix > div.title_wrap {
width: 1200px !important;
}
/* 设置目标元素宽度并相对于父容器居中 */
#container > div.post_main > h1.post_title,
#container > div.post_main > div.post_info,
#contain > div.post_main > h1.post_title,
#contain > div.post_main > div.post_info,
div.title_wrap > h1,
div.title_wrap > div.title_intro {
width: 1000px !important;
margin-left: auto !important;
margin-right: auto !important;
display: block !important;
}
div.post_body,
div.post_author,
div.post_statement,
#post_comment_area {
width: 1000px !important;
}
`
},
// 新浪新闻
sina: {
match: /https:\/\/.*(\.sina\.com\.cn|news\.sina\.com\.cn)\/.*/,
styles: `
#article.article, #artibody.article,
#wrap_bottom_omment.blk-comment,
#bottom_sina_comment.blk-comment.sina-comment-wrap,
#bottom_sina_comment.sina-comment-wrap,
#bottom_sina_comment > div.sina-comment-form.sina-comment-top,
.sina-comment-list.sina-comment-list-has-all {
min-width: 1100px !important; /* 最小宽度 */
max-width: 1100px !important; /* 最大宽度 */
width: 1100px !important;
}
#bottom_sina_comment > div.sina-comment-form.sina-comment-top {
width: 1100px !important;
min-width: 1100px !important;
max-width: 1100px !important;
box-sizing: border-box;
position: relative;
float: none;
flex: none !important;
grid-column: auto !important;
display: block;
}
#bottom_sina_comment.sina-comment-wrap {
margin: 0;
padding: 0;
}
.main-nav, .top-banner.clearfix,
.article-content-right, #heimaogif, #most_read.most-read,
.article-bottom-tg, .blk-zcapp.clearfix,
.baby-app, .fashion-app,
#tab_related.blk-related.clearfix,
.vip-class, .app-viplive, .otherContent_01,
.side-btns-jifen2022, #rightad.Pop-ups,
body > div.side-btns-2w > a.side-btns-2w-img,
body > div.side-btns-2w > a.side-btns-2w-close,
#sinaadToolkitBox0, #sinaadToolkitBox1, #sinaadToolkitBox2,
#sinaadToolkitBox3, #sinaadToolkitBox4,
#sinaadToolkitBox5, #sinaadToolkitBox6,
ins.sinaads.sinaads-done, .mod-01, .mod03,
body > div.main > div.part-l.clearfix,
body > div.main > div.part-l.clearfix > div.part-l-l,
body > div.main > div.part-l.clearfix > div.part-l-m,
body > div.main > div.part-l.clearfix > div.part-l-r,
body > div.main > div.part-n.clearfix > div.part-n-l,
#SI_Wrap > div > div.side,
#footer > div.ft-list {
display: none !important;
}
#article.article.article.article {
font-size: 14px;
line-height: 40px;
}
#article.article.article {
letter-spacing: 1px;
}
#article.article {
line-height: 1.5;
}
#article.article p {
margin-bottom: 10px;
}
`,
handler: () => {
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('[id]').forEach(el => {
if (/^ad_[0-9]+$/.test(el.id)) {
el.setAttribute('style', 'display: none !important;');
}
});
});
}
},
// 今日头条
toutiao: {
match: /https:\/\/www\.toutiao\.com\/article\/.*/,
styles: `
.article-detail-container .main, .ttp-comment-block {
width: auto !important;
}
.article-detail-container .right-sidebar, .detail-end-feed,
.seo-hot-link-list, .feed-m-loading,
.article-detail-container .main .divide {
display: none !important;
}
`,
handler: () => {
const observer = new MutationObserver(() => {
$('.check-more-reply:not(.done)').addClass('done').click();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
},
// 澎湃新闻
thepaper: {
match: /https:\/\/www\.thepaper\.cn\/.*/,
styles: `
div.leftcontent__XcRTe.leftClass__m4gYo,
#__next > main > div.container__zfO7K.normalContentWrap__i8VSb > div > div.wrap__hPMpF,
#__next > main > div.container__zfO7K.normalContentWrap__i8VSb > div > div.recommendsWrap__qarPN,
#__next > main > div.container__zfO7K.normalContentWrap__i8VSb > div > div.commentWrap__jer7i,
div.leftcontent__XcRTe.leftClass__m4gYo > div.wrap__hPMpF > div.wrapper__U7hc_,
div.leftcontent__XcRTe.leftClass__m4gYo > div.commentWrap__jer7i > #commentWrapper {
width: 1000px!important;
margin: 0 auto!important;
}
#__next > main > div.container__zfO7K.normalContentWrap__i8VSb > div > div.recommendsWrap__qarPN {
margin-top: 40px!important;
}
#__next > main > div.container__zfO7K.normalContentWrap__i8VSb > div > div.commentWrap__jer7i {
margin-left: 0px!important;
}
div.content__H_J57,
div.content__H_J57 > div.commonsider__BzNmZ{
display:none!important;
}
`
},
// 36氪
kr36: {
match: /https:\/\/(www\.36kr\.com|36kr\.com)\/.*/,
styles: `
.article-left-container, .article-content, .thumb-up-box,
.navbar-wrapper, .common-width, .common-width.margin-bottom-20,
.navbar-inner-box, .wrapper, .kr-plugin-comment {
width: 1030px !important;
}
.thumb-up-box {
display: flex;
justify-content: center;
align-items: center;
}
.relate-articles, article-right-container, .app-track-card,
.list-author-wrapper, #article-detail-right-qifu, .article-follow-content,
.next-card-wrapper-box, .article-Enterprise-wrappper,
.kr-article-enterprise, .kr-article-follow {
display: none !important;
}
`
},
// 腾讯新闻
qq: {
match: /https:\/\/news\.qq\.com\/rain\/a\/.*/,
exclude: /https:\/\/news\.qq\.com\/rain\/a\/UTR\d+($|\?)/,
styles: `
.content-article, #qqcom-comment { width: 1000px !important; }
#article-content > div[class*="comps-contentify"][class*="-wrap"] > div > p img {
min-width: 1000px !important; width: 1000px !important; }
#article-content [id$="_wrap"].videoPlayer {
min-height: 562.5px !important; height: 562.5px !important; }
.download-banner-wrap, .banner-bg, .oJRu_cx9EEuyfxvDz0As, #recommend,
#content-right, #ArticleBottom, [id^="PC_comment_stream_ad_"],
#topAd, .ad-news ad- { display: none !important; }
.content-left-wrapper {
width: 100% !important;
padding: 0 !important;
margin: 0 !important;
box-sizing: border-box !important;
}
div.content-left {
margin-left: 300px !important;
position: static !important;
left: auto !important;
transform: none !important;
margin-top: 0 !important;
margin-bottom: 0 !important;
}
div.qqweb-pc-content.no-right,
div.qqweb-pc-content {
padding: 0 !important;
margin: 0 !important;
width: 100% !important;
}
`,
handler: () => {
$(() => {
const $contentLeft = $('div.content-left');
if ($contentLeft.length) {
$contentLeft
.not('.content-left-wrapper > div')
.wrap('
');
}
});
}
},
// IT之家
ithome: {
match: /https:\/\/www\.ithome\.com\/.*/,
styles: `
.fl.content {
width: 1100px !important;
}
#ilikeit-div, #tt.bb, .fr.fx, #dajia, .dajia,
.down_app, #dt > div.fl.content > div.related_post > div.title,
#dt > div.fl.content > div.related_post > div.list_3,
#dt > div.fl.content > div.related_post > ul > li {
display: none !important;
}
`
},
// 搜狐新闻
sohu: {
match: /https:\/\/www\.sohu\.com\/.*/,
styles: `
#right-side-bar, #articleAllsee, #god_bottom_banner,
#left-bottom-ad, #article-do, #backsohucom,
.groom-read, #groomRead {
display: none !important;
}
.article-page #article-container .main {
width: 900px !important;
}
`
},
// 果壳
guokr: {
match: /https:\/\/www\.guokr\.com\/article\/.*/,
styles: `
.layout__Wrapper-zgzfsa-1.Article__StyleWrapper-sc-1dunux7-2.eflYNZ,
.layout__Skeleton-zgzfsa-3.styled__ArticleTitle-sc-1ctyfcr-0.ejzYGj,
.layout__Skeleton-zgzfsa-3.styled__ArticleInfo-sc-1ctyfcr-2.bTXgLO,
.layout__Skeleton-zgzfsa-3.styled__ArticleContent-sc-1ctyfcr-4.bxHoEL {
width: 1000px !important;
}
.layout__Wrapper-zgzfsa-1.gsxfuW {
display: none !important;
}
`
},
// 新华网
xinhua: {
match: /https:\/\/(www\.xinhuanet\.com\/.*|.*\.news\.cn\/.*)/,
handler: () => {
$(document).ready(function() {
const removeSelectors = [
'div.main-right.right',
'div.fix-ewm.domPC > img',
'div.main-bar'
];
$(removeSelectors.join(',')).remove();
const targetWidth = '1200px';
const originalWidthToKeep = 1000;
['div.main-left.left', '#detail'].forEach(selector => {
$(selector).each(function() {
const currentWidth = parseInt($(this).css('width'), 10);
if (currentWidth < originalWidthToKeep) {
$(this).css('width', targetWidth);
}
});
});
const $target = $('span.fxd-khd');
if ($target.length) {
const targetOffset = $target.offset();
$('