// ==UserScript== // @name 半自动发布助手 // @namespace https://bbs.tampermonkey.net.cn/ // @version 1.1 // @description try to take over the world! // @author EXI // @match https://dr.jd.com/page/app.html#/new_create/11?type=ARTICLE&cid=0&sid=143 // ==/UserScript== // 软件仅供技术学习交流,请勿用于商业及非法用途,如产生法律纠纷与本人无关 (async function () { 'use strict'; console.log(document) function findDomCallBack(selector, pElement = document, callBack, isMutiple) { let timer = setInterval(() => { let dom = isMutiple ? pElement.querySelectorAll(selector) : pElement.querySelector(selector) if (dom !== null) { //找到了清空定时器 clearInterval(timer); callBack(dom) } }, 300); } function findDom(selector, pElement = document,cycleCall, isMutiple) { return new Promise((re, rj) => { let timer = setInterval(() => { let dom = isMutiple ? pElement.querySelectorAll(selector) : pElement.querySelector(selector) if(cycleCall) cycleCall(); if (dom !== null) { //找到了清空定时器 clearInterval(timer); re(dom) } }, 300); }) } function copyToClip(content) { var aux = document.createElement("input"); aux.setAttribute("value", content); document.body.appendChild(aux); aux.select(); document.execCommand("copy"); document.body.removeChild(aux); } function changInputValue(inputDom, newText) { let lastValue = inputDom.value; inputDom.value = newText; let event = new Event('input', { bubbles: true }); event.simulated = true; let tracker = inputDom._valueTracker; if (tracker) { tracker.setValue(lastValue); } inputDom.dispatchEvent(event); } function removeFileExtension(filename) { const lastDotIndex = filename.lastIndexOf('.'); if (lastDotIndex === -1) return filename; // 如果没有找到点,那么就返回原始文件名 return filename.substring(0, lastDotIndex); } function addXMLRequestCallback(callback) { var oldSend, i; if (XMLHttpRequest.callbacks) { XMLHttpRequest.callbacks.push(callback); } else { XMLHttpRequest.callbacks = [callback]; oldSend = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.send = function () { for (i = 0; i < XMLHttpRequest.callbacks.length; i++) { XMLHttpRequest.callbacks[i](this); } return oldSend.apply(this, arguments); }; } } function sleep(time) { return new Promise((re, rj) => { setTimeout(() => { re(0) }, time) }) } //刷新页面 addXMLRequestCallback(function (xhr) { xhr.addEventListener("load", function () { if (xhr.readyState == 4 && xhr.status == 200 && xhr.responseURL == 'https://api.m.jd.com/articlePublishVideo') { setTimeout(() => { window.open("https://dr.jd.com/page/app.html#/new_create/11?type=ARTICLE&cid=0&sid=143", "_self"); window.location.reload(); }, 1000) } }); }); let fileInput = await findDom('input[type="file"]') fileInput.addEventListener("change", async (event) => { let name = event.target.files[event.target.files.length - 1].name name = removeFileExtension(name) let strs = name.split('_') copyToClip(strs[0]) //打开关联商品 let goodsOpen = await findDom('.goods-list-addgoods') goodsOpen.click() //找到商品多选框 let goodsChebox = await findDom('.good-card-horizontal-check',document,async ()=>{ //找到商品输入框 let goodsInput = await findDom('.search-input input[class="search-input-content-input"]') //找到商品确认按钮 let goodsBtn = await findDom('.search-input .arco-btn') changInputValue(goodsInput, strs[0]) goodsBtn.click() }) goodsChebox.click() //确认商品 let submitBtn = await findDom(".arco-space-item .arco-btn-primary") submitBtn.click() //找到标题框 let titleInput = await findDom('input[maxlength="27"]') changInputValue(titleInput, strs[1].substring(0, 27)) titleInput.dispatchEvent(new Event("focus")) titleInput.dispatchEvent(new Event("blur")) //选择封面 let upload = await findDom('.image-cut-uploadarea-modalcontent-upload') upload.click() let initImgCon = await findDom('.initImgCon') let img = await findDom('img', initImgCon) let imgDialogfoote = await findDom('.arco-modal-footer') let imgBtn = await findDom('button:not([style*="display: none"]).arco-btn.arco-btn-primary.arco-btn-size-default.arco-btn-shape-round', imgDialogfoote) imgBtn.click(); //打开体裁标签 let ticaiInput = await findDom('.ticai .arco-cascader') ticaiInput.click() //打开通用体裁 let tongyongInput = await findDom("li[title='通用体裁'] label") tongyongInput.click() //找到的标签 let tag = await findDom("li[title='种草分享'] label") tag.click() document.title = strs[1].substring(0, 27) }) })();