fix(XHS-Downloader.js): 重构作品链接提取功能

Closes #179
This commit is contained in:
JoeanAmier
2024-09-24 20:10:28 +08:00
parent 2042afcd1e
commit 1698e1c792
5 changed files with 13 additions and 9 deletions

View File

@@ -12,4 +12,6 @@
**用户脚本更新内容:**
1. 优化作品链接提取功能
1. 重构作品链接提取功能
<p><strong>⚠️⚠️⚠️由于小红书规则更新,使用版本号低于 <code>1.7.0</code> 的用户脚本有封号风险,请及时更新用户脚本后再使用!⚠️⚠️⚠️</strong></p>

View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @name XHS-Downloader
// @namespace https://github.com/JoeanAmier/XHS-Downloader
// @version 1.6.3
// @version 1.7.0
// @description 提取小红书作品/用户链接,下载小红书无水印图文/视频作品文件
// @author JoeanAmier
// @match http*://xhslink.com/*
@@ -304,7 +304,7 @@
const extractNotesInfo = order => {
const notesRawValue = unsafeWindow.__INITIAL_STATE__.user.notes._rawValue[order];
return notesRawValue.map(item => [item.id, item.xsecToken]);
return notesRawValue.map(item => [item.id, item.xsecToken, "pc_user", "",]);
};
const extractBoardInfo = order => {
@@ -320,7 +320,7 @@
const id = match[1]; // match[0] 是整个匹配的字符串match[1] 是第一个括号内的匹配
const notesRawValue = unsafeWindow.__INITIAL_STATE__.board.boardFeedsMap._rawValue[id].notes;
return notesRawValue.map(item => [item.noteId, item.xsecToken]);
return notesRawValue.map(item => [item.noteId, item.xsecToken, "pc_user", "&source=web_user_page",]);
} else {
console.error("从链接提取专辑 ID 失败", currentUrl,);
return [];
@@ -329,12 +329,12 @@
const extractFeedInfo = () => {
const notesRawValue = unsafeWindow.__INITIAL_STATE__.feed.feeds._rawValue;
return notesRawValue.map(item => [item.id, item.xsecToken]);
return notesRawValue.map(item => [item.id, item.xsecToken, "pc_feed", "",]);
};
const extractSearchNotes = () => {
const notesRawValue = unsafeWindow.__INITIAL_STATE__.search.feeds._rawValue;
return notesRawValue.map(item => [item.id, item.xsecToken]);
return notesRawValue.map(item => [item.id, item.xsecToken, "pc_search", "&source=web_explore_feed",]);
}
const extractSearchUsers = () => {
@@ -342,7 +342,7 @@
return notesRawValue.map(item => item.id);
}
const generateNoteUrls = data => data.map(([id, token]) => `https://www.xiaohongshu.com/explore/${id}?xsec_token=${token}&xsec_source=pc_user`).join(" ");
const generateNoteUrls = data => data.map(([id, token, source, other]) => `https://www.xiaohongshu.com/explore/${id}?xsec_token=${token}&xsec_source=${source}${other}`).join(" ");
const generateUserUrls = data => data.map(id => `https://www.xiaohongshu.com/user/profile/${id}`).join(" ");