feat(script): 新增图文作品文件下载格式设置

This commit is contained in:
Quan
2026-01-21 18:20:10 +08:00
parent 1c1cb2f7b2
commit 11d5aab6ba
2 changed files with 29 additions and 21 deletions

View File

@@ -12,12 +12,13 @@
**用户脚本更新内容:** **用户脚本更新内容:**
**版本号2.2.6** **版本号2.2.7**
1. 新增链接提取/图片下载选择模式开关 1. 新增链接提取/图片下载选择模式开关
2. 修复合辑作品链接提取失败的问题 2. 修复合辑作品链接提取失败的问题
3. 链接提取选择界面添加序号显示 3. 链接提取选择界面添加序号显示
4. 新增推送下载任务至服务器功能 4. 新增推送下载任务至服务器功能
5. 修复视频作品下载功能 5. 新增图文作品文件下载格式设置
6. 优化用户脚本兼容性 6. 修复视频作品下载功能
7. 重构数据处理逻辑 7. 优化用户脚本兼容性
8. 重构数据处理逻辑

View File

@@ -2,7 +2,7 @@
// @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.6 // @version 2.2.7
// @tag 小红书 // @tag 小红书
// @tag RedNote // @tag RedNote
// @description 提取小红书作品/用户链接,下载小红书无水印图文/视频作品文件 // @description 提取小红书作品/用户链接,下载小红书无水印图文/视频作品文件
@@ -43,7 +43,7 @@
keepMenuVisible: GM_getValue("keepMenuVisible", false), keepMenuVisible: GM_getValue("keepMenuVisible", false),
linkCheckboxSwitch: GM_getValue("linkCheckboxSwitch", true), linkCheckboxSwitch: GM_getValue("linkCheckboxSwitch", true),
imageCheckboxSwitch: GM_getValue("imageCheckboxSwitch", true), imageCheckboxSwitch: GM_getValue("imageCheckboxSwitch", true),
imageDownloadFormat: GM_getValue("imageDownloadFormat", "JPEG"), imageDownloadFormat: GM_getValue("imageDownloadFormat", "jpeg"),
scriptServerURL: GM_getValue("scriptServerURL", defaultsWebSocketURL), scriptServerURL: GM_getValue("scriptServerURL", defaultsWebSocketURL),
scriptServerSwitch: GM_getValue("scriptServerSwitch", false), scriptServerSwitch: GM_getValue("scriptServerSwitch", false),
fileNameFormat: undefined, fileNameFormat: undefined,
@@ -182,6 +182,11 @@
GM_setValue("scriptServerSwitch", config.scriptServerSwitch); GM_setValue("scriptServerSwitch", config.scriptServerSwitch);
} }
const updateImageDownloadFormat = (value) => {
config.imageDownloadFormat = value.toLowerCase();
GM_setValue("imageDownloadFormat", config.imageDownloadFormat);
}
const updateFileNameFormat = (value) => { const updateFileNameFormat = (value) => {
config.fileNameFormat = value; config.fileNameFormat = value;
GM_setValue("fileNameFormat", config.fileNameFormat); GM_setValue("fileNameFormat", config.fileNameFormat);
@@ -246,8 +251,8 @@ KS-Downloader快手、KuaiShouhttps://github.com/JoeanAmier/KS-Download
urls.push( urls.push(
`https://ci.xiaohongshu.com/${match[1]}?imageView2/format/${GM_getValue( `https://ci.xiaohongshu.com/${match[1]}?imageView2/format/${GM_getValue(
"imageDownloadFormat", "imageDownloadFormat",
"JPEG" "jpeg"
).toLowerCase()}`); )}`);
} }
}) })
return urls return urls
@@ -422,9 +427,9 @@ KS-Downloader快手、KuaiShouhttps://github.com/JoeanAmier/KS-Download
const downloadPromises = items.map(async (item) => { const downloadPromises = items.map(async (item) => {
let fileName; let fileName;
if (item.index) { if (item.index) {
fileName = `${name}_${item.index}.${GM_getValue("imageDownloadFormat", "JPEG").toLowerCase()}`; // 根据索引生成文件名 fileName = `${name}_${item.index}.${GM_getValue("imageDownloadFormat", "jpeg")}`; // 根据索引生成文件名
} else { } else {
fileName = `${name}.${GM_getValue("imageDownloadFormat", "JPEG").toLowerCase()}`; fileName = `${name}.${GM_getValue("imageDownloadFormat", "jpeg")}`;
} }
const result = await downloadFile(item.url, fileName, false); // 调用单个文件下载方法 const result = await downloadFile(item.url, fileName, false); // 调用单个文件下载方法
if (result) { if (result) {
@@ -486,13 +491,13 @@ KS-Downloader快手、KuaiShouhttps://github.com/JoeanAmier/KS-Download
let result = []; let result = [];
for (let item of items) { for (let item of items) {
result.push( result.push(
await downloadFile(item.url, `${name}_${item.index}.${GM_getValue("imageDownloadFormat", "JPEG") await downloadFile(item.url, `${name}_${item.index}.${GM_getValue("imageDownloadFormat", "jpeg")
.toLowerCase()}`)); }`));
} }
success = result.every(item => item === true); success = result.every(item => item === true);
} else if (items.length === 1) { } else if (items.length === 1) {
success = await downloadFile( success = await downloadFile(
items[0].url, `${name}.${GM_getValue("imageDownloadFormat", "JPEG").toLowerCase()}`); items[0].url, `${name}.${GM_getValue("imageDownloadFormat", "jpeg")}`);
} else { } else {
success = await downloadFiles(items, name,); success = await downloadFiles(items, name,);
} }
@@ -1180,13 +1185,14 @@ KS-Downloader快手、KuaiShouhttps://github.com/JoeanAmier/KS-Download
checked: GM_getValue("scriptServerSwitch", false), checked: GM_getValue("scriptServerSwitch", false),
}); });
// const imageDownloadFormat = createSelectItem({ const imageDownloadFormat = createSelectItem({
// label: '图片下载格式', label: '图片下载格式',
// description: '选择图片格式', description: '图文作品文件下载格式',
// options: ["AUTO", "PNG", "WEBP", "JPEG", "HEIC"], options: ["PNG", "WEBP", "JPEG", "HEIC"],
// value: GM_getValue("imageDownloadFormat", "JPEG"), value: GM_getValue("imageDownloadFormat", "jpeg")
// }); .toUpperCase(),
// });
// const nameFormat = createTextInput({ // const nameFormat = createTextInput({
// label: '文件名称格式', // label: '文件名称格式',
// description: '设置文件的名称格式(例如:{date}-{title})。', // description: '设置文件的名称格式(例如:{date}-{title})。',
@@ -1210,7 +1216,7 @@ KS-Downloader快手、KuaiShouhttps://github.com/JoeanAmier/KS-Download
body.appendChild(scrollCount); body.appendChild(scrollCount);
body.appendChild(linkCheckboxSwitch); body.appendChild(linkCheckboxSwitch);
body.appendChild(imageCheckboxSwitch); body.appendChild(imageCheckboxSwitch);
// body.appendChild(imageDownloadFormat); body.appendChild(imageDownloadFormat);
body.appendChild(keepMenuVisible); body.appendChild(keepMenuVisible);
body.appendChild(scriptServerURL); body.appendChild(scriptServerURL);
body.appendChild(scriptServerSwitch); body.appendChild(scriptServerSwitch);
@@ -1244,6 +1250,7 @@ KS-Downloader快手、KuaiShouhttps://github.com/JoeanAmier/KS-Download
updateMaxScrollCount(parseInt(scrollCount.querySelector('input').value) || 50) updateMaxScrollCount(parseInt(scrollCount.querySelector('input').value) || 50)
updateScriptServerURL(scriptServerURL.querySelector('.text-input').value.trim() || defaultsWebSocketURL); updateScriptServerURL(scriptServerURL.querySelector('.text-input').value.trim() || defaultsWebSocketURL);
updateScriptServerSwitch(scriptServerSwitch.querySelector('input').checked); updateScriptServerSwitch(scriptServerSwitch.querySelector('input').checked);
updateImageDownloadFormat(imageDownloadFormat.querySelector('select').value.trim() || "jpeg");
// updateFileNameFormat(nameFormat.querySelector('.text-input').value.trim() || null); // updateFileNameFormat(nameFormat.querySelector('.text-input').value.trim() || null);
closeSettingsModal(); closeSettingsModal();
}); });