Skip to content

Commit

Permalink
Automatically add file extension if custom file output is provided fr…
Browse files Browse the repository at this point in the history
…om the browser extension (#18)
  • Loading branch information
dinoosauro committed Jul 6, 2024
1 parent c67a0a0 commit 5132f9a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions extension/code/extensionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function updateClient() {
]);
for (let [key, value] of avoidNullishValues) if (scriptOptions[key] === null) scriptOptions[key] = value;
if (scriptOptions.advanced.maximum_downloads === null) scriptOptions.advanced.maximum_downloads = Infinity;
if (typeof scriptOptions.output_name_type === "string" && ((scriptOptions.export_format === "json" && scriptOptions.output_name_type.indexOf(".json")) === -1 || (scriptOptions.export_format === "txt" && scriptOptions.output_name_type.indexOf(".txt") !== -1))) scriptOptions.output_name_type = `${scriptOptions.output_name_type}.${scriptOptions.export_format}`;
scriptOptions.node.isNode = true; // Mark this script as it is being used in Node via Puppeteer, so that a Promise will be made, resolved when it's time to download everything. While the download would start in any case, in this way we can also notify the extension UI that the conversion has ended.
startDownload().then((arr) => {
downloadScript(arr.join("\n"), true);
Expand Down
2 changes: 0 additions & 2 deletions extension/script.min.js

This file was deleted.

2 changes: 1 addition & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function downloadScript(script, force) {
}
if (typeof scriptOptions.output_name_type === "string") name = scriptOptions.output_name_type; // If it's a string, apply it to the output name
if (scriptOptions.adapt_text_output) name = sanitizeName(name); // If the user wants to use safe characters only, adapt the string name.
link.href = URL.createObjectURL(new File([blob], name, { type: "text/plain" }));
link.href = URL.createObjectURL(new File([blob], name, { type: scriptOptions.export_format === "json" ? "application/json" : "text/plain" }));
link.download = name;
link.click();
URL.revokeObjectURL(link.href);
Expand Down
4 changes: 2 additions & 2 deletions script.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5132f9a

Please sign in to comment.