您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Modeling Helper
当前为
// ==UserScript== // @name MEST Modeling Helper // @namespace joyings.com.cn // @version 1.8.1 // @description Modeling Helper // @author zmz125000 // @match http://*/mest/* // @icon http://www.google.com/s2/favicons?domain=openwrt.org // @grant none // @license MIT // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js // @run-at document-end // ==/UserScript== (function () { 'use strict'; // Your code here... addClickActions(); updateIndexBtn(); semiCellEvent(); addObserverIfDesiredNodeAvailable(); window.loaded = false; window.loadedBtn = false; window.loadedSemi = false; window.autofill = false; window.autofillMat = false; function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } function addObserverIfDesiredNodeAvailable() { var composeBox = document.querySelectorAll('[class="el-popup-parent--hidden"]')[0]; if (!composeBox) { //The node we need does not exist yet. //Wait 500ms and try again window.setTimeout(addObserverIfDesiredNodeAvailable, 500); return; } var config = { attributes: true, }; var composeObserver = new MutationObserver(function () { window.setTimeout(addClickActions, 500); window.setTimeout(updateIndexBtn, 500); window.setTimeout(semiCellEvent, 500); composeObserver.disconnect(); addObserverIfDesiredNodeAvailable(); }); composeObserver.observe(composeBox, config); } // 选择自己 async function semiCellEvent() { if (!$('button:contains(" 选择自己 ")')[0]) { window.loadedSemi = false; await sleep(500); semiCellEvent(); return; } if (window.loadedSemi) { return; } window.loadedSemi = true; $('button:contains(" 选择自己 ")')[0].addEventListener('click', async function (e) { await sleep(100); dbck(); }); await sleep(200); while (!$('button:contains(" 选择 ")', $('button:contains(" 选择自己 ")')[0].parentElement.parentElement)) { await sleep(100); } for (let btn of $('button:contains(" 选择 ")', $('button:contains(" 选择自己 ")')[0].parentElement.parentElement)) { btn.addEventListener('click', async function (e) { await sleep(500); dbck(); await sleep(500); dbck(); }); } semiCellEvent(); } // 添加按钮 async function updateIndexBtn() { if (!$('button:contains(" 新增一行 ")')[0]) { window.loadedBtn = false; await sleep(500); updateIndexBtn(); return; } if (window.loadedBtn) { return; } window.loadedBtn = true; let btnRow = $('button:contains(" 新增一行 ")')[0].parentElement; var btn = document.createElement('button'); btn.setAttribute('title', '一键更新所有序号'); btn.setAttribute('id', 'oneKeyButton'); btn.setAttribute('type', 'button'); btn.onclick = updateIndex; btn.appendChild(document.createTextNode('⇩更新序号')); var btn2 = document.createElement('button'); btn2.setAttribute('title', '重新设置自动填充'); btn2.setAttribute('id', 'reloadBtn'); btn2.setAttribute('type', 'button'); btn2.onclick = dbck; btn2.appendChild(document.createTextNode('⟳重载自动填充')); var btn3 = document.createElement('button'); btn3.setAttribute('title', '一键设置工序'); btn3.setAttribute('id', 'updateProcBtn'); btn3.setAttribute('type', 'button'); btn3.onclick = updateProcess; btn3.appendChild(document.createTextNode('⇩一键设置工序')); var btn4 = document.createElement('button'); btn4.setAttribute('title', '一键设置物料'); btn4.setAttribute('id', 'updateMaterialBtn'); btn4.setAttribute('type', 'button'); btn4.onclick = updateMaterial; btn4.appendChild(document.createTextNode('⇩一键设置物料')); var btn5 = document.createElement('button'); btn5.setAttribute('type', 'button'); btn5.onclick = readme; btn5.appendChild(document.createTextNode('❓使用说明')); btnRow.appendChild(btn); btnRow.appendChild(btn3); btnRow.appendChild(btn4); btnRow.appendChild(btn2); btnRow.appendChild(btn5); dbck(); } function readme() { alert("设置序号会使自动添加物料失灵,建议先设置好所有半成品、再手动选择首工序、再点击更新序号\n插件版本号: " + GM_info.script.version); } // 一键设置物料 async function updateMaterial() { if (!document.querySelectorAll('[class="edit-cell"]')[0]) { await sleep(500); updateMaterial(); return; } let bodyRows = document.querySelectorAll('[class="edit-cell"]')[0].closest('table').lastChild.rows; const semiIndex = $('th:contains(" 半成品/成品名称 ")')[0].cellIndex; const materialIndex = $('th:contains(" 所需物料集 ")')[0].cellIndex; window.autofillMat = true; for (let i of bodyRows) { let prevSemi = ''; if (i.rowIndex > 0) { prevSemi = bodyRows.item(i.rowIndex - 1).cells.item(semiIndex).firstChild.firstChild.firstChild.textContent; } let matCell = i.cells.item(materialIndex); matCell.firstChild.firstChild.click(); await sleep(150); await setMaterial(prevSemi, true); while ($('button:contains("新增行")')[0]) { await sleep(200); } } window.autofillMat = false; } // 一键更新序号 async function updateIndex() { if (!document.querySelectorAll('[class="edit-cell"]')[0]) { await sleep(500); updateIndex(); return; } let bodyRows = document.querySelectorAll('[class="edit-cell"]')[0].closest('table').lastChild.rows; const procIndex = $('th:contains(" 上级序号 ")')[0].cellIndex; for (let i of bodyRows) { let indexCell = i.cells.item(procIndex); if (i.cells.item(3).firstChild.firstChild.firstChild.textContent == '始工序') { continue; } indexCell.firstChild.firstChild.firstChild.click(); await sleep(50); indexCell.querySelector('[class="el-icon-setting"]').closest('a').click(); while (!$('button:contains(" 选择 ")')[i.rowIndex]) { await sleep(50); } $('button:contains(" 选择 ")')[i.rowIndex].click(); await sleep(50); } } // 一键设置工序 async function updateProcess() { if (!document.querySelectorAll('[class="edit-cell"]')[0]) { await sleep(500); updateProcess(); return; } let bodyRows = document.querySelectorAll('[class="edit-cell"]')[0].closest('table').lastChild.rows; const processIndex = $('th:contains(" 工序名称 ")')[0].cellIndex; const semiIndex = $('th:contains(" 半成品/成品名称 ")')[0].cellIndex; window.autofill = true; for (let i of bodyRows) { let name = bodyRows.item(i.rowIndex).cells.item(semiIndex).firstChild.firstChild.firstChild.textContent; await sleep(50); i.cells.item(processIndex).firstChild.firstChild.firstChild.click() await sleep(50); i.querySelector('[placeholder="工序选择"]').closest('div').querySelector('button').click(); await sleep(150); await setProcess(name); } window.autofill = false; } // 新增一行自动填写 async function addClickActions() { if (!$('button:contains(" 新增一行 ")')[0]) { window.loaded = false; await sleep(500); addClickActions(); return; } if (window.loaded) { return; } window.loaded = true; $('button:contains(" 设置工艺版本 ")')[0].addEventListener('click', async function (e) { if ($('div:contains(" 暂未设置工艺 ")')[0]) { await sleep(150); $('button:contains(" 新增工艺版本 ")')[0].click(); await sleep(150); document.querySelectorAll('[placeholder="输入工艺版本名称"]')[0].value = "default"; document.querySelectorAll('[placeholder="输入工艺版本名称"]')[0].dispatchEvent(new Event('input', { bubbles: true })); await sleep(50); $('button:contains(" 选择 ")')[0].click(); } }); while (!$('th:contains(" 半成品/成品名称 ")')[0]) { await sleep(250); } const semiIndex = $('th:contains(" 半成品/成品名称 ")')[0].cellIndex; const materialIndex = $('th:contains(" 所需物料集 ")')[0].cellIndex; const procIndex = $('th:contains(" 上级序号 ")')[0].cellIndex; const alias = document.querySelector('[placeholder="别名"]').closest('textarea').value; $('button:contains(" 新增一行 ")')[0].addEventListener('click', async function (e) { await sleep(100); let bodyRows = document.querySelectorAll('[class="edit-cell"]')[0].closest('table').lastChild.rows; // 设置上级序号 // let lastIndexCell = bodyRows.item(bodyRows.length - 1).cells.item(procIndex); // lastIndexCell.firstChild.firstChild.firstChild.click(); // await sleep(50); // lastIndexCell.firstChild.firstChild.firstChild.firstChild.click(); // while (!$('button:contains(" 选择 ")')[bodyRows.length - 1]) { // await sleep(50); // } // $('button:contains(" 选择 ")')[bodyRows.length - 1].click(); // await sleep(100); // 设置半成品 let lastSemiCell = bodyRows.item(bodyRows.length - 1).cells.item(semiIndex); lastSemiCell.firstChild.firstChild.firstChild.click(); lastSemiCell.querySelector('[placeholder="输出半成品"]').closest('div').querySelector('button').click(); await sleep(150); document.querySelectorAll('[placeholder="存货别名"]')[1].value = alias; await sleep(50); document.querySelectorAll('[placeholder="存货别名"]')[1].dispatchEvent(new Event('input', { bubbles: true })); await sleep(50); $('button:contains(" 搜索 ")')[0].click(); while ($('button:contains(" 选择自己 ")')[0]) { await sleep(100); } // 设置物料 let prevSemi = ""; if (bodyRows.length > 1) { prevSemi = bodyRows.item(bodyRows.length - 2).cells.item(semiIndex).firstChild.firstChild.firstChild.textContent; } let lastMatCell = bodyRows.item(bodyRows.length - 1).cells.item(materialIndex); lastMatCell.firstChild.firstChild.click(); await sleep(150); await setMaterial(prevSemi, false); await sleep(150); while ($('button:contains("新增行")')[0]) { await sleep(200); } dbck(); }); } // 整个表格自动填写 async function dbck() { if (!document.querySelectorAll('[class="edit-cell"]')[0]) { await sleep(500); dbck(); return; } let bodyRows = document.querySelectorAll('[class="edit-cell"]')[0].closest('table').lastChild.rows; const alias = document.querySelector('[placeholder="别名"]').closest('textarea').value; const semiIndex = $('th:contains(" 半成品/成品名称 ")')[0].cellIndex; const processIndex = $('th:contains(" 工序名称 ")')[0].cellIndex; const materialIndex = $('th:contains(" 所需物料集 ")')[0].cellIndex; const procIndex = $('th:contains(" 上级序号 ")')[0].cellIndex; // 设置上级序号 for (let i of bodyRows) { let indexCell = i.cells.item(procIndex); indexCell.addEventListener('auxclick', async function (e) { indexCell.querySelector('[class="el-icon-setting"]').closest('a').click(); await sleep(100); while (!$('button:contains(" 选择 ")')[i.rowIndex]) { await sleep(50); } $('button:contains(" 选择 ")')[i.rowIndex].click(); }); } // 半成品 for (let i of bodyRows) { let semiCell = i.cells.item(semiIndex); semiCell.addEventListener('click', async function (e) { i.querySelector('[placeholder="输出半成品"]').closest('div').querySelector('button').click(); await sleep(150); document.querySelectorAll('[placeholder="存货别名"]')[1].value = alias; await sleep(50); document.querySelectorAll('[placeholder="存货别名"]')[1].dispatchEvent(new Event('input', { bubbles: true })); await sleep(50); $('button:contains(" 搜索 ")')[0].click(); }); } // 物料集 for (let i of bodyRows) { let prevSemi = ''; if (i.rowIndex > 0) { prevSemi = bodyRows.item(i.rowIndex - 1).cells.item(semiIndex).firstChild.firstChild.firstChild.textContent; } let matCell = i.cells.item(materialIndex); matCell.addEventListener('click', async function (e) { if (!window.autofillMat) { matCell.firstChild.firstChild.click(); await sleep(150); await setMaterial(prevSemi, false); } }); } // 工序 for (let i of bodyRows) { let lastProcessCell = i.cells.item(processIndex); lastProcessCell.addEventListener('click', async function (e) { if (!window.autofill) { let name = bodyRows.item(i.rowIndex).cells.item(semiIndex).firstChild.firstChild.firstChild.textContent; i.querySelector('[placeholder="工序选择"]').closest('div').querySelector('button').click(); await sleep(150); await setProcess(name); } }); } } // 设置工序函数 async function setProcess(name) { let processName = getProcName(name); document.querySelectorAll('[placeholder="工序名称"]')[0].value = processName; await sleep(50); document.querySelectorAll('[placeholder="工序名称"]')[0].dispatchEvent(new Event('input', { bubbles: true })); await sleep(50); $('button:contains(" 搜索 ")')[0].click(); if (!document.getElementById('semiNameLabel')) { let label1 = document.createElement('label'); label1.classList.add("el-form-item__label"); label1.setAttribute('id', 'semiNameLabel'); label1.appendChild(document.createTextNode(name)); $('button:contains(" 搜索 ")')[0].parentElement.appendChild(label1); } await sleep(150); // 自动选择第一个工序名称 while (!$('td:contains("GX")')[0]) { await sleep(100); } if ($('button:contains(" 选择 ")', $('td:contains("GX")')[0].parentElement.parentElement).length == 1) { $('button:contains(" 选择 ")', $('td:contains("GX")')[0].parentElement)[0].click(); await sleep(200); } else { while ($('td:contains("GX")')[0]) { await sleep(200); } } } // 设置物料函数 async function setMaterial(prevSemi, ok) { if (!$('button:contains(" 移除 ")')[0]) { $('button:contains("新增行")')[0].click(); await sleep(100); } while (!document.querySelector('[placeholder="物料选择"]')) { await sleep(100); } if (document.querySelector('[placeholder="物料选择"]').parentElement.parentElement.parentElement.parentElement.parentElement.querySelectorAll('[placeholder="物料选择"]').length == 1) { document.querySelector('[placeholder="物料选择"]').closest('div').querySelector('button').click(); await sleep(100); document.querySelectorAll('[placeholder="存货名称"]')[1].value = prevSemi; document.querySelectorAll('[placeholder="存货名称"]')[1].dispatchEvent(new Event('input', { bubbles: true })); await sleep(50); $('button:contains(" 搜索 ")')[0].click(); await sleep(150); while (!$('button:contains(" 选择 ")')[0]) { await sleep(100); } if ($('button:contains(" 选择 ")', $('button:contains(" 选择 ")')[0].parentElement.parentElement.parentElement.parentElement).length == 1) { $('button:contains(" 选择 ")')[0].click(); await sleep(100); if (ok) { $('button:contains("确 定")', $('button:contains("新增行")')[0].parentElement.parentElement.parentElement)[0].click(); await sleep(200); } } } } function getProcName(name) { var processName = ''; if (name.includes('打磨抛光')) { processName = '打磨抛光'; } else if (name.includes('拉伸')) { processName = '拉伸'; } else if (name.includes('飞边')) { processName = '飞边'; } else if (name.includes('打磨')) { processName = '打磨'; } else if (name.includes('烧焊')) { processName = '满焊'; } else if ((new RegExp('.*冲(\\W|\\w)*孔.*')).test(name)) { processName = '冲孔'; } else if (name.includes('验收')) { processName = '验收'; } else if (name.includes('剪板')) { processName = '剪板'; } else if (name.includes('开料')) { processName = '开料'; } else if (name.includes('电镀')) { processName = '电镀'; } else if (name.includes('电泳')) { processName = '电泳'; } else if (name.includes('喷粉')) { processName = '喷粉'; } else if (name.includes('喷涂')) { processName = '喷粉'; } else if (name.includes('折弯')) { processName = '折弯'; } else if (name.includes('注塑')) { processName = '注塑'; } else if (name.includes('成型')) { processName = '成型'; } else if (name.includes('弯线')) { processName = '弯线'; } else if (name.includes('碰焊')) { processName = '碰焊'; } else if (name.includes('抛光')) { processName = '抛光'; } else if (name.includes('锯')) { processName = '锯'; } else if (name.includes('冲')) { processName = '冲'; } else if (name.includes('弯')) { processName = '弯'; } else if (name.includes('压')) { processName = '压'; } else if (name.includes('焊')) { processName = '焊'; } else if (name.includes('激光')) { processName = '激光'; } else if (name.includes('产品组装')) { processName = '产品组装'; } else if (name.includes('铆')) { processName = '铆'; } else if (name.includes('攻牙')) { processName = '攻牙'; } else if (name.includes('锣')) { processName = '锣'; } else if (name.includes('压印')) { processName = '压印'; } else if (name.includes('调')) { processName = '调'; } else if ((new RegExp('.+镀(\\W|\\w)$')).test(name)) { processName = '镀'; } else if (name.includes('清洗')) { processName = '清洗'; } else { processName = ''; } return processName; } })();