您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Modeling Helper
当前为
// ==UserScript== // @name MEST Modeling Helper // @namespace joyings.com.cn // @version 1.9.4 // @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(); multiUnit(); 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); window.setTimeout(multiUnit, 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(); } // 多计量计算 async function multiUnit() { if (!$('td:contains("浮动")')[0]) { await sleep(500); multiUnit(); return; } if ($('button:contains("设置换算率")')[0]) { await sleep(5000); return; } for (let row of $('tr:contains("浮动")')) { let btn = document.createElement('button'); btn.setAttribute('type', 'button'); btn.appendChild(document.createTextNode('设置换算率')); let divb = document.createElement('div'); let result = multiUnitUtil(); for (let cell of $('td:contains("浮动")', row)) { divb.innerHTML = "类型: " + result[3] + "; 厚度: " + result[2][0] + "; 长: " + result[2][1] + "; 宽: " + result[2][2] + "; 总长: " + result[2][3]; cell.appendChild(divb); switch (row.cells.item(0).textContent) { case 'KG': btn.onclick = function () { result = multiUnitUtil() divb.innerHTML = "类型: " + result[3] + "; 厚度: " + result[2][0] + "; 长: " + result[2][1] + "; 宽: " + result[2][2] + "; 总长: " + result[2][3]; $('input', row.cells.item(3))[0].value = multiUnitUtil()[0]; $('input', row.cells.item(3))[0].dispatchEvent(new Event('input', { bubbles: true })); }; break; case '支': btn.onclick = function () { result = multiUnitUtil() divb.innerHTML = "类型: " + result[3] + "; 厚度: " + result[2][0] + "; 长: " + result[2][1] + "; 宽: " + result[2][2] + "; 总长: " + result[2][3]; $('input', row.cells.item(3))[0].value = multiUnitUtil()[1]; $('input', row.cells.item(3))[0].dispatchEvent(new Event('input', { bubbles: true })); }; break; case '块': btn.onclick = function () { result = multiUnitUtil() divb.innerHTML = "类型: " + result[3] + "; 厚度: " + result[2][0] + "; 长: " + result[2][1] + "; 宽: " + result[2][2] + "; 总长: " + result[2][3]; $('input', row.cells.item(3))[0].value = multiUnitUtil()[1]; $('input', row.cells.item(3))[0].dispatchEvent(new Event('input', { bubbles: true })); }; break; } cell.appendChild(btn); } } } function readme() { alert("脚本会用当前存货的别名作为半成品筛选条件,请为产品的所有工件设置相同的别名;脚本会根据上一道工序的半成品名填写物料和工序信息。\n设置序号会使自动添加物料失灵,建议先设置好所有半成品、再手动选择首工序、再点击更新序号\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 (indexCell.firstChild.firstChild.firstChild.textContent.includes('始工序')) { 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(); await sleep(50); lastSemiCell.querySelector('[placeholder="输出半成品"]').closest('div').querySelector('button').click(); await sleep(150); document.querySelectorAll('[placeholder="存货别名"]')[1].value = document.querySelector('[placeholder="别名"]').closest('textarea').value; 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, true); 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); // 因为网页有 bug 这里把 event 设为 auxclick indexCell.addEventListener('click', async function (e) { if (indexCell.firstChild.firstChild.firstChild.textContent.includes('始工序')) { 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(); } else { indexCell.querySelector('[class="el-icon-setting"]').closest('a').click(); await sleep(100); while (!$('button:contains(" 选择 ")')[0]) { await sleep(50); } $('button:contains(" 选择 ")')[0].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 ($('button:contains(" 搜索 ")')[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) { if (!(new RegExp('^0[0|1]-').test(document.querySelector('[placeholder="物料选择"]').value))) { let quantity = $('input[type=text]', $('[placeholder="物料选择"]')[0].closest('tr'))[1].value; 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); $('input[type=text]', $('[placeholder="物料选择"]')[0].closest('tr'))[1].value = quantity; if (ok) { $('button:contains("确 定")', $('button:contains("新增行")')[0].parentElement.parentElement.parentElement)[0].click(); await sleep(200); } } } } } function multiUnitUtil() { const numPattern = /[0-9]+[.]?[0-9]*/g; const code = $('[placeholder="编码"]')[0].value; const alias = $('[placeholder="别名"]')[0].value; const specs = $('[placeholder="规格"]')[0].value; const name = $('[placeholder="名称"]')[0].value; let aalias = alias.match(numPattern); let aspecs = specs.match(numPattern); let rkg = 0; // kg let rmm = 0; // 面积 let t = 0; let l = 0; let w = 0; let length = 0; let mtype = ''; if ((new RegExp('^0[0|1]-10').test(code))) { // 线材 t = aspecs[0]; length = aspecs[1]; if (alias.includes('304') || name.includes('钢')) { rkg = 1 / (t * t * 0.00000619); mtype = '钢线'; } else { rkg = 1 / (t * t * 0.00000617); mtype = '铁线'; } } else if ((new RegExp('^0[0|1]-201').test(code))) { // 分条料 t = aspecs[0]; w = aspecs[1]; if (alias.includes('304') || name.includes('钢')) { rkg = 1 / (0.00000793 * t * w); mtype = '钢分条料'; } else { rkg = 1 / (0.00000785 * t * w); mtype = '铁分条料'; } } else if ((new RegExp('^0[0|1]-20[2|3]').test(code))) { // 板材 t = aspecs[0]; l = aspecs[1]; w = aspecs[2]; if (alias.includes('304') || name.includes('钢')) { rkg = 1 / (0.00000793 * t); rmm = l * w; mtype = '钢板'; } else { rkg = 1 / (0.00000785 * t); rmm = l * w; mtype = '铁板'; } } else if ((new RegExp('^0[0|1]-301').test(code))) { // 方管 t = aspecs[2]; l = aspecs[0]; w = aspecs[1]; length = aspecs[3]; if (alias.includes('304') || name.includes('钢')) { rkg = (1 / (0.00000793 * 2 * (Number(l) + Number(w)) * t)); rmm = length; mtype = '钢方管'; } else { rkg = (1 / (0.00000785 * 2 * (Number(l) + Number(w)) * t)); rmm = length; mtype = '铁方管'; } } else if ((new RegExp('^0[0|1]-302').test(code))) { // 圆管 t = aspecs[1]; l = aspecs[0]; length = aspecs[2]; if (alias.includes('304') || name.includes('钢')) { rkg = 1 / (0.00000793 * 3.14159 * l * t); rmm = length; mtype = '钢圆管'; } else { rkg = 1 / (0.00000785 * 3.14159 * l * t); rmm = length; mtype = '铁圆管'; } } return [rkg, rmm, [t, l, w, length], mtype]; } 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 (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 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 if (name.includes('清洗')) { processName = '清洗'; } else if (name.includes('包装')) { processName = '包装'; } else { processName = ''; } return processName; } })();