Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正Zip壓縮速度異常緩慢 #16

Merged
merged 6 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions FantiaDownloader-WebExtention/WebExtention/FantiaDownloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// @include https://fantia.jp/posts/*
// @include https://fantia.jp/fanclubs/*/backnumbers*
// @icon https://www.google.com/s2/favicons?domain=fantia.jp
// @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.0/jszip.min.js
// @require https://cdn.jsdelivr.net/npm/@zip.js/[email protected]/dist/zip-full.min.js
// @grant none
// ==/UserScript==

Expand Down Expand Up @@ -672,7 +672,10 @@
this.fileImgIndex0 = 0;
this.d = this.metaData.d;

this.zip = (this.type == `zip`) ? new JSZip() : undefined;
if (this.type === 'zip') {
const blobWriter = new zip.BlobWriter('application/zip');
this.zip = new zip.ZipWriter(blobWriter);
}
return this.downloadImg();
}

Expand Down Expand Up @@ -784,31 +787,42 @@
dataCont += 1;
self.changeButton(`log`, `${dataCont} / ${self.metaData.srcArr.length}`);
self.mimeType = mimeType;
let content = new Blob([imgData], { type: mimeType });
if (self.zip == undefined) {
if (dataCont == self.metaData.srcArr.length) self.changeButton('end');
let content = new Blob([imgData], {
type: mimeType
});

downloader.download(content, self.nextName('file', i, mimeType));
return;
} else {
const sDate = lastModified && lastModified !== '' ? new Date(lastModified) : null
const date = sDate ? new Date(sDate.getTime() - sDate.getTimezoneOffset() * 60000) : new Date()
self.zip.file(self.nextName('file', i, mimeType), imgData, {
date
});
if (dataCont == self.metaData.srcArr.length) {
const sDate = lastModified && lastModified !== '' ? new Date(lastModified) : null;
const date = sDate ?? new Date();

self.zip.add(
self.nextName('file', i, mimeType),
new zip.BlobReader(content),
{
lastModDate: date,
level: 0 // The level of compression. 0 to 9, higher mean more compression.
}
);

if (dataCont === self.metaData.srcArr.length) {
self.changeButton(`pickUp`);
self.zip.generateAsync({
type: "blob"
},
function updateCallback(metadata) {
self.changeButton(`log`, `${setting.getDefault(`processing`)}:${metadata.percent.toFixed(2)} %`);
}).then(function (content) {
self.zip
.close({
// this is not getting call, maybe a bug?
onprogress: (progress, total) => {
const percent = (progress / total) * 100;
self.changeButton(
`log`,
`${windowSetting.getDefault(`processing`)}:${percent.toFixed(2)} %`
);
}
})
.then(zipBlob => {
self.changeButton('end');
downloader.download(content, self.nextName('zip', 0, mimeType));
return;
});
downloader.download(zipBlob, self.nextName('zip', 0, 'application/zip'));
});
}
}
});
Expand Down
1 change: 1 addition & 0 deletions FantiaDownloader-WebExtention/WebExtention/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ function injectScript(file_path, tag) {
}
//if (window.jQuery == undefined) {injectScript(chrome.runtime.getURL('jquery-3.4.1.js'), 'body');}
injectScript(chrome.runtime.getURL('jszip.js'), 'body');
injectScript(chrome.runtime.getURL('zip-full.min.js'), 'body');
injectScript(chrome.runtime.getURL('FantiaDownloader.js'), 'body');
45 changes: 15 additions & 30 deletions FantiaDownloader-WebExtention/WebExtention/jszip.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions FantiaDownloader-WebExtention/WebExtention/manifest_.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
{
"resources": ["jszip.js"],
"matches": ["http://*/*", "https://*/*"]
},
{
"resources": ["zip-full.min.js"],
"matches": ["http://*/*", "https://*/*"]
}
]
}
3 changes: 2 additions & 1 deletion FantiaDownloader-WebExtention/WebExtention/manifest_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"manifest_version": 2,
"author": "suzumiyahifumi",
"icons": { "64": "icon_64.png" },
"default_locale": "en",
"content_scripts" : [
{
"matches" : ["https://fantia.jp/posts/*", "https://fantia.jp/fanclubs/*/backnumbers*"],
"js" : ["inject.js"]
}
],
"web_accessible_resources": [ "FantiaDownloader.js", "jquery-3.4.1.js", "jszip.js" ]
"web_accessible_resources": [ "FantiaDownloader.js", "jquery-3.4.1.js", "jszip.js", "zip-full.min.js" ]
}
1 change: 1 addition & 0 deletions FantiaDownloader-WebExtention/WebExtention/zip-full.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion FantiaDownloader-WebExtention/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"manifest_version": 2,
"author": "suzumiyahifumi",
"icons": { "64": "icon_64.png" },
"default_locale": "en",
"content_scripts" : [
{
"matches" : ["https://fantia.jp/posts/*", "https://fantia.jp/fanclubs/*/backnumbers*"],
"js" : ["inject.js"]
}
],
"web_accessible_resources": [ "FantiaDownloader.js", "jquery-3.4.1.js", "jszip.js" ]
"web_accessible_resources": [ "FantiaDownloader.js", "jquery-3.4.1.js", "jszip.js", "zip-full.min.js" ]
}
54 changes: 34 additions & 20 deletions FantiaDownloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// @include https://fantia.jp/posts/*
// @include https://fantia.jp/fanclubs/*/backnumbers*
// @icon https://www.google.com/s2/favicons?domain=fantia.jp
// @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.0/jszip.min.js
// @require https://cdn.jsdelivr.net/npm/@zip.js/[email protected]/dist/zip-full.min.js
// @grant GM_download
// ==/UserScript==

Expand Down Expand Up @@ -684,7 +684,10 @@
this.fileImgIndex0 = 0;
this.d = this.metaData.d;

this.zip = (this.type == `zip`) ? new JSZip() : undefined;
if (this.type === 'zip') {
const blobWriter = new zip.BlobWriter('application/zip');
this.zip = new zip.ZipWriter(blobWriter);
}
return this.downloadImg();
}

Expand Down Expand Up @@ -800,31 +803,42 @@
dataCont += 1;
self.changeButton(`log`, `${dataCont} / ${self.metaData.srcArr.length}`);
self.mimeType = mimeType;
let content = new Blob([imgData], { type: mimeType });
if (self.zip == undefined) {
if (dataCont == self.metaData.srcArr.length) self.changeButton('end');
let content = new Blob([imgData], {
type: mimeType
});

downloader.download(content, self.nextName('file', i, mimeType));
return;
} else {
const sDate = lastModified && lastModified !== '' ? new Date(lastModified) : null
const date = sDate ? new Date(sDate.getTime() - sDate.getTimezoneOffset() * 60000) : new Date()
self.zip.file(self.nextName('file', i, mimeType), imgData, {
date
});
if (dataCont == self.metaData.srcArr.length) {
const sDate = lastModified && lastModified !== '' ? new Date(lastModified) : null;
const date = sDate ?? new Date();

self.zip.add(
self.nextName('file', i, mimeType),
new zip.BlobReader(content),
{
lastModDate: date,
level: 0 // The level of compression. 0 to 9, higher mean more compression.
}
);

if (dataCont === self.metaData.srcArr.length) {
self.changeButton(`pickUp`);
self.zip.generateAsync({
type: "blob"
},
function updateCallback(metadata) {
self.changeButton(`log`, `${windowSetting.getDefault(`processing`)}:${metadata.percent.toFixed(2)} %`);
}).then(function (content) {
self.zip
.close({
// this is not getting call, maybe a bug?
onprogress: (progress, total) => {
const percent = (progress / total) * 100;
self.changeButton(
`log`,
`${windowSetting.getDefault(`processing`)}:${percent.toFixed(2)} %`
);
}
})
.then(zipBlob => {
self.changeButton('end');
downloader.download(content, self.nextName('zip', 0, mimeType));
return;
});
downloader.download(zipBlob, self.nextName('zip', 0, 'application/zip'));
});
}
}
});
Expand Down