您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
商品编辑批量填充颜色分类
当前为
// ==UserScript== // @name 填充颜色分类 // @namespace none // @version 0.0.4 // @description 商品编辑批量填充颜色分类 // @author 鹿秋夏 // @include /^https:\/\/sell\.publish\.tmall\.com\/tmall\/publish\.htm\?id=\d{12}$/ // @grant none // ==/UserScript== (function() { 'use strict'; // 在页面加载完成后执行代码 window.addEventListener('load', function() { // 等待指定元素加载完毕后执行代码 var waitForElement = function(callback) { var targetElement = document.querySelector("div[class='front']"); if (targetElement !== null) { callback(targetElement); } else { setTimeout(function() { waitForElement(callback); }, 100); // 等待0.1秒后重新尝试获取 } }; // 处理逻辑 waitForElement(function(targetElement) { function addCustomButton() { var xpathExpression = "//div[@class='front']"; var result = document.evaluate(xpathExpression, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); var targetElement = result.singleNodeValue; var customButton = document.createElement('button'); customButton.textContent = '填充颜色分类'; customButton.style.borderRadius = '5px'; // 圆角 customButton.style.width = '100px'; // 宽度 customButton.style.height = '32px'; // 高度 customButton.style.marginLeft = '-275px'; // 左边距 customButton.style.backgroundColor = 'rgb(234, 244, 253)'; // 背景颜色 customButton.style.color = 'rgb(76, 148, 253)'; // 字体颜色 customButton.style.outline = 'none'; // 去除焦点样式 customButton.style.border = '1px solid rgb(69, 143, 236)'; // 边框样式 customButton.style.boxShadow = 'none'; // 去除阴影样式 customButton.addEventListener('click', function() { navigator.clipboard.readText() .then(text => { // 对剪贴板内容进行分割与过滤操作,得到处理后的列表 const processedList = text.split('\n').filter(item => item.trim() !== ''); // 示例分割与过滤操作 // 循环处理列表中的每个元素 processedList.forEach((value, index) => { setTimeout(() => { const addButton = document.evaluate('(//span[@class="next-btn-helper" and text()="新增规格项"])[last()]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; addButton.click(); // 等待指定元素加载完毕 const waitForElement = function(callback) { const inputElement = document.evaluate('//input[@placeholder="主色(必选)" and @value=""]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (inputElement !== null) { callback(inputElement); } else { setTimeout(function() { waitForElement(callback); }, 100); // 等待0.1秒后重新尝试获取 } }; // 处理当前元素 waitForElement(function(inputElement) { inputElement.value = value; var event = document.createEvent('HTMLEvents'); event.initEvent("input", true, true); inputElement.dispatchEvent(event); }); }); }); }) .catch(error => { console.error(error); }); }); // 鼠标悬停时修改鼠标指针和样式 customButton.addEventListener('mouseenter', function() { customButton.style.cursor = 'pointer'; customButton.style.backgroundColor = 'rgb(204, 214, 223)'; // 悬停时的背景颜色 }); // 鼠标离开时恢复原样式 customButton.addEventListener('mouseleave', function() { customButton.style.cursor = 'auto'; customButton.style.backgroundColor = 'rgb(234, 244, 253)'; }); targetElement.parentNode.insertBefore(customButton, targetElement.nextSibling); } addCustomButton(); }); }); })();