// ==UserScript== // @name KJL后台-编辑器部件栏添加分类隐藏 // @namespace Violentmonkey Scripts // @match https://www.kujiale.com/vc/modeleditor/new // @grant none // @version 1.0 // @author hejie13250 // @description 2024/11/26 22:10:03 // ==/UserScript== (function() { 'use strict'; // 添加样式到文档 var style = document.createElement('style'); document.head.appendChild(style); style.type = 'text/css'; style.appendChild(document.createTextNode(` /* 轮廓线的线宽与颜色 */ .profile-canvas .canvas-items-container .line { stroke-width: 10; stroke: rgba(0,0,0,.65); } /* 轮廓线选中后的线宽与颜色 */ .profile-canvas .canvas-items-container .line.selected { stroke-width: 10; stroke: #1a7af8; } `)); // 创建隐藏按钮的函数 function createHideButtonForAll() { // 获取所有的ul.tui-tree-new元素 var treeNewElements = document.querySelectorAll('ul.tui-tree-new'); treeNewElements.forEach(function(treeNew) { // 查找特定的子元素位置 var targetElement = treeNew.querySelector('li:nth-child(1) > span:nth-child(1) > span:nth-child(2) > div:nth-child(1) > div:nth-child(1) > span:nth-child(1) > span:nth-child(1)'); if (targetElement) { // 检查按钮是否已经存在,以避免重复添加 if (targetElement.nextElementSibling && targetElement.nextElementSibling.classList.contains('fwwEgA')) { return; } // 创建隐藏按钮 var link = document.createElement('a'); link.setAttribute('role', 'button'); link.setAttribute('aria-disabled', 'false'); link.setAttribute('class', 'fwwEgA'); link.textContent = '全部隐藏'; // 添加点击事件监听器以隐藏文本 link.addEventListener('click', function() { // 获取ul中的所有需要隐藏的元素 var hideButtons = treeNew.querySelectorAll('.param-iconfont'); hideButtons.forEach(function(button) { button.click(); // 模拟点击隐藏按钮 }); }); // 在目标元素后插入隐藏按钮 targetElement.parentNode.insertBefore(link, targetElement.nextSibling); } }); } // MutationObserver配置 var observer = new MutationObserver(function(mutationsList) { mutationsList.forEach(function(mutation) { if (mutation.type === 'childList') { // 当子节点列表变化时,为所有ul.tui-tree-new添加按钮 createHideButtonForAll(); } }); }); // 观察器选项(监控子节点列表变化和子树变化) var config = { childList: true, subtree: true }; // 开始监视body的变化 observer.observe(document.body, config); // 初始化时也为所有ul.tui-tree-new添加按钮 createHideButtonForAll(); })();