-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from bluenk/perf-zip-performance
修正Zip壓縮速度異常緩慢
- Loading branch information
Showing
8 changed files
with
93 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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== | ||
|
||
|
@@ -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(); | ||
} | ||
|
||
|
@@ -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')); | ||
}); | ||
} | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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== | ||
|
||
|
@@ -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(); | ||
} | ||
|
||
|
@@ -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')); | ||
}); | ||
} | ||
} | ||
}); | ||
|