// ==UserScript== // @name 资讯阅读器 // @namespace https://bbs.tampermonkey.net.cn/ // @version 1.1.4 // @description 对多个新闻网站进行宽版处理,隐藏干扰元素,提升阅读体验 // @author ZZW // @match https://www.guancha.cn/* // @match https://news.163.com/ // @match https://*.163.com/* // @match https://www.163.com/* // @match https://news.sina.com.cn/* // @match https://*.news.sina.com.cn/* // @match https://*.sina.com.cn/* // @match https://www.toutiao.com/article/* // @match https://www.thepaper.cn/* // @match https://www.36kr.com/* // @match https://www.36kr.com/p/* // @match https://www.36kr.com/video/* // @match https://36kr.com/* // @match https://36kr.com/p/* // @match https://36kr.com/video/* // @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://www.news.cn/* // @match https://*.news.cn/* // @match https://*.ifeng.com/c/* // @require https://lib.baomitu.com/jquery/3.5.0/jquery.min.js // @grant GM_addStyle // @run-at document-start // ==/UserScript== (function() { 'use strict'; // 配置对象 - 集中管理所有网站的匹配规则和优化逻辑 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 currentPage = window.location.href; const shouldApplyRules = !siteConfig.guancha.exclude.some( url => currentPage === url ); if (shouldApplyRules) { GM_addStyle(`.new-left-list { display: none !important; }`); } } }, // 网易 netease: { match: /https:\/\/(news|www|.*)\.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:\/\/(news|.*\.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: () => { // 使用MutationObserver自动展开评论 const observer = new MutationObserver(mutations => { mutations.forEach(() => { $('.check-more-reply:not(.done)').each(function() { $(this).click().addClass('done'); }); }); }); 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(\/|\/p\/|\/video\/).*/, 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; /* 相对于外层容器(即屏幕)左侧300px */ /* 清除原有可能干扰的样式 */ 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() { // 页面加载完成后执行容器包裹操作 $(document).ready(function() { // 选择子元素 const $contentLeft = $('div.content-left'); // 选择父容器 const $parentContainers = $('div.qqweb-pc-content.no-right, div.qqweb-pc-content'); // 当子元素和父容器都存在时执行操作 if ($contentLeft.length && $parentContainers.length) { // 给子元素套上外层容器 $contentLeft.wrap('
'); // 验证容器是否添加成功 if ($('.content-left-wrapper').length) { console.log('外层容器已成功添加,布局隔离生效'); } else { console.log('外层容器添加失败,使用备选样式'); // 备选方案:直接调整子元素样式 $contentLeft.css({ 'margin-left': '300px', 'position': 'static' }); } } }); } }, // 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\/.*|(www\.|.*\.)?news\.cn\/.*)/, handler: function() { /** * 移除指定选择器对应的元素 */ function removeElements() { const selectors = [ 'div.main-right.right', 'div.fix-ewm.domPC > img', 'div.main-bar' ]; selectors.forEach(selector => { const elements = document.querySelectorAll(selector); elements.forEach(element => { if (element) { element.parentNode.removeChild(element); } }); }); } /** * 修改指定选择器对应元素的宽度 */ function changeWidth() { const targetWidth = '1200px'; const originalWidthToKeep = '1000px'; const targetSelectors = [ 'div.main-left.left', '#detail' ]; targetSelectors.forEach(selector => { const elements = document.querySelectorAll(selector); elements.forEach(element => { if (element) { const currentWidth = parseInt(window.getComputedStyle(element).width, 10); const originalWidthValue = parseInt(originalWidthToKeep, 10); if (currentWidth < originalWidthValue) { element.style.width = targetWidth; } } }); }); } /** * 创建回到顶部按钮 */ function createBackToTopButton() { const targetElement = document.querySelector('span.fxd-khd'); if (!targetElement) return; // 如果目标元素不存在则不创建按钮 const backToTopBtn = document.createElement('button'); backToTopBtn.textContent = '▲'; backToTopBtn.id = 'back-to-top-btn'; const targetRect = targetElement.getBoundingClientRect(); // 样式设置 Object.assign(backToTopBtn.style, { width: '50px', height: '50px', position: 'fixed', left: `${targetRect.left + window.scrollX}px`, top: `${targetRect.bottom + window.scrollY + 30}px`, backgroundColor: '#000', color: 'white', border: 'none', borderRadius: '5px', cursor: 'pointer', fontSize: '24px', display: 'flex', alignItems: 'center', justifyContent: 'center', zIndex: '9999' }); backToTopBtn.addEventListener('click', () => { window.scrollTo({ top: 0, behavior: 'smooth' }); }); document.body.appendChild(backToTopBtn); } // 确保在DOM加载完成后执行 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { removeElements(); changeWidth(); createBackToTopButton(); }); } else { removeElements(); changeWidth(); createBackToTopButton(); } } }, // 凤凰网 ifeng: { match: /https:\/\/.*\.ifeng\.com\/c\/.*/, styles: ` [class^="index_artical_"] { width: 1000px !important; } [class^="index_video_"] { width: 999px !important; height: 791px !important; } [class^="index_video_"]> div, [class^="index_video_"]> div > div, [class^="index_video_"]> div > div > div, [class^="style_c_video__poster_"], [class^="vjs_video_"] { width: 999px !important; height: 791px !important; } [class^="index_rightContent_"], [class^="index_recommend_"], .index_title_9X1oe, .index_list_box_TLUw-, .index_box_HGdrQ, .index_bottomNew_psdHw, .index_fixSales_VS7Xm, [class^="index_headerlogo_"], [class^="index_qrCodeBox_"], #js_vfeed.index_vPanelFeed_XKhLI, [class^="index_rightPart_"], [class^="index_hotTopic_"], .index_container_sQwKn, [class^="index_audioTopic_"], .index_container_EuROe, .index_container_GxL7r, .index_hardAd_hPMFB { display: none !important; } ` } }; // 主执行函数 function initScript() { const currentUrl = window.location.href; // 查找匹配的网站配置 for (const [site, config] of Object.entries(siteConfig)) { try { const isMatch = typeof config.match === 'function' ? config.match(currentUrl) : currentUrl.match(config.match); if (isMatch) { console.log(`Applying optimizations for: ${site}`); // 添加样式 if (config.styles) { GM_addStyle(config.styles); } // 执行处理函数 if (config.handler) { if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', config.handler); } else { config.handler(); } } // 找到匹配后退出循环 break; } } catch (error) { console.error(`Error processing site ${site}:`, error); } } } // 启动脚本 initScript(); })();