// ==UserScript== // @name 惠州佰斯特Temu运营-辅助插件-店小秘上架货号SKU同步增减/上新界面精简/标题轻松清除 // @namespace http://tampermonkey.net/ // @version 1.7 // @description 惠州佰斯特Temu运营-辅助插件-店小秘上架货号SKU同步增减/上新界面精简/标题轻松清除 // @match https://www.dianxiaomi.com/pddkjProduct/quoteEdit.htm* // @grant none // @run-at document-end // @require https://scriptcat.org/lib/881/1.2.0/script-statistics.js // @antifeature tracking // ==/UserScript== try { new SC_Statistic({ key: "g0p8kc57fz5d4lsd", }); } catch (e) { console.warn("statistic failed: ", e); } (function () { 'use strict'; const mainInputSelector = '#productNumber'; const skuInputSelector = 'input.form-component.sameVarinatIpt.p-right24:first-child'; const titleInputSelector = '#productTitle'; function waitForInputs(callback) { const interval = setInterval(() => { const mainInput = document.querySelector(mainInputSelector); const skuInput = document.querySelector(skuInputSelector); const titleInput = document.querySelector(titleInputSelector); if (mainInput && skuInput && titleInput) { clearInterval(interval); callback(mainInput, skuInput, titleInput); } }, 500); } function adjustValue(value, delta) { const match = value.match(/^(\d+)([A-Za-z]*)$/); if (!match) return value; let num = parseInt(match[1], 10); const suffix = match[2] || ''; num += delta; if (num < 0) num = 0; return `${num}${suffix}`; } function addButtonsToInput(input, onChange) { const container = document.createElement('div'); container.style.position = 'relative'; container.style.display = 'inline-block'; container.style.width = input.offsetWidth + 'px'; input.style.paddingRight = '60px'; input.parentNode.insertBefore(container, input); container.appendChild(input); const btnWrapper = document.createElement('div'); btnWrapper.style.position = 'absolute'; btnWrapper.style.right = '5px'; btnWrapper.style.bottom = '3px'; btnWrapper.style.display = 'flex'; btnWrapper.style.gap = '3px'; function makeBtn(symbol, delta) { const btn = document.createElement('button'); btn.textContent = symbol; btn.style.cssText = ` background-color: #1890ff; color: white; border: none; border-radius: 4px; font-size: 14px; width: 22px; height: 22px; cursor: pointer; transition: transform 0.2s ease; `; btn.onmousedown = () => btn.style.transform = 'scale(0.85)'; btn.onmouseup = () => btn.style.transform = 'scale(1)'; btn.onclick = () => onChange(delta); return btn; } btnWrapper.appendChild(makeBtn('-', -1)); btnWrapper.appendChild(makeBtn('+', 1)); container.appendChild(btnWrapper); } function addClearButtonToTitleInput(titleInput) { const container = document.createElement('div'); container.style.position = 'relative'; container.style.display = 'inline-block'; container.style.width = titleInput.offsetWidth + 'px'; titleInput.style.paddingRight = '60px'; titleInput.parentNode.insertBefore(container, titleInput); container.appendChild(titleInput); const btn = document.createElement('button'); btn.textContent = '清除'; btn.style.cssText = ` position: absolute; right: 70px; bottom: 30px; background-color: #ff4d4f; color: white; border: none; border-radius: 4px; font-size: 12px; padding: 0 8px; height: 22px; cursor: pointer; transition: transform 0.1s ease; `; btn.onmousedown = () => btn.style.transform = 'scale(0.9)'; btn.onmouseup = () => btn.style.transform = 'scale(1)'; btn.onclick = () => { titleInput.value = ''; titleInput.dispatchEvent(new Event('input')); // 触发 input 事件 }; container.appendChild(btn); } waitForInputs((mainInput, skuInput, titleInput) => { let isSyncing = false; const syncValues = (from, to) => { if (isSyncing) return; isSyncing = true; to.value = from.value; isSyncing = false; }; const updateBoth = (delta) => { const newVal = adjustValue(mainInput.value, delta); mainInput.value = newVal; skuInput.value = newVal; }; // 添加按钮 addButtonsToInput(mainInput, updateBoth); addButtonsToInput(skuInput, updateBoth); addClearButtonToTitleInput(titleInput); // 添加监听,保持手动同步 mainInput.addEventListener('input', () => syncValues(mainInput, skuInput)); skuInput.addEventListener('input', () => syncValues(skuInput, mainInput)); }); })();