// ==UserScript== // @name 腾讯新闻-宽版 // @namespace https://bbs.tampermonkey.net.cn/ // @version 1.0.3 // @description 新闻页隐藏侧边栏和下方新闻推荐,使用外层容器隔离布局影响 // @author ZZW // @match https://news.qq.com/rain/a/* // @require https://lib.baomitu.com/jquery/3.5.0/jquery.min.js // @grant GM_addStyle // ==/UserScript== (function() { 'use strict'; // 添加自定义样式 GM_addStyle(` /* 文章内容和评论区宽度设置 */ .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; } `); // 页面加载完成后执行容器包裹操作 $(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' }); } } }); })();