// ==UserScript==
// @name 店小秘-扫描发货手动输入补全工具 Ver2.0
// @namespace none
// @match https://www.dianxiaomi.com/web/package/scanPackShipped
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @grant GM_getResourceText
// @license MIT
// @require https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js
// @require https://cdn.bootcdn.net/ajax/libs/jqueryui/1.14.1/jquery-ui.js
// @require https://scriptcat.org/lib/567/1.0.3/Hook%20Vue3%20app.js
// @require https://scriptcat.org/lib/3085/0.0.4.2/%E9%80%9A%E7%94%A8%E5%87%BD%E6%95%B0.js
// @require https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.3/js/bootstrap.bundle.min.js
// @resource css https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.3/css/bootstrap.min.css
// @resource jqui_css https://cdn.bootcdn.net/ajax/libs/jqueryui/1.14.1/themes/base/jquery-ui.min.css
// @version 2.0.0
// @author -
// @description 2025/12/08 14:50:34
// ==/UserScript==
window.onload = async function(){
unsafeWindow._$ = $;
await new Promise((resolve)=>{
setTimeout(resolve,1500);
})
let url = "https://www.dianxiaomi.com/package/list.htm";
let data = {
"pageNo": 1,
"pageSize": 300,
"shopId": "-1",
"state": "allocated_has",
"platform": "",
"isSearch": 0,
"searchType": "orderId",
"authId": "-1",
"startTime": "",
"endTime": "",
"country": "",
"orderField": "order_pay_time",
"isVoided": 0,
"isRemoved": 0,
"ruleId": "-1",
"sysRule": "",
"applyType": "",
"applyStatus": "",
"printJh": -1,
"printMd": -1,
"commitPlatform": "",
"productStatus": "",
"jhComment": -1,
"storageId": 0,
"isOversea": -1,
"isFree": 0,
"isBatch": 0,
"history": "",
"custom": -1,
"timeOut": 0,
"refundStatus": 0,
"buyerAccount": "",
"forbiddenStatus": -1,
"forbiddenReason": 0,
"behindTrack": -1,
"orderId": ""
}
let book = await tool.getTotalPage(url,data);
var orig_css = GM_getResourceText("css");
var jqui_css = GM_getResourceText("jqui_css");
var rules = orig_css.match(/@keyframes\s+([^{]+)\{([\s\S]*?})\}/g);
$.each(rules,(i,v)=>{
orig_css = orig_css.replace(v,"");
})
var style = orig_css.replace("*,","#interceptList-box {*,") + "}" + rules.join("");
GM_addStyle(`${style}`);
GM_addStyle(`${jqui_css}`);
unsafeWindow.interceptList = {};
if(localStorage.getItem('interceptList')){
unsafeWindow.interceptList = JSON.parse(localStorage.getItem('interceptList'));
}
var interceptListPage = $(`
`);
interceptListPage.find(".clear").on("click",function(){
localStorage.removeItem('interceptList');
unsafeWindow.interceptList = {};
unsafeWindow.reload_interceptListPage();
});
unsafeWindow.reload_interceptListPage = function(){
$("#interceptList-box .list-box").find(".content").remove();
$.map(unsafeWindow.interceptList,function(_,item){
var item = $(`
`);
item.find(".remove").on("click",function(){
var id = $(this).attr("data-id");
delete unsafeWindow.interceptList[id];
localStorage.setItem('interceptList',JSON.stringify(unsafeWindow.interceptList));
unsafeWindow.reload_interceptListPage();
});
$(".list-box").append(item);
});
if ($(".list-box").find(".content").length === 0){
$(".list-box").find(".no-data").show();
}else{
$(".list-box").find(".no-data").hide();
}
}
interceptListPage.find(".action").on("click",function(){
var code = $.trim($(".putinIninterceptList").val());
if(code){
$(".putinIninterceptList").val("");
unsafeWindow.interceptList[code] = null;
localStorage.setItem('interceptList',JSON.stringify(unsafeWindow.interceptList));
unsafeWindow.reload_interceptListPage();
}
});
$(document.body).append(interceptListPage);
unsafeWindow.reload_interceptListPage();
let orderList = [];
for(var page of book){
orderList = orderList.concat(page.find("#orderListTable tr[data-orderid]").map(function(){return $(this).children("td:eq(5)").find("a[title='点击查看物流追踪']").text()}).toArray());
}
const scann_input_space = $("#scanShippingInput").closest(".ant-space");
const scann_input_space_provides = scann_input_space.prop("__vue__").provides;
// scann_input_space_provides[Object.getOwnPropertySymbols(scann_input_space_provides)[0]].scanPackData.code
const goodSort = function(request, response){
var weightMap = []
for(var it of orderList){
var search_content = request.term.toUpperCase().split("").reverse().join("");
var tmpIt = it.split("").reverse().join("");
if(tmpIt.indexOf(search_content) === -1){
continue;
}else{
weightMap.push({
'label': it,
'value': it,
'weight': tmpIt.length - tmpIt.indexOf(search_content)
})
}
}
weightMap = weightMap.sort((a,b)=>b.weight - a.weight)
response(weightMap);
}
let acomp = $("#scanShippingInput").autocomplete({
source:(request, response)=>{goodSort(request, response)},
focus: function(event,v) {
scann_input_space_provides[Object.getOwnPropertySymbols(scann_input_space_provides)[0]].scanPackData.code = v.item.value;
},
delay: 0,
});
$("#scanShippingInput").on("input",function(){
var val = $(this).val();
if(orderList.includes(val.toUpperCase())){
acomp.autocomplete( "disable" );
}else{
acomp.autocomplete( "enable" );
}
})
const current_code = {
code: undefined,
obj: undefined
};
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);
}
oldSend.apply(this, arguments);
};
}
}
addXMLRequestCallback(function (xhr) {
xhr.addEventListener("readystatechange", function () {
if (xhr.readyState == 2 && xhr.responseURL.indexOf("/api/package/getPackageByCode.json") !== -1) {
current_code.obj = scann_input_space_provides[Object.getOwnPropertySymbols(scann_input_space_provides)[0]].scanPackData
current_code.code = current_code.obj.code
current_code.code = current_code.code.toUpperCase()
}
});
xhr.addEventListener("load", async function () {
if (xhr.readyState == 4 && xhr.status == 200) {
if (xhr.responseURL.indexOf("/api/package/getPackageByCode.json") !== -1) {
let res = JSON.parse(xhr.response);
if(unsafeWindow.interceptList[current_code.code] === null){
res['data'] = {
"totalWeight": 0,
"orderList": [],
"pack": null,
"colorAndContentMap": null,
"errorMsg": `⌊${current_code.code}⌉ 处于拦截列表中`
}
}else if (/^\wP\d+$/g.test(current_code.code) && res['data']['orderList'].length === 0 && res['data']['errorMsg']=='包裹号或物流追踪号不存在'){
const new_code = current_code.code.replace(/^\wP/,'CNG');
scann_input_space_provides[Object.getOwnPropertySymbols(scann_input_space_provides)[0]].scanPackData.code = new_code;
$("#scanShippingInput").closest(".ant-space").find(".ant-btn-primary").click()
}
Object.defineProperty(this, 'responseText', {
writable: true,
value: JSON.stringify(res)
});
}
}
});
});
}