Using settimeout function in javascript you can run the CSS code continuously to update and change the style.
Example:
setTimeout(() => document.getElementsByClassName("mx-name-container1").style.backgroundColor ="green");
The solution provided with setTimeout() / setInterval() is a JavaScript workaround which is not really recommended. Why not add an on click event handler to the pagination buttons?
You can target these buttons with the HTML snippet once the page is loaded and based on the CSS class you can give in Studio Pro to the datagrid, those pagination buttons can be retrieved with plain JavaScript like document.getElementsByClassName. Once retrieved add the on click event handler. On click run the code you are also running on page load.