// ==UserScript== // @name KJL后台-编缉器功能增强 // @namespace Violentmonkey Scripts // @match https://www.kujiale.com/vc/modeleditor/new* // @grant none // @version 1.3 // @author - // @description 2025/4/20 18:21:03 // ==/UserScript== // KJL后台-编缉器隐藏网格和高亮隐藏参数 (function() { 'use strict'; // 目标选择器 const gridButtonSelector = 'div.tuipro-bottombar-group:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1)'; const hideGridOptionSelector = 'li.visibility-menu-content-item:nth-child(1)'; const highlightButtonSelector = 'button.tui-switch:nth-child(2)'; const checkButtonSelector = 'button.tui-switch:nth-child(2)'; // 执行操作的函数 function performActions() { // 隐藏网格 let gridButton = document.querySelector(gridButtonSelector); if (gridButton) { gridButton.click(); let hideGridOption = document.querySelector(hideGridOptionSelector); if (hideGridOption) { hideGridOption.click(); gridButton.click(); // 可能是为了关闭菜单? } } else { console.log("未能找到网格按钮"); } // 高亮隐藏变量 let highlightButton = document.querySelector(highlightButtonSelector); if (highlightButton) { highlightButton.click(); } else { console.log("未能找到高亮开关按钮"); } } // 创建一个MutationObserver实例 const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { mutation.addedNodes.forEach((node) => { if (node.nodeType === 1) { // 确保是元素节点 let checkButton = node.querySelector(checkButtonSelector); if (checkButton) { performActions(); observer.disconnect(); // 执行一次后停止观察 } } }); }); }); // 配置观察选项 const config = { childList: true, subtree: true }; // 开始观察整个文档 observer.observe(document.body, config); // 初始检查,以防目标元素已经存在 let checkButton = document.querySelector(checkButtonSelector); if (checkButton) { performActions(); observer.disconnect(); // 如果已经找到,停止观察 } })(); // KJL后台-编辑器参数提示框优化 (function() { 'use strict'; // Function to reorder the first two children of the target element function reorderChildren(target) { if (target && target.children.length > 1) { // Store the first child var firstChild = target.children[0]; // Store the second child var secondChild = target.children[1]; // Remove the first child target.removeChild(firstChild); // Insert the first child after the second child target.insertBefore(firstChild, secondChild.nextSibling); } } // Create a new MutationObserver instance var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { // Check if addedNodes is not empty and the first added node is a div with the class 'auto-complete-select-list' if (mutation.addedNodes.length > 0 && mutation.addedNodes[0].classList && mutation.addedNodes[0].classList.contains('auto-complete-select-list')) { // Call the reorder function with the added node reorderChildren(mutation.addedNodes[0]); } }); }); // Start the observer observer.observe(document.body, { childList: true, subtree: true }); })(); // KJL后台-编缉器属性栏添加更新商品名称 (function() { 'use strict'; // 添加样式到文档 var style = document.createElement('style'); document.head.appendChild(style); style.type = 'text/css'; style.appendChild(document.createTextNode(` /* 可视化按钮样式 */ .auto-update-button { width: 40px; height: 20px; background-color: #ccc; border-radius: 10px; position: relative; cursor: pointer; transition: background-color 0.3s; border: none; outline: none; margin-left: 5px; } .auto-update-button::before { content: ''; position: absolute; width: 16px; height: 16px; background-color: white; border-radius: 50%; top: 2px; left: 2px; transition: transform 0.3s; } .auto-update-button.active { background-color: #4caf50; } .auto-update-button.active::before { transform: translateX(20px); } /* 文本标签样式 */ .mode-label { font-size: 16px; margin-left: 10px; margin-right: 5px; cursor: pointer; /* 手动模式时显示手形光标 */ color: #007bff; transition: color 0.3s; } .mode-label:hover { color: #fd00fd; } /* 按钮容器样式 */ .button-container { display: flex; margin-left: 10px; align-items: center; /* 垂直居中对齐 */ justify-content: flex-start; /* 水平左对齐 */ height: 30px; /* 固定高度 */ gap: 5px; /* 按钮之间的间距 */ } `)); // 设置默认更新方式 let autoUpdate = false; // 设置检测间隔时间(毫秒) const checkInterval = 100; // 添加自动/手动切换按钮和文本标签 function addButtons() { const sidebarHeader = document.querySelector('.sidebar-container .sidebar-header'); if (sidebarHeader && !document.querySelector('.button-container')) { // 创建按钮容器 const buttonContainer = document.createElement('div'); buttonContainer.classList.add('button-container'); // 创建文本标签 const modeLabel = document.createElement('span'); modeLabel.classList.add('mode-label'); modeLabel.textContent = autoUpdate ? '自动更新' : '手动更新'; // 根据模式设置文本标签的样式和点击事件 if (!autoUpdate) { modeLabel.classList.add('manual'); // 手动模式时添加样式 modeLabel.addEventListener('click', updateName); // 绑定点击事件 } // 创建自动/手动切换按钮 const autoUpdateButton = document.createElement('button'); autoUpdateButton.classList.add('auto-update-button'); autoUpdateButton.title = autoUpdate ? '自动更新已开启' : '自动更新已关闭'; // 鼠标悬停提示 // 根据 autoUpdate 状态设置初始样式 if (autoUpdate) { autoUpdateButton.classList.add('active'); } // 为按钮添加点击事件 autoUpdateButton.addEventListener('click', function() { autoUpdate = !autoUpdate; autoUpdateButton.classList.toggle('active'); autoUpdateButton.title = autoUpdate ? '自动更新已开启' : '自动更新已关闭'; // 更新鼠标悬停提示 modeLabel.textContent = autoUpdate ? '自动更新' : '手动更新'; // 更新文本标签 // 切换文本标签的样式和点击事件 if (autoUpdate) { modeLabel.classList.remove('manual'); modeLabel.removeEventListener('click', updateName); // 移除点击事件 } else { modeLabel.classList.add('manual'); modeLabel.addEventListener('click', updateName); // 绑定点击事件 } }); // 创建“查打详情”按钮 const modelDetail = document.createElement('span'); modelDetail.classList.add('mode-label'); modelDetail.textContent = '详情'; modelDetail.addEventListener('click', function() { const productNameDiv = document.querySelector('button.tui-btn--primary:nth-child(1)'); if (productNameDiv) { productNameDiv.click(); } }); // 创建“打开模型”按钮 const openModel = document.createElement('span'); openModel.classList.add('mode-label'); openModel.textContent = '打开'; openModel.addEventListener('click', function() { const openModelIcon = document.querySelector('.option-button > button:nth-child(2)'); if (openModelIcon) { openModelIcon.click(); } }); // 将文本标签和按钮添加到容器中 buttonContainer.appendChild(autoUpdateButton); buttonContainer.appendChild(modeLabel); buttonContainer.appendChild(modelDetail); buttonContainer.appendChild(openModel); // 将按钮容器插入到.sidebar-header的前面 sidebarHeader.parentNode.insertBefore(buttonContainer, sidebarHeader); } } // 手动更新名称 function updateName() { const nameLinkDiv = document.querySelector('.tui-text-overflow-multiple-line'); const nameContent = document.querySelector('.name-editor p.name-content'); const changeButton = document.querySelector('.name-change-button'); if (nameLinkDiv && nameContent && changeButton) { const nameLinkText = nameLinkDiv.textContent.trim(); const nameContentText = nameContent.textContent.trim(); if (nameLinkText !== nameContentText) { changeButton.click(); // 等待.name-editor > input出现 setTimeout(() => { const input = document.querySelector('.name-editor > input'); if (input) { input.value = nameLinkText; // 使输入框失去焦点 input.blur(); } }, 100); // 延迟100毫秒确保输入框已经加载 } } } // 自动更新名称 function autoCheckAndUpdateName() { const nameLinkDiv = document.querySelector('.tui-text-overflow-multiple-line'); const nameContent = document.querySelector('.name-editor p.name-content'); const changeButton = document.querySelector('.name-change-button'); // 确保所有元素都已加载 if (nameLinkDiv && nameContent && changeButton && autoUpdate == true) { // 获取两个元素的文本内容 const nameLinkText = nameLinkDiv.textContent.trim(); const nameContentText = nameContent.textContent.trim(); // 比较文本内容 if (nameLinkText !== nameContentText) { // 文本不同,点击.name-change-button changeButton.click(); // 等待.name-editor > input出现 setTimeout(() => { const input = document.querySelector('.name-editor > input'); if (input) { // 更新.name-editor > input内的文本 input.value = nameLinkText; // 使输入框失去焦点 input.blur(); } }, 100); // 延迟500毫秒确保输入框已经加载 } } } // 检测并添加按钮 function checkAndAddButton() { const nameEditor = document.querySelector('.name-editor'); if (nameEditor && nameEditor.offsetParent !== null) { addButtons(); autoCheckAndUpdateName(); } } // 使用setInterval来周期性检测 setInterval(checkAndAddButton, checkInterval); })(); // KJL后台-编缉器部件栏添加关闭所有干涉 (function() { 'use strict'; function createToggleButton(targetElement) { // 检查按钮是否已经存在,以避免重复添加 if (targetElement.nextElementSibling && targetElement.nextElementSibling.classList.contains('ikKMNI')) { return; } // 创建按钮 var button = document.createElement('button'); button.setAttribute('type', 'button'); button.classList.add('ikKMNI'); button.style.marginLeft= '5px'; button.style.marginLeft= '10px'; button.style.fontSize = '12px'; button.style.cursor = 'pointer'; // 设置光标为手形 button.textContent = '关闭所有干涉'; button.addEventListener('mouseover', function() { this.style.color = '#fd00fd'; this.style.setProperty('color', '#fd00fd', 'important'); }); button.addEventListener('mouseout', function() { this.style.removeProperty('color'); }); // 按钮点击事件处理函数 button.addEventListener('click', async function() { var items = document.querySelectorAll('ul.tui-tree-new:nth-child(2) > li > span:nth-child(2) > span:nth-child(2) > div:nth-child(1) > div:nth-child(1) > span:nth-child(1) > span:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2)'); for (let index = 0; index < items.length; index++) { const item = items[index]; if (item) { item.click(); console.log('点击第 ' + (index + 1) + ' 项,共 ' + items.length + ' 项'); // 等待 specificElement1 出现 const specificElement1 = await waitElement('.element-attr-groups > li:nth-child(11) > li:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(10) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1)', 500); if (specificElement1) { specificElement1.click(); console.log('点击 => 忽略内部干涉', specificElement1); // 等待 specificElement2 出现 const specificElement2 = await waitElement('.select-input-options > li.option-item:nth-child(2)', 500); if (specificElement2) { specificElement2.click(); console.log('选择 => 是', specificElement2); } } } } }); function waitElement(selector, timeout) { return new Promise(function(resolve) { const startTime = Date.now(); const interval = setInterval(function() { const element = document.querySelector(selector); if (element || (Date.now() - startTime > timeout)) { clearInterval(interval); resolve(element); } }, 100); }); } // 在目标元素后插入切换按钮 targetElement.parentNode.insertBefore(button, targetElement.nextSibling); } // MutationObserver配置 var observer = new MutationObserver(function(mutationsList) { mutationsList.forEach(function(mutation) { if (mutation.type === 'childList') { // 检查目标元素是否出现或变化 var targetElement = document.querySelector('.tui-tabs-bar-tab-content-flex'); if (targetElement) { // 在目标元素旁边创建切换按钮 createToggleButton(targetElement); } } }); }); // 观察器选项(监控子节点列表变化和子树变化) var config = { childList: true, subtree: true }; // 开始监视body的变化 observer.observe(document.body, config); })(); // KJL后台-编辑器部件栏添加分类隐藏 (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; } /* 隐藏按钮的样式 */ .fwwEgA { margin-left: 10px; cursor: pointer; color: #1a7af8; } `)); var count = 0; // 创建隐藏按钮的函数 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 = '隐藏'; // 创建隐藏布尔按钮 var booleanLink = document.createElement('a'); booleanLink.setAttribute('role', 'button'); booleanLink.setAttribute('aria-disabled', 'false'); booleanLink.setAttribute('class', 'fwwEgA'); booleanLink.textContent = '布尔'; // 添加点击事件监听器以隐藏布尔元素 booleanLink.addEventListener('click', function() { var hideButtons = treeNew.querySelectorAll('.param-iconfont.param-yixianshibuermoxing-20px, .param-iconfont.param-yincangbuermoxing-20px'); hideButtons.forEach(function(button) { button.click(); }); }); // 添加点击事件监听器以隐藏文本 link.addEventListener('click', function() { var hideButtons = treeNew.querySelectorAll('.param-iconfont.param-eye-on, .param-iconfont.param-a-duixiang_yincang_20pxbeifen2'); hideButtons.forEach(function(button) { button.click(); }); }); // 在目标元素后插入隐藏布尔按钮和全部隐藏按钮 targetElement.parentNode.insertBefore(link, targetElement.nextSibling); if(count==0){ targetElement.parentNode.insertBefore(booleanLink, targetElement.nextSibling); count++; } } }); } // 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(); })(); // KJL后台-编缉器属性项添加锁定值 (function() { 'use strict'; // 添加样式到文档 var style = document.createElement('style'); document.head.appendChild(style); style.type = 'text/css'; style.appendChild(document.createTextNode(` /* 右栏 属性 下拉框 */ div.attr-select-input div.attr-select-input-dropdown { height: auto !important; background: #fff !important; border: 1px solid #1a7af8; } div.attr-select-input div.attr-select-input-dropdown ul.select-input-options a.lock { position: absolute; margin-top: -26px !important; margin-left: 205px; } .attr-select-input .attr-select-input-dropdown .select-input-options { height: auto !important; max-height:1000px !important; } .attr-select-input .attr-select-input-dropdown .select-input-options .option-item { width: 190px !important; } .attr-select-input .attr-select-input-dropdown .select-input-options .option-item .option-label .description { width: 30px !important; } `)); function addLockAfterOptionItems() { const dropdowns = document.querySelectorAll('.attr-select-input-dropdown'); dropdowns.forEach(dropdown => { const optionItems = dropdown.querySelectorAll('.option-item'); optionItems.forEach((item, index) => { if (index > 0) { let nextSibling = item.nextElementSibling; let hasLock = false; while (nextSibling) { if (nextSibling.classList.contains('lock')) { hasLock = true; break; } nextSibling = nextSibling.nextElementSibling; } if (!hasLock) { const lockElement = document.createElement('a'); lockElement.textContent = '锁定'; lockElement.className = 'lock'; item.insertAdjacentElement('afterend', lockElement); lockElement.addEventListener('click', function() { const descriptionElement = item.querySelector('.description') || item.querySelector('.name'); const descriptionContent = descriptionElement.textContent; const inputElement = document.querySelector('.custom-input > div:nth-child(1) > div:nth-child(1) > input:nth-child(1)'); if (inputElement) { // 触发完整事件序列 const triggerEvents = ['focus', 'input', 'change', 'blur']; // 使用原型方法设置值 const valueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set; let finalValue; if (descriptionContent === 'true' || descriptionContent === 'false') { finalValue = descriptionContent; } else { finalValue = '1*' + descriptionContent; } valueSetter.call(inputElement, finalValue); // 触发框架事件 if (inputElement.__vue__) { inputElement.__vue__.$emit('input', '1*' + descriptionContent); } // 派发完整事件 triggerEvents.forEach(eventType => { const event = new Event(eventType, { bubbles: true, cancelable: true }); inputElement.dispatchEvent(event); }); // 保持焦点控制 inputElement.focus(); // 新增确认按钮点击(加在inputElement处理完成后) setTimeout(() => { document.querySelectorAll('.custom-input-btn').forEach(btn => { if (getComputedStyle(btn).display !== 'none') { btn.dispatchEvent(new MouseEvent('click', { view: window, bubbles: true, cancelable: true })); } }); }, 150); } }); } } }); }); } // 使用 MutationObserver 监听 DOM 变化 const observer = new MutationObserver(function(mutationsList) { for (const mutation of mutationsList) { if (mutation.type === 'childList') { addLockAfterOptionItems(); } } }); // 开始观察整个文档的 body,监听子节点变化 observer.observe(document.body, { childList: true, subtree: true }); // 在页面卸载时停止观察 window.addEventListener('unload', function() { observer.disconnect(); }); })();