Skip to content

Commit

Permalink
Add option: Make folders by download URI
Browse files Browse the repository at this point in the history
  • Loading branch information
nojimage committed Jun 28, 2023
1 parent 4d41265 commit 582b658
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Options/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ const Options = () => {
>
<span>Show file renaming textbox</span>
<//>
<br />
<${Checkbox}
id="make_uri_folder_checkbox"
title="Make folders by download URI"
checked="${options.make_uri_folder === 'true'}"
onChange=${setCheckboxOption('make_uri_folder')}
>
<span>Make folders by download URI</span>
<//>
</fieldset>
<fieldset>
Expand Down
4 changes: 4 additions & 0 deletions src/background/downloadImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ function suggestNewFilename(item, suggest) {
if (task.options.folder_name) {
newFilename += `${task.options.folder_name}/`;
}
if (task.options.make_uri_folder) {
const url = new URL(item.url);
newFilename += `${url.host}/${url.pathname.slice(0, -(item.filename.length))}/`;
}
if (task.options.new_file_name) {
const regex = /(?:\.([^.]+))?$/;
const extension = regex.exec(item.filename)[1];
Expand Down
1 change: 1 addition & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const defaults = {
// Filters
folder_name: '',
new_file_name: '',
make_uri_folder: false,
filter_url: '',
filter_url_mode: 'normal',
filter_min_width: 0,
Expand Down

0 comments on commit 582b658

Please sign in to comment.