invoiceradar / plugins

11 stars 5 forks source link

Multiline scripts #17

Closed chriskalmar closed 5 months ago

chriskalmar commented 6 months ago

Proposal for a schema change to support multiline scripts as an array of strings for improved readability. of course, the stitching together of the lines will need to be implemented in the app as well.

the idea is to turn this:

    {
      "action": "extractAll",
      "script": "Array.from(Array.from(document.querySelectorAll('h2')).filter(el => el.textContent.startsWith('Invoices'))[0].closest('div').querySelectorAll('table tbody tr')).map(row => { const cells = row.querySelectorAll('td'); const date = cells[0].innerText.trim(); const total = cells[1].innerText.trim(); const url = cells[2].querySelector('a').href; const match = url.match(/receipt\\/([^\\/]+)/); const id = match ? match[1] : null; return { id, date, total, url }; })",
      "variable": "item",
      ...

into that:

    {
      "action": "extractAll",
      "script": [
        "Array.from(",
        "  Array.from(document.querySelectorAll('h2'))",
        "    .filter(el => el.textContent.startsWith('Invoices'))[0]",
        "    .closest('div')",
        "    .querySelectorAll('table tbody tr')",
        "  ).map(row => {",
        "    const cells = row.querySelectorAll('td');",
        "    const date = cells[0].innerText.trim();",
        "    const total = cells[1].innerText.trim();",
        "    const url = cells[2].querySelector('a').href;",
        "    const match = url.match(/receipt\\/([^\\/]+)/);",
        "    const id = match ? match[1] : null;",
        "    return { id, date, total, url };",
        "  }",
        ")"
      ],
      "variable": "item",
      ...
timolins commented 5 months ago

Thanks for your suggestion. Closing this in favour of the new in-app code editor, which makes writing JS a lot more enjoyable.

chriskalmar commented 5 months ago

absolutely, makes sense. 👍