diff --git a/pugongying/xhs-pgy-export.user.js b/pugongying/xhs-pgy-export.user.js index a54f3d2..8eb29d8 100644 --- a/pugongying/xhs-pgy-export.user.js +++ b/pugongying/xhs-pgy-export.user.js @@ -4,7 +4,8 @@ // @version 0.1.1 // @description 输入达人主页链接或达人 ID,勾选字段后导出 Excel // @match https://pgy.xiaohongshu.com/* -// @grant none +// @grant GM_xmlhttpRequest +// @connect api.internal.intelligrow.cn // @require https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js // ==/UserScript== @@ -14,6 +15,27 @@ module.exports = api; } })(typeof globalThis !== "undefined" ? globalThis : this, function factory(root) { + function gmFetch(url, options) { + return new Promise((resolve, reject) => { + const headers = options && options.headers ? options.headers : {}; + GM_xmlhttpRequest({ + method: (options && options.method) || "GET", + url, + headers, + onload(res) { + resolve({ + ok: res.status >= 200 && res.status < 300, + status: res.status, + json: () => Promise.resolve(JSON.parse(res.responseText)), + }); + }, + onerror(err) { + reject(new Error("GM_xmlhttpRequest 网络错误: " + (err.statusText || url))); + }, + }); + }); + } + const API_BASE = "https://pgy.xiaohongshu.com/api/solar/cooperator/user/blogger/"; const PROXY_API_BASE = "https://api.internal.intelligrow.cn"; @@ -395,7 +417,9 @@ async function fetchSupplementalPayload(userId, fetchImpl, config) { const extra = typeof config.extraHeaders === "function" ? config.extraHeaders() : {}; - const response = await fetchImpl(config.buildUrl(userId), { + const hasExtra = Object.keys(extra).length > 0; + const fetcher = hasExtra && typeof GM_xmlhttpRequest === "function" ? gmFetch : fetchImpl; + const response = await fetcher(config.buildUrl(userId), { method: "GET", credentials: "include", headers: {