// ==UserScript== // @name 简化新华网页面 // @namespace https://bbs.tampermonkey.net.cn/ // @version 1.0 // @description 去除新华网中的特定元素 // @author ZZW // @match https://www.xinhuanet.com/* // @match https://www.news.cn/* // @grant none // ==/UserScript== (function() { 'use strict'; /** * 移除指定选择器对应的元素 */ 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; } } }); }); } removeElements(); changeWidth(); })();