// ==UserScript== // @name 隐藏评论区 // @namespace http://tampermonkey.net/ // @version 0.2 // @description PEACE AND LOVE,跟恶臭言论说拜拜。 // @author Young2fun // @match *://*/* // @grant none // @license GPL-3.0 License // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 获取当前页面的 URL var currentUrl = window.location.href; // 定义不同容器对应的选择器 var containers = [ { page: 'baijiahao.baidu.com', selector: '#commentModule' }, { page: 'baidu.com/s', selector: '#danmuWrapper' }, { page: 'qq.com', selector: '#qqcom-comment' } // 添加更多页面和对应的选择器 ]; // 在容器数组中查找当前页面的选择器 var commentsSelector = getSelectorForCurrentPage(currentUrl); // 如果没有匹配的页面,不执行隐藏评论的操作 if (!commentsSelector) { return; } // 获取所有匹配选择器的评论区域元素 var commentsSections = document.querySelectorAll(commentsSelector); // 遍历所有匹配的评论区域元素,并隐藏它们 commentsSections.forEach(function(section) { section.style.display = 'none'; }); // 根据当前页面的 URL 查找对应的选择器 function getSelectorForCurrentPage(url) { for (var i = 0; i < containers.length; i++) { if (url.includes(containers[i].page)) { return containers[i].selector; } } return null; } })();