// ==UserScript==
// @name HY POD快速关联
// @namespace http://tampermonkey.net/
// @license MIT
// @version 20260423.2
// @description POD快速关联 F2 多件
// @author binning
// @match https://www.haoyipod.com/*
// @match https://www2.haoyipod.com/*
// @match https://www.haoyipodeur.com/*
// @match https://www.ecofengpod.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @run-at document-end
// @grant GM_addStyle
// @require https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.14/vue.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/element-ui/2.15.6/index.min.js
// @resource element-ui-css https://cdnjs.cloudflare.com/ajax/libs/element-ui/2.15.6/theme-chalk/index.min.css
// ==/UserScript==
(function () {
'use strict';
// Inject Element UI CSS
GM_addStyle('@import url("https://cdnjs.cloudflare.com/ajax/libs/element-ui/2.15.6/theme-chalk/index.min.css");');
// Create a Vue instance for Element UI
const app = document.createElement('div');
document.body.appendChild(app);
// Define Vue component with Element UI dialog
new Vue({
el: app,
data: {
dialogVisible: false,
inputValue: ''
},
template: `
`,
methods: {
handleClose() {
this.inputValue = ''; // 清空输入框
},
// 工具函数:延迟执行,保证页面渲染完成
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
},
async confirm() {
// 按空格分割输入内容
let processedValue = this.inputValue.split(" ").filter(item => item);
console.log("处理后的内容:", processedValue);
// 1. 找到所有 款式容器 .finished-form
const finishedForms = document.querySelectorAll('.finished-form');
if (!finishedForms.length) {
console.log('未找到款式容器');
this.dialogVisible = false;
return;
}
let valueIndex = 0; // 输入内容索引
// 遍历每个款式容器
for (const form of finishedForms) {
// 2. 找到里面所有 尺码容器 .el-form-item.el-form-item--medium
const sizeItems = form.querySelectorAll('.el-form-item.el-form-item--medium');
if (!sizeItems.length) continue;
// 遍历每个尺码容器
for (const item of sizeItems) {
try {
// 3. 点击尺码容器里唯一的 i 标签
const iTag = item.querySelector('i');
if (iTag) {
iTag.click();
await this.sleep(100); // 等待弹窗/元素渲染
}
// 4. 点击尺码容器里最后一个 button 标签
const buttons = item.querySelectorAll('button');
if (buttons.length) {
const lastBtn = buttons[buttons.length - 1];
lastBtn.click();
await this.sleep(50);
}
// 5. 找到第三方SKU输入框并赋值
const skuInput = item.querySelector('input[placeholder="第三方SKU"]');
if (skuInput && processedValue[valueIndex]) {
skuInput.focus();
document.execCommand('selectAll', false, null);
document.execCommand('insertText', false, processedValue[valueIndex]);
valueIndex++;
await this.sleep(50);
}
} catch (e) {
console.warn("处理尺码项出错:", e);
continue;
}
}
}
// 完成操作
document.activeElement.blur();
this.dialogVisible = false;
console.log("批量关联完成");
},
},
mounted() {
// 监听 F2 键触发事件
window.addEventListener('keydown', (event) => {
if (event.key === 'F2') {
this.dialogVisible = true;
}
if (event.key === 'F8') {
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
document.querySelectorAll('.el-table__fixed-body-wrapper tbody .el-table__row').forEach(item=>{
if (item.querySelectorAll('[data-v-52763079].shop-item')[5]?.innerHTML.split(':')[1] != 1){
item.style.backgroundColor = 'yellow';
item.querySelector('input[type="checkbox"]')?.click();
}
})
}
// 监听 Enter 键触发确认操作
if (this.dialogVisible && (event.key === 'Enter' || event.key === 'NumpadEnter')) {
this.confirm();
}
});
// 聚焦输入框
this.$watch('dialogVisible', (newVal) => {
if (newVal) {
this.$nextTick(() => {
this.$refs.inputField.$el.querySelector('input').focus();
});
}
});
}
});
})();