您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
解析粘贴信息并填充到页面对应的表单字段中
当前为
// ==UserScript== // @name Auto Parse and Fill Form for Quick Quotation // @namespace http://tampermonkey.net/ // @version 0.1 // @description 解析粘贴信息并填充到页面对应的表单字段中 // @author You // @match https://issue.cpic.com.cn/ecar/view/portal/page/quotation_merge/quick_quotation.html // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; // 动态创建文本框和按钮 let inputDiv = document.createElement('div'); inputDiv.style.position = 'fixed'; inputDiv.style.top = '20px'; inputDiv.style.right = '20px'; inputDiv.style.zIndex = '9999'; inputDiv.style.backgroundColor = 'white'; inputDiv.style.padding = '20px'; inputDiv.style.border = '1px solid #ccc'; inputDiv.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.2)'; // 创建粘贴信息的文本框 let pasteInput = document.createElement('textarea'); pasteInput.style.width = '300px'; pasteInput.style.height = '200px'; pasteInput.style.marginBottom = '10px'; pasteInput.placeholder = '粘贴信息(每行一个字段)'; inputDiv.appendChild(pasteInput); // 创建解析按钮 let parseButton = document.createElement('button'); parseButton.textContent = '解析'; parseButton.style.marginTop = '10px'; inputDiv.appendChild(parseButton); // 将文本框和按钮插入到页面 document.body.appendChild(inputDiv); // 解析按钮的点击事件 parseButton.addEventListener('click', function() { let pasteText = pasteInput.value.trim(); if (pasteText === '') { alert('请粘贴信息后再点击解析'); return; } let lines = pasteText.split('\n').map(line => line.trim()); // 确保粘贴的行数符合预期 if (lines.length < 10) { alert('粘贴的信息行数不正确,请确保有10行'); return; } // 解析各个字段 let plateNo = lines[0]; // 车牌号 let modelType = lines[1]; // 车型 let carVIN = lines[2]; // VIN let engineNo = lines[3]; // 发动机号 let stRegisterDate = lines[4]; // 注册日期 let name = lines[5]; // 公司名称(现在是lines[6]) let certificateCode = lines[6]; // 统一社会信用代码(现在是lines[7]) let detail = lines[7]; // 地址(现在是lines[8]) // 第6行特殊处理:解析 “2 9200 39605” let [seatCount, emptyWeight, tonnage] = lines[5].split(' ').map(Number); emptyWeight = emptyWeight / 1000; // 除以1000 // 填充到页面表单 try { document.getElementById('plateNo').value = plateNo; // 填充车牌号 document.getElementById('modelType').value = modelType; // 填充车型 document.getElementById('carVIN').value = carVIN; // 填充VIN document.getElementById('engineNo').value = engineNo; // 填充发动机号 document.getElementById('stRegisterDate').value = stRegisterDate; // 填充注册日期 document.getElementsByName('name')[0].value = name; // 填充公司名称 document.getElementsByName('certificateCode')[0].value = certificateCode; // 填充统一社会信用代码 document.getElementsByName('detail')[0].value = detail; // 填充地址 // 填充 seatCount, emptyWeight, tonnage 到页面 document.getElementsByName('seatCount')[0].value = seatCount; document.getElementsByName('emptyWeight')[0].value = emptyWeight; document.getElementsByName('tonnage')[0].value = tonnage; alert('信息解析并填充成功!'); } catch (error) { alert('解析过程中出现错误,请检查粘贴信息的格式'); console.error('解析错误:', error); } }); })();