// ==UserScript== // @name mteam根据评论筛选 // @namespace http://tampermonkey.net/ // @version 2024.4.1 // @description mteam 根据评论数高亮颜色, 筛选,隐藏0评论的种子,骑兵 // @author plexpt // @match https://kp.m-team.cc/* // @grant GM_log // @license MIT // @run-at document-end // @supportURL https://greasyfork.org/en/scripts/409983 // @downloadURL none // ==/UserScript== // 自执行函数,用于封装代码,防止变量污染全局作用域 (function () { try { console.log("开始执行mteam馒头优化脚本"); let totalHide = 0; // 定义变量,用于统计隐藏的0评论种子数量 let totalHideCensored = 0; // 定义变量,用于统计隐藏的骑兵种子数量 // 根据评论数和是否为骑兵来隐藏或显示表格行的函数 function hideOrShowRows(displayValue, hideZeroComment, hideCensored) { // 获取页面中的表格元素 const maintable = document.querySelector("#app-content > div > div.mt-4.app-content__inner > div > div > div.ant-table-wrapper.css-1gwm2nm > div > div > div > div > div > table"); // 获取表格中的所有行 const rows = maintable.querySelectorAll('tr'); rows.forEach((row, index) => { // 跳过表头,从第二行开始遍历 if (index > 1) { // 获取当前行的第三列(评论数) const commentCell = row.cells[3]; // 将评论数转换为整数 const commentNum = parseInt(commentCell.innerText); // 获取当前行的第一列中的链接 const categoryLink = row.cells[0].querySelector("a").href; row.style.display = ''; // 检查评论数是否为0或1,并且用户选择隐藏0评论的种子 if (hideZeroComment && commentNum <= 2) { totalHide++; // 隐藏行 row.style.display = displayValue; return; } // 检查分类链接是否包含骑兵相关的分类ID,并且用户选择隐藏骑兵种子 if (hideCensored && (categoryLink.includes("cat=431") || categoryLink.includes("cat=424") || categoryLink.includes("cat=410") || categoryLink.includes("cat=437"))) { totalHide++; // 隐藏行 row.style.display = displayValue; return; } } }); } // 封装将div添加到body元素中的函数 function appendDivToBody() { const divall = document.createElement("div"); // 设置div的样式 divall.style.cssText = "padding-left: 10%; padding-right: 10%; font-size: x-large; background: #409EFF; margin-left: 5%; margin-right: 5%; width: auto; color: #fff"; // 设置div的文本内容,显示隐藏的种子数量 divall.textContent = `成功隐藏了:${totalHide}个0评论的种子,${totalHideCensored}个骑兵的种子`; // 创建一个按钮,用于隐藏0评论的种子 const buttonHideZeroComment = document.createElement("button"); // 设置按钮的样式 buttonHideZeroComment.style.cssText = "color: #409eff; background: #ecf5ff; border-color: #b3d8ff; display: inline-block; line-height: 1; white-space: nowrap; cursor: pointer; -webkit-appearance: none; text-align: center; box-sizing: border-box; outline: none; margin: 8px; transition: .1s; font-weight: 300; padding: 6px 10px; font-size: 14px; border-radius: 4px;"; // 设置按钮的文本内容 buttonHideZeroComment.innerText = "隐藏0评论种子"; // 为按钮添加点击事件监听 buttonHideZeroComment.addEventListener('click', function () { // 根据按钮的文本内容切换隐藏或显示0评论种子,并更新按钮的文本和状态 hideOrShowRows(buttonHideZeroComment.innerText === "隐藏0评论种子" ? 'none' : '', !buttonHideZeroComment.classList.contains('hidden'), buttonHideCensored.classList.contains('hidden')); buttonHideZeroComment.innerText = buttonHideZeroComment.innerText === "隐藏0评论种子" ? "显示0评论种子" : "隐藏0评论种子"; buttonHideZeroComment.classList.toggle('hidden'); }, false); // 创建一个按钮,用于隐藏骑兵种子 const buttonHideCensored = document.createElement("button"); // 设置按钮的样式 buttonHideCensored.style.cssText = "color: #409eff; background: #ecf5ff; border-color: #b3d8ff; display: inline-block; line-height: 1; white-space: nowrap; cursor: pointer; -webkit-appearance: none; text-align: center; box-sizing: border-box; outline: none; margin: 8px; transition: .1s; font-weight: 300; padding: 6px 10px; font-size: 14px; border-radius: 4px;"; // 设置按钮的文本内容 buttonHideCensored.innerText = "隐藏骑兵种子"; // 为按钮添加点击事件监听 buttonHideCensored.addEventListener('click', function () { // 根据按钮的文本内容切换隐藏或显示骑兵种子,并更新按钮的文本和状态 hideOrShowRows(buttonHideCensored.innerText === "隐藏骑兵种子" ? 'none' : '', buttonHideZeroComment.classList.contains('hidden'), !buttonHideCensored.classList.contains('hidden')); buttonHideCensored.innerText = buttonHideCensored.innerText === "隐藏骑兵种子" ? "显示骑兵种子" : "隐藏骑兵种子"; buttonHideCensored.classList.toggle('hidden'); }, false); // 将按钮添加到div中 divall.appendChild(buttonHideZeroComment); divall.appendChild(buttonHideCensored); // 获取页面的body元素 const bodyElement = document.querySelector("#app-content > div"); // 获取页面中的主表格元素 const tableElement = document.querySelector("#app-content > div > div.ant-card.ant-card-small.css-1gwm2nm"); console.log("tableElement", tableElement); // 将div添加到body元素中,位于主表格之前 bodyElement.insertBefore(divall, tableElement); } // hideOrShowRows('', false, false); // 定义你想要监听的目标元素的CSS选择器 const targetSelector = "#app-content > div > div.ant-card.ant-card-small.css-1gwm2nm"; // 当目标元素被添加到DOM中时执行的回调函数 function onTargetElementAdded(mutations) { // 检查我们关心的元素是否已经加载 var targetElement = document.querySelector(targetSelector); // 替换为实际的CSS选择器 if (targetElement) { // 元素已找到,可以执行所需的操作 console.log('特定元素已加载,执行脚本...'); appendDivToBody(); // 一旦元素被找到并处理,可以停止观察 observer.disconnect(); } } // 创建一个MutationObserver实例并提供回调函数 const observer = new MutationObserver(onTargetElementAdded); // 配置观察选项,指定要观察的元素和观察的类型 const config = { childList: true, // 观察子元素的变化 subtree: true, // 观察整个DOM树 attributes: false, // 不观察属性变化 characterData: false, // 不观察字符数据变化 attributeOldValue: false, // 不比较属性旧值 characterDataOldValue: false // 不比较字符数据旧值 }; // 选择一个根元素来开始观察,通常是document.body或document.documentElement const rootElement = document.body; // 等待文档加载完成 document.addEventListener('DOMContentLoaded', (event) => { // 在这里编写你的脚本代码 // 由于DOM已加载完成,现在可以安全地访问页面元素 console.log("mteam馒头优化 DOMContentLoaded "); // 启动观察 observer.observe(rootElement, config); }); // 如果页面上有异步加载的内容,你可能还需要监听window的load事件 window.addEventListener('load', (event) => { // 在这里处理那些需要等待所有资源(如图片)加载完成后的任务 console.log("mteam馒头优化 load "); // appendDivToBody(); }); } catch (e) { console.error("mteam馒头优化出错了", e); } })();