Skip to content

Commit 7b82eaf

Browse files
committed
Merge branch 'feature'
2 parents b8f07b1 + 6f6b8ac commit 7b82eaf

File tree

20 files changed

+378
-140
lines changed

20 files changed

+378
-140
lines changed

config/webpack.background.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,22 @@ module.exports = env => {
5858

5959
json.version_name = json.version = packageInfo.version;
6060

61+
/**
62+
* About manifest file, there are some differences between FireFox and browsers which based Chromium.
63+
* So we need do some extra works to make the target browser manifest file.
64+
*/
6165
if (json.options_page && platform === 'firefox') {
6266
console.log(`rename options_page to options_ui`);
6367

6468
json.options_ui = {};
6569
json.options_ui.page = json.options_page;
6670
json.options_ui.open_in_tab = true;
71+
72+
json.optional_permissions.forEach(permission => {
73+
json.permissions.push(permission);
74+
});
75+
76+
delete json.optional_permissions;
6777
delete json.options_page;
6878

6979
console.log(`remove version_name property from manifest`);

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": "5.0.3",
3+
"version": "5.1.0",
44
"description": "A web extension for adding features on Pixiv",
55
"author": "leoding86 <leoding86@msn.com>",
66
"private": false,

src/config/default.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,14 @@ export default Object.assign({}, {
191191
downloadPackFiles: true,
192192
ugoiraConvertTool: 'default',
193193
ugoiraCustomFFmpegCommand: '',
194+
195+
/**
196+
* @since 5.1.0
197+
*/
198+
illustrationCreateSubdirectory: true,
199+
200+
/**
201+
* @since 5.2.0
202+
*/
203+
disableDownloadsShelf: false,
194204
});

src/content_scripts/Browser/downloads.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import Browser from '@/modules/Browser/Browser';
22

3+
/**
4+
* @typedef DownloadOptions
5+
* @property {ArrayBuffer} arrayBuffer
6+
* @property {string} url
7+
* @property {boolean} saveAs
8+
* @property {string} filename
9+
*/
310
export default {
11+
/**
12+
*
13+
* @param {DownloadOptions} options
14+
* @returns
15+
*/
416
download(options) {
517
return new Promise(function (resolve, reject) {
618
let browser = Browser.getBrowser();

src/content_scripts/FilesDownloader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ class FilesDownloader extends Event {
150150
});
151151
});
152152

153-
zip.generateAsync({ type: 'blob' }).then(blob => {
153+
zip.generateAsync({ type: 'arraybuffer' }).then(ab => {
154154
resolve({
155-
data: blob,
155+
data: ab,
156156
filename: ((typeof getFilenameFunc == 'function') ? getFilenameFunc() : this.getPackedFilename()) + '.zip'
157157
});
158158
}).catch(error => {

src/content_scripts/components/Illust.vue

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ export default {
9797
}
9898
},
9999
100+
created() {
101+
this.createSubdirectory = this.browserItems.illustrationCreateSubdirectory;
102+
},
103+
100104
mounted() {
101105
/**
102106
* @var {IllustTool}
@@ -229,6 +233,27 @@ export default {
229233
}
230234
},
231235
236+
/**
237+
* Download multiple files
238+
*
239+
* @param {Object[]} files
240+
* @param {{savePath: string}} options
241+
* @param {number} [index=0]
242+
* @returns {Promise}
243+
*/
244+
downloadMultipleFiles(files, { savePath }, index = 0) {
245+
let file = files[index];
246+
247+
if (!file) {
248+
return Promise.resolve();
249+
}
250+
251+
return this.downloadFile({
252+
src: file.data, filename: file.filename, folder: savePath
253+
})
254+
.then(() => this.downloadMultipleFiles(files, { savePath }, index + 1));
255+
},
256+
232257
/**
233258
* Download multiple files. The browser will popup a confirm dialog for user
234259
* for asking user if he/she agree to download multiple files from the website.
@@ -251,32 +276,29 @@ export default {
251276
}
252277
253278
if ((files.length === 1 && this.alwaysPack) || (files.length > 1 && this.packFiles)) {
254-
this.tool.getPackedFile({files}).then(file => {
279+
this.tool.getPackedFile({files}).then(result => {
255280
/**
256281
* Download zip file
257282
*/
258-
this.downloadFile(file.data, file.filename, {
259-
folder: savePath,
260-
statType: 'illust'
261-
});
283+
this.downloadFile({
284+
src: result.data,
285+
filename: result.filename,
286+
folder: savePath
287+
})
288+
.then(() => this.updateDownloadStat('illust'));
262289
});
263290
} else {
264-
savePath = pathjoin(savePath, this.tool.relativePath, '/');
291+
if (this.createSubdirectory) {
292+
savePath = pathjoin(savePath, this.tool.relativePath, '/');
293+
} else {
294+
savePath = pathjoin(savePath, '/');
295+
}
265296
266297
/**
267298
* Cache files and change button type
268299
*/
269-
270-
files.forEach(file => {
271-
this.downloadFile(
272-
new Blob([file.data], { type: file.mimeType }),
273-
file.filename,
274-
{
275-
folder: savePath,
276-
statType: 'illust'
277-
}
278-
);
279-
});
300+
this.downloadMultipleFiles(files, { savePath })
301+
.then(() => this.updateDownloadStat('illust'));
280302
}
281303
282304
this.saveDownloadRecord({ illust: 1 });

src/content_scripts/components/Manga.vue

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,27 @@ export default {
159159
this.$set(this.buttonsInfo, buttonInfo.index, Object.assign(buttonInfo, data));
160160
},
161161
162+
/**
163+
* Download multiple files
164+
*
165+
* @param {Object[]} files
166+
* @param {{savePath: string}} options
167+
* @param {number} [index=0]
168+
* @returns {Promise}
169+
*/
170+
downloadMultipleFiles(files, { savePath }, index = 0) {
171+
let file = files[index];
172+
173+
if (!file) {
174+
return Promise.resolve();
175+
}
176+
177+
return this.downloadFile({
178+
src: file.data, filename: file.filename, folder: savePath
179+
})
180+
.then(() => this.downloadMultipleFiles(files, { savePath }, index + 1));
181+
},
182+
162183
/**
163184
* Download multiple files. The browser will popup a confirm dialog for user
164185
* for asking user if he/she agree to download multiple files from the website.
@@ -186,28 +207,21 @@ export default {
186207
/**
187208
* Download zip file
188209
*/
189-
this.downloadFile(file.data, file.filename, {
210+
this.downloadFile({
211+
src: file.data,
212+
filename: file.filename,
190213
folder: savePath,
191-
statType: 'manga'
192-
});
214+
})
215+
.then(() => this.updateDownloadStat('manga'));
193216
});
194217
} else {
195218
savePath = pathjoin(savePath, this.tool.relativePath, '/');
196219
197220
/**
198221
* Cache files and change button type
199222
*/
200-
201-
files.forEach(file => {
202-
this.downloadFile(
203-
new Blob([file.data], { type: file.mimeType }),
204-
file.filename,
205-
{
206-
folder: savePath,
207-
statType: 'manga'
208-
}
209-
);
210-
});
223+
this.downloadMultipleFiles(files, { savePath })
224+
.then(() => this.updateDownloadStat('manga'));
211225
}
212226
213227
this.saveDownloadRecord({ manga: 1 });

src/content_scripts/components/Novel.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,12 @@ export default {
156156
this.getSubfolder(this.browserItems.novelRelativeLocation, this.tool.context) :
157157
this.browserItems.downloadRelativeLocation;
158158
159-
this.downloadFile(blob, this.getFilename(type), {
159+
this.downloadFile({
160+
src: blob,
161+
filename: this.getFilename(type),
160162
folder: savePath,
161-
statType: 'novel'
162-
});
163+
})
164+
.then(() => this.updateDownloadStat('novel'));
163165
164166
let record = {};
165167

src/content_scripts/components/Ugoira.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,12 @@ export default {
181181
182182
let savePath = this.getSavePath();
183183
184-
this.downloadFile(this.tool.zipBlob, this.getFilename() + '.zip', {
184+
this.downloadFile({
185+
src: this.tool.zipBlob,
186+
filename: this.getFilename() + '.zip',
185187
folder: savePath,
186-
statType: 'ugoira',
187-
});
188+
})
189+
.then(() => this.updateDownloadStat('ugoira'));
188190
189191
this.saveDownloadRecord({
190192
zip: 1
@@ -197,10 +199,12 @@ export default {
197199
saveFile(button, blob, type) {
198200
let savePath = this.getSavePath();
199201
200-
this.downloadFile(blob, this.getFilename() + '.' + button.extName, {
202+
this.downloadFile({
203+
src: blob,
204+
filename: this.getFilename() + '.' + button.extName,
201205
folder: savePath,
202-
statType: 'ugoira'
203-
});
206+
})
207+
.then(() => this.updateDownloadStat('ugoira'));
204208
205209
let data = {};
206210
data[type] = 1;

0 commit comments

Comments
 (0)