Last active
November 2, 2025 10:41
-
-
Save mitian233/3c3c2aca6ad6c7040dd01a6017fc01d0 to your computer and use it in GitHub Desktop.
sf-taobao.user.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name 顺丰网页版淘宝发货自动填写分区号 | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.1 | |
| // @description 劫持JSON解析函数并修改客户端获取的数据,将分区号自动填写到姓名区域 | |
| // @author Mikan | |
| // @match *://www.sf-express.com/*/*/*/home | |
| // @grant none | |
| // @run-at document-start | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| const OriginalJSONParse = JSON.parse; | |
| function modifyResponseBody(originalBody) { | |
| console.warn(`[SF Intercept] 原始响应体:`, originalBody); | |
| try { | |
| // 尝试解析原始 JSON | |
| const data = OriginalJSONParse(originalBody); | |
| data.result = data.result.map(item=> { | |
| if(item.extension) item.name = `${item.name}(分区号:${item.extension})`; | |
| return item; | |
| }); | |
| // --------------------------------------------- | |
| const modifiedBody = JSON.stringify(data); | |
| console.log(`[SF Intercept] 修改后的响应体:`, modifiedBody); | |
| return modifiedBody; | |
| } catch (e) { | |
| console.error('[SF Intercept] 错误:无法解析或修改 JSON 响应体。', e); | |
| return originalBody; | |
| } | |
| } | |
| // XHR 劫持失败,页面最终会调用 JSON.parse 来处理数据。 | |
| window.JSON.parse = function(text) { | |
| let originalData; | |
| try { | |
| originalData = OriginalJSONParse(text); | |
| if (originalData.result[0].extension) { | |
| const modifiedData = modifyResponseBody(text); | |
| console.log('[JSON.parse Hijacked] 成功在 JSON.parse 阶段替换数据!'); | |
| return OriginalJSONParse(modifiedData); | |
| } | |
| } catch (e) { | |
| // console.error('[JSON.parse Hijacked Error] 原始数据不是有效 JSON 或修改失败。', e); | |
| return OriginalJSONParse(text); | |
| } | |
| // 非目标请求,返回原始的 JSON.parse 结果 | |
| return OriginalJSONParse(text); | |
| }; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment