|
发表于
2023-1-3 16:39:59
|
显示全部楼层
本帖最后由 Major 于 2023-1-3 16:55 编辑
遇到一个问题,寻求帮助。以下代码我用了两种不同的 hook方式。在 【// @match https://fxg.jinritemai.com/ffa/mexpress/goods/storage】 这个网址,两种方式都生效。但是奇怪的是,在 【// @match https://base.work.cainiao.com/ma ... hInventoryQuery.htm*】两种方式都不生效,也就是 a.hookJson_tm_bms_xiaoqi(); 这个函数内的hook 没执行
我看到了这个说明(但是不太会用)见下图2,如果有个完整示例,让这段代码执行就更好了:
- // ==UserScript==
- // [url=home.php?mod=space&uid=23356]@name[/url] [major]简称显示
- // @namespace https://bbs.tampermonkey.net.cn/
- // @version 0.1.0
- // @description try to take over the world!
- // @author You
- // [url=home.php?mod=space&uid=52134]@match[/url] https://fxg.jinritemai.com/ffa/mexpress/goods/storage
- // @match https://base.work.cainiao.com/manage/batch/batchInventoryQuery.htm*
- // @require https://scriptcat.org/lib/637/1.0.0/ajaxHooker.js
- // @run-at document-start
- // ==/UserScript==
- // 店铺库存简称显示
- let b = {
- // 根据条形码匹配商品简称
- code:{
- "4004148057274":"01德大铁",
- "4004148323218":"02红铁片",
- "4004148047503":"03中大铁",
- "4004148313547":"04绿大铁",
- "4004148323768":"05绿铁片",
- "4004148017537":"06钙镁锌",
- "4004148057267":"08德小铁",
- "4004148324741":"09德版艾儿",
- "4004148322327":"10儿童铁元",
- "4004148323232":"11维B族",
- "4004148017223":"14德版多维",
- "4004148307058":"17护肝液",
- "4004148019821":"20黑莓鱼油",
- "4004148017018":"23肠道卫士",
- "4004148018916":"24钙片",
- "4004148330599":"27软骨胶囊",
- "4004148018121":"28润嗓糖",
- "4004148345975":"褪黑素30片",
- "4004148307478":"维B胶囊",
- "4004148349775":"05绿铁片(新)",
- },
- // 铁元店 菜鸟货品ID 匹配商品名称
- itemId : {
- "637854584084":"01德大铁",
- "638881163050":"02红铁片",
- "638924845292":"03中大铁",
- "638558160498":"04绿大铁",
- "639596995875":"05绿铁片",
- "638563752479":"07中小铁",
- "638557156350":"08德小铁",
- "639267098498":"10儿童铁元",
- "639261274711":"12绿小铁",
- "639714222006":"40女士调经茶",
- "641688011698":"50德超大铁",
- "643491679413":"51迷你15ml儿铁",
- "652636028202":"紫锥菊唇膏",
- },
- };
- let a = {
- // 抖音供应链管理(hook 方式1)
- hookJson_dy_gylgl:function(){
- const xhrOpen = XMLHttpRequest.prototype.open;
- XMLHttpRequest.prototype.open = function() {
- // let url = '/shopuser/cb/wareStock/wareList'
- let urlfined = /\/shopuser\/cb\/wareStock\/wareList/;
- let response = 'responseText'
- const xhr = this;
- if (arguments[1].match(urlfined)) {
- const getter = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, response).get;
- Object.defineProperty(xhr, response, {
- get: () => {
- let result = getter.call(xhr);
- console.log("结果类型是:",typeof(result))
- let resultDic = JSON.parse(result);
- let goodsitem = resultDic.data.list
- goodsitem.forEach((element,index) => {
- let barCode = element.wareInfo.barCode
- if(b.code[barCode]){
- goodsitem[index].wareInfo.wareName = b.code[barCode] + '\n'
- };
- });
- //这里可以修改result
- return resultDic;
- }
- });
- }
- return xhrOpen.apply(xhr, arguments);
- };
- },
- // 天猫国际BMS效期查询(hook 方式2)
- hookJson_tm_bms_xiaoqi:function(){
- console.log("天猫国际BMS效期查询1")
- ajaxHooker.protect(); // 这一句,加 和 没加 hook 都没执行
- ajaxHooker.hook(request => {
- console.log("URLGET:",request.url)
- if (request.url.match(/\/batch\/batchInventoryQueryJson.do/)){
- console.log('test:',request);
- console.log('test_URL:',request.url);
- };
- });
- },
- };
- let c = {
- inmain:function(){
- if(document.location.pathname.match(/\/ffa\/mexpress\/goods\/storage/)){
- a.hookJson_dy_gylgl();
- }else if(document.location.pathname.match(/\/batch\/batchInventoryQuery.htm/)){
- a.hookJson_tm_bms_xiaoqi();
- };
- },
- };
- (function() {
- c.inmain();
- })();
复制代码
|
-
-
|