Skip to content

Commit

Permalink
feat: download by page range supports -end
Browse files Browse the repository at this point in the history
close #52
  • Loading branch information
Tsuk1ko committed Aug 17, 2024
1 parent 27de7d6 commit 2564e56
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default {
unignore: 'Ignore this',
},
input: {
downloadSpecifiedPages: 'Download specified pages (e.g. 1-10,12,14,18-)',
downloadSpecifiedPages: 'Download specified pages (e.g. -5,7-10,12,14,18-)',
},
confirmPopup: {
title: 'Are you sure?',
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default {
unignore: '不再忽略',
},
input: {
downloadSpecifiedPages: '下载指定页面(例:1-10,12,14,18-)',
downloadSpecifiedPages: '下载指定页面(例:-5,7-10,12,14,18-)',
},
confirmPopup: {
title: '真的吗?',
Expand Down
13 changes: 9 additions & 4 deletions src/utils/initPage/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ export const initDetailPage = async (): Promise<void> => {
const gallery = await getGalleryInfo();
const rangeCheckers: RangeChecker[] = pagesInput.value
.split(',')
.filter(range => !Number.isNaN(parseInt(range)))
.filter(range => /^(?:\d+-?\d*|-\d+)$/.test(range))
.map(range => {
const [start, end] = range.split('-').map(num => parseInt(num));
if (typeof end === 'undefined') return page => page === start;
else if (Number.isNaN(end)) return page => page >= start;
else return page => start <= page && page <= end;
// -end
if (Number.isNaN(start)) return page => page <= end;
// start
if (end === undefined) return page => page === start;
// start-
if (Number.isNaN(end)) return page => page >= start;
// start-end
return page => start <= page && page <= end;
});

progressDisplayController.lockBtn();
Expand Down

0 comments on commit 2564e56

Please sign in to comment.