// ==UserScript== // @name 资讯阅读器 // @namespace https://bbs.tampermonkey.net.cn/ // @version 1.1.9 // @description 对多个新闻网站进行宽版处理,隐藏干扰元素,提升阅读体验 // @author ZZW // @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/* // @require https://lib.baomitu.com/jquery/3.5.0/jquery.min.js // @grant GM_addStyle // @run-at document-end // ==/UserScript== (function() { 'use strict'; /* global $ */ // 添加的全局变量声明 // 配置对象 - 集中管理所有网站的匹配规则和优化逻辑 const siteConfig = { // 观察者网 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 { 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 { 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 { width: 1100px !important; } .main-nav, .article-content-right, #most_read.most-read, #tab_related.blk-related.clearfix, .vip-class, .app-viplive, body > div.side-btns-2w > a.side-btns-2w-img, body > div.side-btns-2w > a.side-btns-2w-close { 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; } ` }, // 今日头条 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: ` .index_wrapper__L_zqV, .index_commentWrap__N_wpL { width: 1000px !important; } .index_content___Uhtm, .mdCard { 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-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\/.*/, styles: ` /* 文章内容和评论区宽度设置 */ .content-article, #qqcom-comment { width: 1000px!important; } /* 隐藏不需要的元素 */ .download-banner-wrap, .user-article, .qqcom-jxvideo, .banner-bg, .oJRu_cx9EEuyfxvDz0As, #recommend { display: none!important; } /* 新增的外层容器样式 */ .content-left-wrapper { width: 100% !important; padding: 0 !important; margin: 0 !important; box-sizing: border-box !important; } /* 子元素.content-left的样式设置 */ 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: function() { // 直接使用jQuery的ready方法简化DOM加载判断 $(() => { 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 { 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: function() { // 等待DOM加载完成 $(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(); $('