// These constants were defined according to the performance of my server.
// You can tweak them, particularily in case actions are triggered before the previous one has ended.
const waitForTableData = 3000 // how long to wait for the table data to be refreshed.
const waitForCheckboxes = 3000 // how long to wait for the checkboxes to be clicked.
const waitForModal = 3000 // how long to wait for the modal to appear
const interval = 30000 // The interval between two scripts run.
// Define a callback to delete leads
const deleteLeads = () => {
// Hack Mautic limit of 100 rows per page. When I set 500 rows it's buggy...
Mautic.limitTableData('lead',300,'list','.page-list', '/s/contacts');
setTimeout(() => {
// Click the headers checkbox to trigger checking all rows.
jQuery('#customcheckbox-one0').click()
setTimeout(() => {
// Click the batchDelete button.
jQuery('a[href="/s/contacts/batchDelete"]').click()
setTimeout(() => {
// Click the modal's delete button.
jQuery('.modal[aria-hidden="false"] .btn-danger').click()
}, waitForModal)
}, waitForCheckboxes)
}, waitForTableData)
}
// First trigger
deleteLeads()
// And run
setInterval(() => {
deleteLeads()
}, interval)