Skip to content

Commit

Permalink
保存外链时会显示提示
Browse files Browse the repository at this point in the history
  • Loading branch information
xuejianxianzun committed Jan 20, 2025
1 parent 071b0ed commit 02d008d
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 56 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export NODE_OPTIONS=--openssl-legacy-provider

测试用的文章:https://www.fanbox.cc/@xuejianxianzun/posts/9201637

### 保存外链时会显示提示

当抓取结果里有外链保存到 TXT 文件时,会显示一条提示消息:

这次的抓取结果里有一些外部链接,下载器会把它们保存到 TXT 文件里,请手动处理。

# 4.4.2 2024/09/02

Expand Down
64 changes: 40 additions & 24 deletions dist/js/content.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/content.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Pixiv Fanbox Downloader",
"version": "4.4.2",
"version": "4.5.0",
"manifest_version": 3,
"description": "Pixiv Fanbox 批量下载器。Pixiv Fanbox batch downloader.",
"icons": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pixiv-fanbox-downloader",
"version": "4.4.2",
"version": "4.5.0",
"description": "Pixiv Fanbox Downloader",
"repository": "https://github.com/xuejianxianzun/PixivFanboxDownloader",
"author": "xuejianxianzun",
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Pixiv Fanbox Downloader",
"version": "4.4.2",
"version": "4.5.0",
"manifest_version": 3,
"description": "Pixiv Fanbox 批量下载器。Pixiv Fanbox batch downloader.",
"icons": {
Expand Down
1 change: 1 addition & 0 deletions src/ts/InitPageBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ abstract class InitPageBase {

log.success(lang.transl('_开始抓取'))
toast.show(lang.transl('_开始抓取'))
msgBox.resetOnce('tipLinktext')

EVT.fire('crawlStart')

Expand Down
50 changes: 31 additions & 19 deletions src/ts/SaveData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { settings } from './setting/Settings'
import { log } from './Log'
import { lang } from './Lang'
import { msgBox } from './MsgBox'

type Dict = {
[key in ServiceProvider]: string
Expand Down Expand Up @@ -64,8 +65,8 @@ class SaveData {
createID: data.creatorId,
tags: data.tags.join(','),
files: [],
links: {
fileId: '',
textContent: {
fileID: '',
name: 'links-' + data.id,
ext: 'txt',
size: null,
Expand All @@ -88,7 +89,7 @@ class SaveData {
if (cover) {
const { name, ext } = this.getUrlNameAndExt(cover)
const r: FileResult = {
fileId: this.createFileId(),
fileID: this.createFileId(),
name,
ext,
size: null,
Expand Down Expand Up @@ -129,12 +130,12 @@ class SaveData {
}
if (text) {
const links = this.getTextLinks(text)
result.links.text = result.links.text.concat(links)
result.links.fileId = this.createFileId()
result.textContent.text = result.textContent.text.concat(links)
result.textContent.fileID = this.createFileId()

// 保存文章正文里的文字
if (settings.saveText) {
result.links.text.push(text)
result.textContent.text.push(text)
}
}
}
Expand Down Expand Up @@ -175,18 +176,18 @@ class SaveData {

for (const link of linkTexts) {
const links = this.getTextLinks(link)
result.links.text = result.links.text.concat(links)
result.links.fileId = this.createFileId()
result.textContent.text = result.textContent.text.concat(links)
result.textContent.fileID = this.createFileId()
}

// 如果有链接,则添加一个空字符串,使其占据一行
// 这样可以让链接和下面的正文部分之间有一个空行
if (result.links.text.length > 0) {
result.links.text.push('')
if (result.textContent.text.length > 0) {
result.textContent.text.push('')
}

if (settings.saveText && text) {
result.links.text.push(text)
result.textContent.text.push(text)
}

// 保存图片资源
Expand Down Expand Up @@ -221,8 +222,8 @@ class SaveData {
embedDataArr.push([embedData.serviceProvider, embedData.contentId])
}
const embedLinks = this.getEmbedLinks(embedDataArr, data.id)
result.links.text = result.links.text.concat(embedLinks)
result.links.fileId = this.createFileId()
result.textContent.text = result.textContent.text.concat(embedLinks)
result.textContent.fileID = this.createFileId()

// 保存嵌入的 URL,只能保存到文本
if (settings.saveLink) {
Expand Down Expand Up @@ -254,8 +255,10 @@ class SaveData {
}
}
if (urlArr.length > 0) {
result.links.text = result.links.text.concat(urlArr.join('\n\n'))
result.links.fileId = this.createFileId()
result.textContent.text = result.textContent.text.concat(
urlArr.join('\n\n')
)
result.textContent.fileID = this.createFileId()
}
}
}
Expand Down Expand Up @@ -336,8 +339,17 @@ class SaveData {
[video.serviceProvider, video.videoId],
]
const embedLinks = this.getEmbedLinks(embedDataArr, data.id)
result.links.text = result.links.text.concat(embedLinks)
result.links.fileId = this.createFileId()
result.textContent.text = result.textContent.text.concat(embedLinks)
result.textContent.fileID = this.createFileId()
}

if (result.textContent.text.length > 0) {
const findURL = result.textContent.text.some((text) =>
text.includes('https://')
)
if (findURL) {
msgBox.once('tipLinktext', lang.transl('_提示有外链保存到txt'))
}
}

store.addResult(result)
Expand All @@ -350,7 +362,7 @@ class SaveData {
})
) {
return {
fileId: imageData.id,
fileID: imageData.id,
name: imageData.id,
ext: imageData.extension,
size: null,
Expand All @@ -371,7 +383,7 @@ class SaveData {
})
) {
return {
fileId: fileData.id,
fileID: fileData.id,
name: fileData.name,
ext: fileData.extension,
size: fileData.size,
Expand Down
4 changes: 2 additions & 2 deletions src/ts/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class Store {
this.resultMeta.push(data)
// 为投稿里的所有的 文本内容 生成一份数据
// 但是此时并不会生成文本的 URL,等到下载时才会为其生成 URL
if (data.links.text.length > 0) {
const result = Object.assign(this.getCommonData(data), data.links)
if (data.textContent.text.length > 0) {
const result = Object.assign(this.getCommonData(data), data.textContent)

this.result.push(result)
}
Expand Down
Loading

0 comments on commit 02d008d

Please sign in to comment.