gildas-lormeau/SingleFile

how to determine filename from user script?

Closed this issue · 2 comments

Describe the bug

for example , I want to crawl site "www.example/?id=a:b:c", and I want to save the result into a/b/c.html
Change document.title to "a/b/c.html" and use filename template "{page-title}" does not work (the extension will replace / to _ )
so I have 2 question

  1. how to make sf to interpret "/" in page title as directory separator?
  2. is it possible to determine filename from user script? like this :
  addEventListener("single-file-on-before-capture-request", (e) => {
      singleFile=e.target
      singleFile.filename="a/b/c.html"
  });

thanks!

To Reproduce

Expected behavior

Screenshots

Environment

  • OS: [e.g. Win10 Pro, Ubuntu 18.04.1, Android 7.1.2]
  • Browser: [e.g. Chrome, Firefox]
  • Version: [e.g. 64]

Additional context

Thank you for the suggestion. I've just implemented the feature which will allow you to update the options before the page is processed. Here is below an example of userscript which shows for example how to update the filenameTemplate value. This new feature will be available in the next version.

dispatchEvent(new CustomEvent("single-file-user-script-init"));


addEventListener("single-file-on-before-capture-request", event => {
  event.preventDefault();
  const { options } = event.detail;
  options.filenameTemplate = "test.html";
  dispatchEvent(new CustomEvent("single-file-on-before-capture-response", { detail: { options }}));
});

@gildas-lormeau thank you very much!