Preprocessing action when using `executeClientScripts`
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
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>`);
}
Very clever indeed!
I made a simple search that did not find anything because it was URL encoded.
Will implement this then
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