Skip to content

Commit 9277396

Browse files
author
leoding86
committed
Merge branch 'master' of github.com:leoding86/webextension-pixiv-toolkit
2 parents 1897cb9 + 277c425 commit 9277396

8 files changed

Lines changed: 94 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pixiv-toolkits",
3-
"version": "6.4.1",
3+
"version": "6.4.2",
44
"description": "A web extension for adding features on Pixiv and more",
55
"author": "leoding86 <leoding86@msn.com>",
66
"private": false,

src/background/services/DownloadService.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: Leo Ding <leoding86@msn.com>
33
* @Date: 2024-08-11 11:09:14
44
* @LastEditors: Leo Ding <leoding86@msn.com>
5-
* @LastEditTime: 2024-08-21 19:54:16
5+
* @LastEditTime: 2024-09-22 13:13:08
66
* @FilePath: \webextension-pixiv-toolkit\src\background\services\DownloadService.js
77
*/
88
import browser from "@/modules/Extension/browser";
@@ -24,6 +24,12 @@ class DownloadService extends AbstractService {
2424

2525
constructor() {
2626
super();
27+
this.listenOnDeterminingFilename();
28+
}
29+
30+
listenOnDeterminingFilename() {
31+
if (DownloadService.onDeterminingFilenameListenered === true) return;
32+
DownloadService.onDeterminingFilenameListenered = true;
2733

2834
browser.downloads.onDeterminingFilename.addListener((downloadItem, suggest) => {
2935
const filenameSuggestion = {
@@ -37,8 +43,6 @@ class DownloadService extends AbstractService {
3743
filenameSuggestion.filename = downloadItem.filename;
3844
}
3945

40-
console.log(downloadItem, filenameSuggestion);
41-
4246
suggest(filenameSuggestion);
4347
});
4448
}
@@ -133,4 +137,9 @@ class DownloadService extends AbstractService {
133137
}
134138
}
135139

140+
/**
141+
* @type {boolean} Prevent listen the event multiple times
142+
*/
143+
DownloadService.onDeterminingFilenameListenered = false;
144+
136145
export default DownloadService;

src/background/updates/update6_0_0.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: Leo Ding <leoding86@msn.com>
33
* @Date: 2024-08-21 13:26:02
44
* @LastEditors: Leo Ding <leoding86@msn.com>
5-
* @LastEditTime: 2024-09-08 14:12:23
5+
* @LastEditTime: 2024-09-22 11:24:09
66
* @FilePath: \webextension-pixiv-toolkit\src\background\updates\update6_0_0.js
77
*/
88
import { app } from "../Application";
@@ -15,7 +15,7 @@ import defaultSettings from "@/config/default";
1515
export default async () => {
1616
let settings = await app().getService('setting').getSettings();
1717
let updateSettings = Object.assign({}, defaultSettings, settings, {
18-
version: '6.4.1',
18+
version: '6.4.2',
1919
});
2020

2121
/**

src/modules/GlobalSettings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @property {number} downloadSaveMode
44
* @property {number} globalZipMultipleImages
55
* @property {number} downloadSaveMode
6+
* @property {boolean} enableDownloadMetadata
67
*
78
* @param {*} fallback
89
* @returns {GlobalSettings}

src/options_page/modules/DownloadTasks/MultiplePagesDownloadTask.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,50 @@ class MultipleDownloadTask extends AbstractDownloadTask {
197197
this.dispatch('progress', [this.progress]);
198198
}
199199

200+
/**
201+
* Override in download task
202+
* @returns {boolean}
203+
*/
204+
canSaveInfo() {
205+
return false;
206+
}
207+
208+
async saveInfo() {
209+
const metaFilename = 'info.json';
210+
const that = this;
211+
212+
return new Promise(async resolve => {
213+
const blob = new Blob([JSON.stringify(that.options.context)], {
214+
type: 'application/json'
215+
});
216+
217+
if (that.shouldZipFile()) {
218+
that.zip.file(metaFilename, blob, { date: this.now });
219+
} else {
220+
await browser.runtime.sendMessage({
221+
to: 'ws',
222+
action: 'download:saveFile',
223+
args: {
224+
url: URL.createObjectURL(blob),
225+
filename: metaFilename
226+
}
227+
})
228+
}
229+
resolve();
230+
});
231+
}
232+
200233
/**
201234
* @fires MultipleDownloadTask#complete
202235
*/
203-
onFinish() {
236+
async onFinish() {
237+
if (GlobalSettings().enableDownloadMetadata &&
238+
this.options.context &&
239+
this.canSaveInfo()
240+
) {
241+
await this.saveInfo();
242+
}
243+
204244
if (this.shouldZipFile()) {
205245
const nameFormatter = NameFormattor.getFormatter({ context: Object.assign({}, this.context) });
206246
let filename = pathjoin(

src/options_page/modules/DownloadTasks/Pixiv/IllustDownloadTask.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* @Author: Leo Ding <leoding86@msn.com>
3+
* @Date: 2024-08-01 01:14:07
4+
* @LastEditors: Leo Ding <leoding86@msn.com>
5+
* @LastEditTime: 2024-09-22 13:05:04
6+
* @FilePath: \webextension-pixiv-toolkit\src\options_page\modules\DownloadTasks\Pixiv\IllustDownloadTask.js
7+
*/
18
import MultipleDownloadTask from "../MultiplePagesDownloadTask";
29

310
/**
@@ -25,6 +32,14 @@ class IllustDownloadTask extends MultipleDownloadTask {
2532
static create(options) {
2633
return new IllustDownloadTask(options);
2734
}
35+
36+
/**
37+
* @override
38+
* @returns {true}
39+
*/
40+
canSaveInfo() {
41+
return true;
42+
}
2843
}
2944

3045
export default IllustDownloadTask;

src/options_page/modules/DownloadTasks/Pixiv/MangaDownloadTask.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ class MangaDownloadTask extends MultipleDownloadTask {
2525
static create(options) {
2626
return new MangaDownloadTask(options);
2727
}
28+
29+
/**
30+
* @override
31+
* @returns {true}
32+
*/
33+
canSaveInfo() {
34+
return true;
35+
}
2836
}
2937

3038
export default MangaDownloadTask;

src/options_page/modules/DownloadTasks/Pixiv/UgoiraDownloadTask.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ class UgoiraDownloadTask extends AbstractDownloadTask {
186186
URL.revokeObjectURL(url);
187187

188188
this.dispatch('progress', [this.progress]);
189+
190+
/**
191+
* Save work information accroding the enableDownloadMetadata setting
192+
*/
193+
if (GlobalSettings().enableDownloadMetadata && this.options.context) {
194+
const blob = new Blob([JSON.stringify(this.options.context)], { type: 'application/json' });
195+
await browser.runtime.sendMessage({
196+
to: 'ws', action: 'download:saveFile',
197+
args: {
198+
url: URL.createObjectURL(blob),
199+
filename: 'info.json'
200+
}
201+
});
202+
}
189203
}
190204

191205
/**

0 commit comments

Comments
 (0)