engine icon indicating copy to clipboard operation
engine copied to clipboard

Preprocessing action when using `executeClientScripts`

Open martinratinaud opened this issue 3 years ago • 3 comments

It sometimes happen that user need to do an action before being able to access the document.

For example on AutoEurope.

User needs to click on the Terms and conditions link at the bottom of the page for the terms to display in a modal.

An interesting feature would be to add a preprocess action in executeClientScripts to be able to handle these kind of needs.

Lists of documents needing this

martinratinaud avatar Aug 31 '22 08:08 martinratinaud

Yes, we will certainly need this feature at some point, but let's try to put it off as long as possible.

As a workaround for AutoEurope you can use a filter to move modal content in a div with a specific ID to allow selecting it later:

// `AutoEurope.json`
{
  "name": "AutoEurope",
  "documents": {
    "Affiliate Agreement": {
      "fetch": "https://www.autoeurope.com/affiliateform/",
      "filter": ["moveModalContentFromAttributeToBody"],
      "select": "#open-terms-archive-content"
    }
  }
}
// AutoEurope.filters.json
export async function moveModalContentFromAttributeToBody(document, declaration) {
  const modalParamsString = decodeURIComponent(document.querySelector('[data-aff-terms]').getAttribute('data-aff-terms'));
  const modalParams = JSON.parse(modalParamsString);
  document.body.insertAdjacentHTML( 'beforeend', `<div id="open-terms-archive-content"><h1>${modalParams.HEAD}</h1>${modalParams.BODY}</div>`);
}

Ndpnt avatar Aug 31 '22 09:08 Ndpnt

Very clever indeed!

I made a simple search that did not find anything because it was URL encoded.

Will implement this then

martinratinaud avatar Aug 31 '22 10:08 martinratinaud

Implemented in https://github.com/OpenTermsArchive/p2b-compliance-declarations/pull/284

I suggest to close this one and reopen it if we ever encounter this problem again @Ndpnt

martinratinaud avatar Sep 06 '22 05:09 martinratinaud