闲管家自动填写表单

自动填写设置的默认值,帮助更快的上传商品。

  1. // ==UserScript==
  2. // @name 闲管家自动填写表单
  3. // @namespace Take
  4. // @version 1.36
  5. // @description 自动填写设置的默认值,帮助更快的上传商品。
  6. // @match https://*.goofish.pro/*
  7. // @match https://*.kongfz.com/*
  8. // @homepage https://www.aiapply.cn
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.6.0/jszip.min.js
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_addStyle
  13. // @grant GM_xmlhttpRequest
  14. // @grant GM_download
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20.  
  21.  
  22. console.log('脚本开始执行');
  23. const oneTouch = document.createElement('button');
  24. const configIcon = document.createElement('button');
  25. oneTouch.style.display = "none";
  26. configIcon.style.display = "none";
  27.  
  28. var type = 0 // 0 闲管家 1 孔夫子
  29. // 判断当前页面的域名是否为指定的域名
  30. function isDomainAllowed(domain) {
  31. var currentDomain = window.location.hostname;
  32. return currentDomain.includes(domain);
  33. }
  34.  
  35. // 在示例中判断当前页面是否为 example.com 域名
  36. if (isDomainAllowed('kongfz.com')) {
  37. console.log('孔夫子脚本加载成功!');
  38. type = 1
  39. }
  40.  
  41. // 显示隐藏闲管家按钮
  42. var currentURL = window.location.href;
  43. window.history.pushState = new Proxy(window.history.pushState, {
  44. apply: function(target, thisArg, args) {
  45. var url = args[2];
  46. console.log("URL变化:", url);
  47. if(url.includes('add')){
  48. oneTouch.style.display = "block";
  49. configIcon.style.display = "block";
  50. }else{
  51. oneTouch.style.display = "none";
  52. configIcon.style.display = "none";
  53. }
  54. return target.apply(thisArg, args);
  55. }
  56. });
  57.  
  58. // 孔夫子脚本
  59. if(type==1){
  60. // 计算平均价格
  61. window.addEventListener('load', function() {
  62. var xpath = '//ul[@class="itemList"]//div[@class="list-con-moneys"]/div/span';
  63. var result = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  64. var priceNum = 0
  65. var priceList = []
  66. for (var i = 0; i < result.snapshotLength; i++) {
  67. var element = result.snapshotItem(i);
  68. priceNum = priceNum + parseFloat(element.textContent);
  69. priceList.push(parseFloat(element.textContent))
  70. }
  71. priceShow(priceList,priceNum)
  72. });
  73.  
  74. // 查找图片大于3的突出显示
  75. window.addEventListener('load', function() {
  76. var xpath = '//div[@id="listBox"]//span[@class="img-num"]';
  77. var result = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  78.  
  79. for (var i = 0; i < result.snapshotLength; i++) {
  80. var element = result.snapshotItem(i);
  81. var imgNum = parseInt(element.textContent);
  82.  
  83. if (imgNum > 3) {
  84. element.style.background = "#15ff08";
  85. element.style.fontSize = "23px";
  86. element.style.width = "93%";
  87. }
  88. }
  89. });
  90.  
  91. // 计算平均价格
  92. var open = window.XMLHttpRequest.prototype.open;
  93. window.XMLHttpRequest.prototype.open = function(method, url, async) {
  94. var xhr = this;
  95.  
  96. // 监听 load 事件
  97. xhr.addEventListener('readystatechange', function() {
  98. if (url.includes('product_result/?key=')&&!url.includes('ajaxdata=2')&&!url.includes('ajaxdata=3')) {
  99. var booksList = JSON.parse(xhr.responseText).data.itemList;
  100. var priceNum = 0
  101. var priceList = []
  102. for (var i = 0; i < booksList.length; i++) {
  103. priceList.push(parseFloat(booksList[i].price))
  104. priceNum = priceNum + parseFloat(booksList[i].price)
  105. }
  106. priceShow(priceList,priceNum)
  107.  
  108. var xpath = '//div[@id="listBox"]//span[@class="img-num"]';
  109. var result = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  110.  
  111.  
  112.  
  113. }
  114. });
  115.  
  116. // 调用原始的 open 方法
  117. open.apply(xhr, arguments);
  118. };
  119.  
  120. function priceShow(priceList,priceNum){
  121. if(!priceList||priceList.length==0){
  122. return false
  123. }
  124. // 使用 sort 方法进行升序排序
  125. priceList.sort(function(a, b) {
  126. return a - b;
  127. });
  128. var middleIdx = Math.floor(priceList.length / 2)
  129. var median = 0
  130. if (priceList.length % 2 === 0) {
  131. // 数组长度为偶数
  132. median = (priceList[middleIdx - 1] + priceList[middleIdx]) / 2;
  133. } else {
  134. // 数组长度为奇数
  135. median = priceList[middleIdx];
  136. }
  137. // 创建卡片容器
  138. var cardContainer = document.createElement('div');
  139. cardContainer.id = 'card-container';
  140. document.body.appendChild(cardContainer);
  141.  
  142. // 创建卡片内容
  143. var cardContent = document.createElement('div');
  144. cardContent.id = 'card-content';
  145. cardContent.innerHTML = '<p>当前页面价格:</p><p>平均价格:' + (priceNum/priceList.length).toFixed(2) + '</p><p>最低价格:¥'+priceList[0]+'</p><p>中位数:¥'+median+'</p><p>注:以上不含运费</p>';
  146. cardContainer.appendChild(cardContent);
  147.  
  148. // 设置卡片样式
  149. cardContainer.style.position = 'fixed';
  150. cardContainer.style.top = '50%';
  151. cardContainer.style.right = '20px';
  152. cardContainer.style.transform = 'translateY(-50%)';
  153. cardContainer.style.width = '200px';
  154. cardContainer.style.height = '150px';
  155. cardContainer.style.backgroundColor = '#f1f1f1';
  156. cardContainer.style.padding = '10px';
  157. cardContainer.style.borderRadius = '5px';
  158. cardContainer.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.2)';
  159. }
  160.  
  161. var imageArray = [];
  162. var figureInfoBox = document.getElementById('figure-info-box');
  163. if(figureInfoBox){
  164. var imageElements = figureInfoBox.getElementsByTagName('img');
  165.  
  166. for (var i = 0; i < imageElements.length; i++) {
  167. var imageUrl = imageElements[i].getAttribute('data-imgurl');
  168. imageArray.push(imageUrl.replace('_b', ''));
  169. }
  170. }
  171.  
  172. if(imageArray.length>0){
  173. name = '下载图片(' + imageArray.length + '张)'
  174. }else{
  175. name = '未找到图片'
  176. //showEleToast('该页面未找到图片,无法进行下载');
  177. }
  178. // 创建一键赋值按钮
  179. const donwimg = document.createElement('button');
  180. donwimg.textContent = name;
  181. donwimg.style.position = 'fixed';
  182. donwimg.style.bottom = '50px';
  183. donwimg.style.right = '35px';
  184. donwimg.style.zIndex = '9999';
  185. donwimg.style.padding = '5px 20px';
  186. donwimg.style.fontSize = '16px';
  187. donwimg.style.backgroundColor = '#ffe60f';
  188. donwimg.style.border = 'none';
  189. donwimg.style.borderRadius = '50px';
  190. donwimg.style.cursor = 'pointer';
  191. donwimg.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.2)';
  192. donwimg.addEventListener('click', downloadImagesAsZip);
  193. document.body.appendChild(donwimg);
  194.  
  195.  
  196. // 创建下载链接并点击触发下载
  197. function downloadFile(content, filename) {
  198. var blob = new Blob([content], { type: 'application/zip' });
  199. var url = URL.createObjectURL(blob);
  200. var a = document.createElement('a');
  201. a.href = url;
  202. a.download = filename;
  203. a.style.display = 'none';
  204. document.body.appendChild(a);
  205. a.click();
  206. document.body.removeChild(a);
  207. URL.revokeObjectURL(url);
  208. }
  209.  
  210. // 下载图片并生成压缩包
  211. function downloadImagesAsZip() {
  212. var images = imageArray;
  213. if (images.length === 0) {
  214. showEleToast('该页面未找到图片,无法进行下载');
  215. return;
  216. }
  217. showEleToast('正在下载图片...');
  218. var zip = new JSZip();
  219. var folder = zip.folder(document.title);
  220.  
  221. var fetchPromises = [];
  222.  
  223. showEleToast('正在合并为压缩包...');
  224.  
  225. function addImageToZip(imageUrl, filename) {
  226. return fetch(imageUrl)
  227. .then(function (response) {
  228. return response.blob();
  229. })
  230. .then(function (blob) {
  231. folder.file(filename, blob);
  232. showEleToast('下载成功');
  233. })
  234. .catch(function (error) {
  235. console.error('下载图片失败', error);
  236. showEleToast("下载图片失败")
  237. });
  238. }
  239.  
  240. for (var i = 0; i < images.length; i++) {
  241. var imageUrl = images[i];
  242. var filename = 'image' + (i + 1) + '.jpg';
  243. fetchPromises.push(addImageToZip(imageUrl, filename));
  244. }
  245.  
  246. Promise.all(fetchPromises)
  247. .then(function () {
  248. return zip.generateAsync({ type: 'blob' });
  249. })
  250. .then(function (content) {
  251. downloadFile(content, document.title + '.zip');
  252. })
  253. .catch(function (error) {
  254. console.error('生成压缩包失败', error);
  255. showEleToast("生成压缩包失败")
  256. });
  257. }
  258.  
  259. }
  260.  
  261. // 闲管家
  262. if(type==0){
  263. // 从本地存储中获取配置
  264. let defaultCategory = GM_getValue('defaultCategory', '');
  265. let defaultStore = GM_getValue('defaultStore', '');
  266. let defaultTitle = GM_getValue('defaultTitle', '');
  267. let defaultDescription = GM_getValue('defaultDescription', '');
  268. let defaultCategories = []
  269. let defaultStores = []
  270. let inventoryNum = GM_getValue('inventoryNum', '1');
  271. let blacklist = GM_getValue('blacklist', '');
  272. let ok = 0
  273.  
  274. const observer = new MutationObserver(mutationsList => {
  275. for (let mutation of mutationsList) {
  276. if (mutation.type === 'childList' && mutation.target.nodeName === 'TITLE') {
  277. //console.log('页面标题变为:', mutation.target.textContent);
  278. // 初始化
  279. ok = 0
  280. setTimeout(function() {
  281. if(mutation.target.textContent == '新建商品'&&defaultCategory!=''){
  282. fillForm() // 自动执行赋值
  283. }
  284. },3000)
  285. }
  286. }
  287. });
  288.  
  289. observer.observe(document.querySelector('title'), { childList: true, subtree: true });
  290.  
  291. // 获取页面的分类、店铺数据
  292. function getCategories(){
  293. defaultCategories = []
  294. defaultStores = []
  295.  
  296.  
  297. // 获取包含所有分类
  298. const elementDiv = document.querySelectorAll('div.release-history');
  299. console.log(elementDiv)
  300. if(elementDiv){
  301. // 获取所有的<span>元素
  302. //const spanElements = element.querySelectorAll('span.color-blue');
  303. // 遍历每个<span>元素,获取文本内容并添加到数组中
  304. elementDiv.forEach(div => {
  305. const text = div.textContent.trim();
  306. if(text!='上传方式' && text!='仓储管理'){
  307. defaultCategories.push(text.replace("、", ""));
  308. }
  309. });
  310. console.log(defaultCategories)
  311. }else{
  312. defaultCategories = ["请先添加商品后,才能读取到历史类别"]
  313. }
  314.  
  315.  
  316. var parentElement = document.querySelector('.auth-list'); // 使用class选择器选取父元素
  317. var liElements = parentElement.querySelectorAll('li');
  318. liElements.forEach(function(li) {
  319. var text = li.textContent.trim(); // 提取文本内容并去除首尾空格
  320. if(text!='创建闲鱼店铺'){
  321. defaultStores.push(text);
  322. }
  323.  
  324. });
  325. console.log(defaultStores)
  326. updateConfigPopupOptions()
  327. }
  328.  
  329. // 创建一键赋值按钮
  330. oneTouch.textContent = '一键赋值';
  331. oneTouch.style.position = 'fixed';
  332. oneTouch.style.bottom = '180px';
  333. oneTouch.style.right = '50px';
  334. oneTouch.style.zIndex = '9999';
  335. oneTouch.style.padding = '10px 20px';
  336. oneTouch.style.fontSize = '16px';
  337. oneTouch.style.backgroundColor = '#ffe60f';
  338. oneTouch.style.border = 'none';
  339. oneTouch.style.borderRadius = '50px';
  340. oneTouch.style.cursor = 'pointer';
  341. oneTouch.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.2)';
  342. oneTouch.addEventListener('click', fillForm);
  343. document.body.appendChild(oneTouch);
  344.  
  345. // 创建配置按钮
  346. configIcon.textContent = '设置';
  347. configIcon.style.position = 'fixed';
  348. configIcon.style.bottom = '130px';
  349. configIcon.style.right = '50px';
  350. configIcon.style.zIndex = '9999';
  351. configIcon.style.padding = '10px 35px';
  352. configIcon.style.fontSize = '16px';
  353. configIcon.style.border = 'none';
  354. configIcon.style.borderRadius = '50px';
  355. configIcon.style.cursor = 'pointer';
  356. configIcon.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.2)';
  357. configIcon.addEventListener('click', openConfigPopup);
  358. document.body.appendChild(configIcon);
  359.  
  360. // 创建配置弹窗的 HTML 代码
  361. const configPopupHTML = `
  362. <div id="configPopup" style="
  363. display: none;
  364. position: fixed;
  365. top: 50%;
  366. left: 50%;
  367. transform: translate(-50%, -50%);
  368. z-index: 9999;
  369. width: 550px;
  370. padding: 20px;
  371. background-color: #fff;
  372. border: 1px solid #ccc;
  373. border-radius: 5px;
  374. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  375. ">
  376. <h3 style="margin:10px 0;margin-top: 0;">脚本设置</h3>
  377. <div class='config' style="
  378. height: 500px;
  379. overflow-y: scroll;
  380. ">
  381.  
  382. <div style="margin-bottom: 15px; line-height: 20px;">Tip:已默认开启自动一键赋值,下拉可配置黑名单。</div>
  383. <form style="height: 100%;">
  384. <label style=" display: block;">
  385. <span style="font-weight: bold;">选中类别:</span>
  386. <select id="categoryInput" style="width: 100%;" style='margin-top: 10px;'>
  387. ${renderOptions(defaultCategories, defaultCategory)}
  388. </select>
  389. </label>
  390. <label style="margin: 10px 0; display: block;">
  391. <span style="font-weight: bold;">选中店铺:</span>
  392. <select id="storeInput" style="width: 100%;"placeholder="请选择默认店铺">
  393. ${renderOptions(defaultStores, defaultStore)}
  394. </select>
  395. </label>
  396. <label style="margin: 10px 0; display: block;">
  397. <span style="font-weight: bold;">标题前缀:</span>
  398. <input id="titleInput" type="text" style="width: 100%;"placeholder="请输入标题开头" style='margin-top: 10px;'>
  399. </label>
  400. <label style="margin: 10px 0; display: block;">
  401. <span style="font-weight: bold;display: block;">商品描述:</span>
  402. <textarea id="descriptionInput" rows="8" cols="50"placeholder="请输入默认描述" style='margin-top: 10px;' maxlength="-1"></textarea>
  403. </label>
  404. <label style="margin: 10px 0; display: block;">
  405. <span style="font-weight: bold;">设置库存:</span>
  406. <input id="inventoryInput" type="text" style="width: 100%;"placeholder="设置库存,默认:1" style='margin-top: 10px;'>
  407. </label>
  408. <label style="margin: 10px 0; display: block;">
  409. <span style="font-weight: bold;display: block;">黑名单:</span>
  410. <textarea id="blacklistInput" maxlength="-1" rows="8" cols="50"placeholder="禁书过滤(一行一个,可以是书名、作者名称)设置后,包含该关键词的书将会提醒您" style='margin-top: 10px;'></textarea>
  411. </label>
  412. </div>
  413. <div style="text-align: right;margin-top: 30px;">
  414. <div id="cancelConfigButton" style="padding: 10px 50px;
  415. display: inline-block;
  416. border-radius: 50px;
  417. border: 1px solid #ffe60f;
  418. margin-right: 10px;">取消</div>
  419. <div id="saveConfigButton" style="padding: 10px 50px;
  420. display: inline-block;
  421. background-color: #ffe60f;
  422.  
  423. border-radius: 50px;">保存</div>
  424.  
  425. </div>
  426. </form>
  427. </div>`;
  428.  
  429. // 辅助函数:根据数组渲染下拉选择器选项
  430. function renderOptions(options, selectedValue) {
  431. return options
  432. .map(option => `<option value="${option}" ${option === selectedValue ? 'selected' : ''}>${option}</option>`)
  433. .join('');
  434. }
  435.  
  436. // 更新配置弹窗中的选项
  437. function updateConfigPopupOptions() {
  438. const categoryInput = document.getElementById('categoryInput');
  439. const storeInput = document.getElementById('storeInput');
  440. const updatedCategoryOptions = renderOptions(defaultCategories, defaultCategory);
  441. const updatedStoreOptions = renderOptions(defaultStores, defaultStore);
  442. categoryInput.innerHTML = updatedCategoryOptions;
  443. storeInput.innerHTML = updatedStoreOptions;
  444. }
  445.  
  446. // 插入配置弹窗到页面中
  447. document.body.insertAdjacentHTML('beforeend', configPopupHTML);
  448.  
  449. // 获取配置弹窗元素
  450. const configPopup = document.getElementById('configPopup');
  451.  
  452. // 创建配置按钮点击事件处理函数
  453. function openConfigPopup() {
  454. getCategories()
  455.  
  456. configPopup.style.display = 'block';
  457. // 创建一键赋值按钮点击事件处理函数
  458.  
  459. const titleInput = document.getElementById('titleInput');
  460. const descriptionInput = document.getElementById('descriptionInput');
  461. const inventoryInput = document.getElementById('inventoryInput');
  462. const blacklistInput = document.getElementById('blacklistInput');
  463.  
  464. // 填充表单字段
  465.  
  466. titleInput.value = defaultTitle;
  467. descriptionInput.value = defaultDescription;
  468. inventoryInput.value = inventoryNum;
  469. blacklistInput.value = blacklist;
  470. }
  471.  
  472. // 创建保存配置按钮点击事件处理函数
  473. function saveConfig() {
  474. const categoryInput = document.getElementById('categoryInput');
  475. const storeInput = document.getElementById('storeInput');
  476. const titleInput = document.getElementById('titleInput');
  477. const descriptionInput = document.getElementById('descriptionInput');
  478. const inventoryInput = document.getElementById('inventoryInput');
  479. const blacklistInput = document.getElementById('blacklistInput');
  480.  
  481. // 将配置保存到本地存储
  482. defaultCategory = categoryInput.value
  483. defaultStore = storeInput.value
  484. defaultTitle = titleInput.value
  485. defaultDescription = descriptionInput.value
  486. inventoryNum = inventoryInput.value
  487. blacklist = blacklistInput.value
  488. GM_setValue('defaultCategory', categoryInput.value);
  489. GM_setValue('defaultStore', storeInput.value);
  490. GM_setValue('defaultTitle', titleInput.value);
  491. GM_setValue('defaultDescription', descriptionInput.value);
  492. GM_setValue('inventoryNum', inventoryInput.value);
  493. GM_setValue('blacklist', blacklistInput.value);
  494.  
  495. // 提示保存成功,并关闭配置弹窗
  496. showEleToast("保存成功")
  497. closeConfigPopup();
  498. }
  499.  
  500. // 创建取消配置按钮点击事件处理函数
  501. function closeConfigPopup() {
  502.  
  503. configPopup.style.display = 'none';
  504. }
  505.  
  506.  
  507. // 监听保存配置按钮点击事件
  508. const saveConfigButton = document.getElementById('saveConfigButton');
  509. saveConfigButton.addEventListener('click', saveConfig);
  510.  
  511. // 监听取消配置按钮点击事件
  512. const cancelConfigButton = document.getElementById('cancelConfigButton');
  513. cancelConfigButton.addEventListener('click', closeConfigPopup);
  514.  
  515. // 黑名单查询
  516. function BlacklistDetection(title,author){
  517. if(blacklist==''){
  518. return false
  519. }
  520. // 黑名单数组
  521. var blacklist2 = blacklist.split('\n');
  522. // 过滤空格 空行
  523. blacklist2 = blacklist2.filter(function(item) {
  524. return item.trim() !== "";
  525. });
  526.  
  527. // 循环遍历黑名单数组
  528. for (var i = 0; i < blacklist2.length; i++) {
  529. // 检测标题是否包含黑名单中的字符串
  530. if (title.includes(blacklist2[i]) || author.includes(blacklist2[i])) {
  531. console.log("触发黑名单:",blacklist2[i]);
  532. showEleToast("触发黑名单:" + blacklist2[i],6000)
  533. return true
  534. break; // 匹配到黑名单中的数据,停止循环
  535. }
  536. }
  537.  
  538. return false
  539. }
  540.  
  541. // 更新商品标题
  542. function updateProductTitle(isbnInput,titleInput,publisherInput,authorInput) {
  543. var isbn = isbnInput.value || '';
  544. var title = titleInput.value || '';
  545. var publisher = publisherInput.value || '';
  546. var author = authorInput.value || '';
  547. //publisher
  548. var productTitle = defaultTitle + ' ' + title + ' ' + author.replace(/[^\u4E00-\u9FA5]/g, '').replace(/\s/g, '').replace('著', '').replace('主编', '') + isbn;
  549.  
  550. // 填写商品标题
  551. var newtitle = document.querySelector('input[placeholder="请输入商品标题,最多允许输入30个汉字"]');
  552. if (newtitle) {
  553. console.log('找到商品标题输入框',productTitle);
  554. newtitle.value = productTitle;
  555. triggerInputEvent(newtitle);
  556. } else {
  557. console.log('未找到商品标题输入框');
  558. showEleToast('未找到商品标题输入框')
  559. }
  560.  
  561. // 禁书检测
  562. if(BlacklistDetection(title,author)){
  563. showWarningPopup()
  564. }
  565.  
  566. }
  567.  
  568. // 填写商品标题和商品描述
  569. function fillForm() {
  570.  
  571. getCategories()
  572. var genreElements = document.querySelectorAll('div.release-history');
  573. console.log(genreElements)
  574. for (var i = 0; i < genreElements.length; i++) {
  575. var genreElement = genreElements[i];
  576. var genreTitle = genreElement.textContent.trim();
  577. if (genreTitle.includes(defaultCategory)) {
  578.  
  579. if(ok==0){
  580. genreElement.click();
  581. console.log('成功点击"' + defaultCategory + '"');
  582. }else{
  583. console.log('已选择分类,跳过点击')
  584. }
  585.  
  586.  
  587. // 延迟执行
  588. setTimeout(function() {
  589.  
  590. if(ok==0){
  591. // 选择店铺
  592. var storeElements = document.querySelectorAll('.auth-list li:not(.sku-add-btn)');
  593.  
  594. for (var ii = 0; i < storeElements.length; ii++) {
  595. var storeElement = storeElements[ii];
  596. var storeTitle = storeElement.querySelector('.auth-left p').textContent.trim();
  597.  
  598. if (storeTitle == defaultStore) {
  599.  
  600. storeElement.click();
  601. console.log('成功点击"' + defaultStore + '"');
  602. ok=1
  603. break;
  604. }
  605. }
  606. }else{
  607. console.log('已选择店铺,跳过点击')
  608. }
  609.  
  610.  
  611. // 延迟执行
  612. setTimeout(function() {
  613.  
  614. // 监听输入框的值变化并更新商品标题
  615. var isbnInput = document.querySelector('input[placeholder="请输入ISBN编码"]');
  616. var titleInput = document.querySelector('input[placeholder="请输入书名"]');
  617. var publisherInput = document.querySelector('input[placeholder="请输入出版社"]');
  618. var authorInput = document.querySelector('input[placeholder="请输入作者"]');
  619. const button = document.querySelector('.el-button.w-90.mgl-8.color-black.el-button--primary');
  620.  
  621. button.addEventListener('click', function() {
  622. console.log('查询按钮被点击了');
  623. setTimeout(function() {
  624. isbnInput.value = isbnInput.value;
  625. triggerInputEvent(isbnInput);
  626. updateProductTitle(isbnInput,titleInput,publisherInput,authorInput)
  627. }, 300);
  628. });
  629. updateProductTitle(isbnInput,titleInput,publisherInput,authorInput)
  630. if (isbnInput && titleInput && publisherInput && authorInput) {
  631. titleInput.addEventListener('input', function() {
  632. updateProductTitle(isbnInput,titleInput,publisherInput,authorInput);
  633. });
  634. publisherInput.addEventListener('input', function() {
  635. updateProductTitle(isbnInput,titleInput,publisherInput,authorInput);
  636. });
  637. authorInput.addEventListener('input', function() {
  638. updateProductTitle(isbnInput,titleInput,publisherInput,authorInput);
  639. });
  640. }
  641.  
  642. // 填写商品描述
  643. var descriptionTextarea = document.querySelector('textarea[placeholder="请输入商品描述"]');
  644. if (descriptionTextarea) {
  645. console.log('找到商品描述输入框');
  646. descriptionTextarea.value = defaultDescription;
  647. triggerInputEvent(descriptionTextarea);
  648. } else {
  649. console.log('未找到商品描述输入框');
  650. showEleToast('未找到商品描述输入框')
  651. }
  652.  
  653. var stockLabel = document.querySelector('label[for="stock"]');
  654. if (stockLabel) {
  655. var stockInput = stockLabel.nextElementSibling.querySelector('input');
  656. if (stockInput) {
  657. stockInput.value = inventoryNum;
  658. stockInput.dispatchEvent(new Event('input', { bubbles: true }));
  659. console.log('设置库存成功');
  660. } else {
  661. console.log('未找到库存输入框2');
  662. showEleToast('未找到库存输入框2');
  663. }
  664. } else {
  665. console.log('未找到库存输入框');
  666. showEleToast('未找到库存输入框');
  667. }
  668.  
  669. // 获取立即发布按钮的元素
  670. const publishButton = document.querySelectorAll('label.el-radio');
  671. if (publishButton[5]) {
  672. // 模拟点击立即发布按钮
  673. console.log('选中立即发布',publishButton);
  674. publishButton[5].click();
  675.  
  676. } else {
  677. console.log('未找到立即发布按钮');
  678. showEleToast('未找到立即发布按钮')
  679. }
  680.  
  681. showEleToast('一键赋值成功')
  682. }, 100); // 延迟1秒执行填写操作
  683.  
  684. }, 100); // 延迟1秒执行填写操作
  685.  
  686.  
  687.  
  688. return;
  689. }
  690. }
  691.  
  692.  
  693. }
  694.  
  695.  
  696.  
  697. GM_addStyle(`
  698. .modal {
  699. position: fixed;
  700. z-index: 9999;
  701. left: 0;
  702. top: 0;
  703. width: 100%;
  704. height: 100%;
  705. background-color: rgba(0, 0, 0, 0.4);
  706. }
  707.  
  708. .modal-content {
  709. position: relative;
  710. background-color: #fff;
  711. border-radius: 6px;
  712. padding: 30px;
  713. margin: 20% auto;
  714. max-width: 400px;
  715. }
  716.  
  717. .close {
  718. position: absolute;
  719. top: 10px;
  720. right: 10px;
  721. font-size: 24px;
  722. font-weight: bold;
  723. cursor: pointer;
  724. }
  725.  
  726. .modal-title {
  727. margin-top: 0;
  728. }
  729.  
  730. .modal-message {
  731. margin: 20px 0;
  732. }
  733.  
  734. .modal-button {
  735. background-color: red;
  736. color: #fff;
  737. border: none;
  738. padding: 10px 20px;
  739. border-radius: 4px;
  740. cursor: pointer;
  741. }
  742. `);
  743.  
  744. // 定义函数显示警告弹窗提示
  745. function showWarningPopup() {
  746.  
  747. // 创建弹窗元素
  748. var modal = document.createElement('div');
  749. modal.className = 'modal';
  750. modal.innerHTML = `
  751. <div class="modal-content">
  752. <span class="close">&times;</span>
  753. <h3 class="modal-title">禁书提示</h3>
  754. <p class="modal-message">该书疑是禁书,请自行核验是否还要继续上架!!!</p>
  755. <button class="modal-button">我已了解</button>
  756. </div>
  757. `;
  758.  
  759.  
  760. // 找到页面的 body 元素
  761. var body = document.querySelector('body');
  762.  
  763. // 将弹窗添加到 body 元素中
  764. body.appendChild(modal);
  765.  
  766. // 查找所有的模态框元素
  767. var modals = document.querySelectorAll('.modal');
  768.  
  769. // 遍历每个模态框元素
  770. modals.forEach(function(modal) {
  771. // 找到当前模态框中的关闭按钮和"我已了解"按钮
  772. var closeButton = modal.querySelector('.close');
  773. var acknowledgeButton = modal.querySelector('.modal-button');
  774.  
  775. // 绑定关闭按钮和"我已了解"按钮的点击事件
  776. closeButton.addEventListener('click', closeModal);
  777. acknowledgeButton.addEventListener('click', closeModal);
  778. });
  779.  
  780. // 关闭弹窗
  781. function closeModal() {
  782. // 找到当前点击按钮所在的模态框
  783. var modal = this.closest('.modal');
  784. if (modal) {
  785. // 从父元素中移除模态框
  786. modal.parentNode.removeChild(modal);
  787. }
  788. }
  789.  
  790. }
  791.  
  792. // 触发输入事件,以便网页响应
  793. function triggerInputEvent(element) {
  794. var inputEvent = new Event('input', {
  795. bubbles: true,
  796. cancelable: true,
  797. });
  798. element.dispatchEvent(inputEvent);
  799. }
  800. }
  801.  
  802. // 以下为公共
  803. GM_addStyle(`
  804. .ele-toast {
  805. position: fixed;
  806. left: 50%;
  807. transform: translateX(-50%);
  808. top: 30%;
  809. z-index: 9999;
  810. padding: 10px 20px;
  811. background-color: rgb(0 0 0 / 85%);
  812. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.85);
  813. border-radius: 4px;
  814. font-size: 15px;
  815. color: #fff;
  816. }
  817. #configPopup textarea,#configPopup select,#configPopup input{
  818. width: 100%;
  819. border: 1px solid rgba(0, 0, 0, 0.08);
  820. border-radius: 10px;
  821. padding: 10px;
  822. margin: 10px 0;
  823. }
  824. .config::-webkit-scrollbar { width: 0 !important }
  825. `);
  826.  
  827. // 定义函数显示提示
  828. function showEleToast(message, duration = 3000) {
  829. console.log(message)
  830. var toast = document.createElement('div');
  831. toast.className = 'ele-toast';
  832. toast.textContent = message;
  833. document.body.appendChild(toast);
  834.  
  835. setTimeout(function() {
  836. toast.style.opacity = '0';
  837. setTimeout(function() {
  838. document.body.removeChild(toast);
  839. }, 300);
  840. }, duration);
  841. }
  842. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址