// ==UserScript== // @name 佰斯特Temu运营-店小秘上架货号便捷同步增减 // @namespace http://tampermonkey.net/ // @version 1.4 // @description 店小秘上架货号SKU货号框按钮联动,支持手动输入联动同步,按钮嵌入输入框 // @match https://www.dianxiaomi.com/pddkjProduct/quoteEdit.htm* // @grant none // @run-at document-end // ==/UserScript== (function () { 'use strict'; const mainInputSelector = '#productNumber'; const skuInputSelector = 'input.form-component.sameVarinatIpt.p-right24:first-child'; function waitForInputs(callback) { const interval = setInterval(() => { const mainInput = document.querySelector(mainInputSelector); const skuInput = document.querySelector(skuInputSelector); if (mainInput && skuInput) { clearInterval(interval); callback(mainInput, skuInput); } }, 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.1s 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); } waitForInputs((mainInput, skuInput) => { 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); // 添加监听,保持手动同步 mainInput.addEventListener('input', () => syncValues(mainInput, skuInput)); skuInput.addEventListener('input', () => syncValues(skuInput, mainInput)); }); })();