mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2026-03-22 06:57:16 +08:00
perf(script): 优化用户脚本兼容性
This commit is contained in:
@@ -12,10 +12,12 @@
|
|||||||
|
|
||||||
**用户脚本更新内容:**
|
**用户脚本更新内容:**
|
||||||
|
|
||||||
**版本号:2.2.4**
|
**版本号:2.2.6**
|
||||||
|
|
||||||
1. 新增链接提取/图片下载选择模式开关
|
1. 新增链接提取/图片下载选择模式开关
|
||||||
2. 修复合辑作品链接提取失败的问题
|
2. 修复合辑作品链接提取失败的问题
|
||||||
3. 链接提取选择界面添加序号显示
|
3. 链接提取选择界面添加序号显示
|
||||||
4. 新增推送下载任务至服务器功能
|
4. 新增推送下载任务至服务器功能
|
||||||
5. 修复视频作品下载功能
|
5. 修复视频作品下载功能
|
||||||
|
6. 优化用户脚本兼容性
|
||||||
|
7. 重构数据处理逻辑
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
// @name XHS-Downloader
|
// @name XHS-Downloader
|
||||||
// @namespace xhs_downloader
|
// @namespace xhs_downloader
|
||||||
// @homepage https://github.com/JoeanAmier/XHS-Downloader
|
// @homepage https://github.com/JoeanAmier/XHS-Downloader
|
||||||
// @version 2.2.5
|
// @version 2.2.6
|
||||||
// @tag 小红书
|
// @tag 小红书
|
||||||
// @tag RedNote
|
// @tag RedNote
|
||||||
// @description 提取小红书作品/用户链接,下载小红书无水印图文/视频作品文件
|
// @description 提取小红书作品/用户链接,下载小红书无水印图文/视频作品文件
|
||||||
// @description:en Extract RedNote works/user links, Download watermark-free images/videos files
|
// @description:en Extract RedNote works/user links, Download watermark-free images/videos files
|
||||||
// @author JoeanAmier
|
// @author JoeanAmier
|
||||||
// @match http*://www.xiaohongshu.com/explore*
|
// @match http*://www.xiaohongshu.com/explore*
|
||||||
|
// @match http*://www.xiaohongshu.com/discovery/item/*
|
||||||
// @match http*://www.xiaohongshu.com/user/profile/*
|
// @match http*://www.xiaohongshu.com/user/profile/*
|
||||||
// @match http*://www.xiaohongshu.com/search_result*
|
// @match http*://www.xiaohongshu.com/search_result*
|
||||||
// @match http*://www.xiaohongshu.com/board/*
|
// @match http*://www.xiaohongshu.com/board/*
|
||||||
@@ -222,17 +223,13 @@ KS-Downloader(快手、KuaiShou):https://github.com/JoeanAmier/KS-Download
|
|||||||
}
|
}
|
||||||
|
|
||||||
const generateVideoUrl = note => {
|
const generateVideoUrl = note => {
|
||||||
// try {
|
|
||||||
// return [`https://sns-video-bd.xhscdn.com/${note.video.consumer.originVideoKey}`];
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error("Error generating video URL:", error);
|
|
||||||
// return [];
|
|
||||||
// }
|
|
||||||
try {
|
try {
|
||||||
|
const key = note.video?.consumer?.originVideoKey;
|
||||||
|
if (key) return [`https://sns-video-bd.xhscdn.com/${key}`];
|
||||||
const video = note.video.media.stream.h265;
|
const video = note.video.media.stream.h265;
|
||||||
return [video[video.length - 1].masterUrl];
|
return [video[video.length - 1].masterUrl];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error extract video URL:", error);
|
console.error("Error deal video URL:", error);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -243,7 +240,8 @@ KS-Downloader(快手、KuaiShou):https://github.com/JoeanAmier/KS-Download
|
|||||||
let urls = [];
|
let urls = [];
|
||||||
try {
|
try {
|
||||||
images.forEach((item) => {
|
images.forEach((item) => {
|
||||||
let match = item.urlDefault.match(regex);
|
const url = item.urlDefault || item.url;
|
||||||
|
let match = url.match(regex);
|
||||||
if (match && match[1]) {
|
if (match && match[1]) {
|
||||||
urls.push(
|
urls.push(
|
||||||
`https://ci.xiaohongshu.com/${match[1]}?imageView2/format/${GM_getValue(
|
`https://ci.xiaohongshu.com/${match[1]}?imageView2/format/${GM_getValue(
|
||||||
@@ -268,9 +266,10 @@ KS-Downloader(快手、KuaiShou):https://github.com/JoeanAmier/KS-Download
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
for (const [index, item] of imageList.entries()) {
|
for (const [index, item] of imageList.entries()) {
|
||||||
if (item.urlDefault) {
|
const url = item.urlDefault || item.url;
|
||||||
|
if (url) {
|
||||||
items.push({
|
items.push({
|
||||||
webp: item.urlDefault, index: index + 1, url: urls[index],
|
webp: url, index: index + 1, url: urls[index],
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.error("提取图片预览链接失败", item)
|
console.error("提取图片预览链接失败", item)
|
||||||
@@ -339,20 +338,23 @@ KS-Downloader(快手、KuaiShou):https://github.com/JoeanAmier/KS-Download
|
|||||||
};
|
};
|
||||||
|
|
||||||
const extractNoteInfo = () => {
|
const extractNoteInfo = () => {
|
||||||
|
const data = unsafeWindow.__INITIAL_STATE__?.noteData?.data?.noteData;
|
||||||
|
if (data) return data;
|
||||||
const regex = /\/explore\/([^?]+)/;
|
const regex = /\/explore\/([^?]+)/;
|
||||||
const match = currentUrl.match(regex);
|
const match = currentUrl.match(regex);
|
||||||
if (match) {
|
if (match) {
|
||||||
return unsafeWindow.__INITIAL_STATE__.note.noteDetailMap[match[1]]
|
return unsafeWindow.__INITIAL_STATE__.note.noteDetailMap[match[1]].note;
|
||||||
} else {
|
} else {
|
||||||
console.error("从链接提取作品 ID 失败", currentUrl,);
|
console.error("从链接提取作品 ID 失败", currentUrl,);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const extractDownloadLinks = async (server = false) => {
|
const extractDownloadLinks = async (server = false) => {
|
||||||
if (currentUrl.includes("https://www.xiaohongshu.com/explore/")) {
|
if (currentUrl.includes("https://www.xiaohongshu.com/explore/") || currentUrl.includes(
|
||||||
|
"https://www.xiaohongshu.com/discovery/item/")) {
|
||||||
let note = extractNoteInfo();
|
let note = extractNoteInfo();
|
||||||
if (note.note) {
|
if (note) {
|
||||||
await exploreDeal(note.note, server,);
|
await exploreDeal(note, server,);
|
||||||
} else {
|
} else {
|
||||||
abnormal("读取作品数据发生异常!");
|
abnormal("读取作品数据发生异常!");
|
||||||
}
|
}
|
||||||
@@ -2039,7 +2041,8 @@ KS-Downloader(快手、KuaiShou):https://github.com/JoeanAmier/KS-Download
|
|||||||
action: () => extractAllLinksEvent(-1),
|
action: () => extractAllLinksEvent(-1),
|
||||||
description: '提取当前页面的作品链接至剪贴板'
|
description: '提取当前页面的作品链接至剪贴板'
|
||||||
},);
|
},);
|
||||||
} else if (currentUrl.includes("https://www.xiaohongshu.com/explore/")) {
|
} else if (currentUrl.includes("https://www.xiaohongshu.com/explore/") || currentUrl.includes(
|
||||||
|
"https://www.xiaohongshu.com/discovery/item/")) {
|
||||||
menuItems.push({
|
menuItems.push({
|
||||||
text: '下载作品文件',
|
text: '下载作品文件',
|
||||||
icon: ' 📦 ',
|
icon: ' 📦 ',
|
||||||
|
|||||||
Reference in New Issue
Block a user