function customSetInterval(callback, interval) {
  let startTime = performance.now();
  let elapsedTime = 0;
 
  function repeat(currentTime) {
    elapsedTime = currentTime - startTime;
 
    if (elapsedTime >= interval) {
      callback();
      startTime = currentTime;
    }
 
    requestAnimationFrame(repeat);
  }
 
  requestAnimationFrame(repeat);
}
 
// Example usage:
function printMessage() {
  console.log("Hello, this is a custom setInterval!");
}
 
customSetInterval(printMessage, 2000);
 

Javascript import

// main.js
import { sayHello } from "./module.js";
 
sayHello(); // This will log "Hello from the module!" to the console.
 
<!DOCTYPE html>
<html>
<head>
  <title>My Page</title>
</head>
<body>
  <!-- Other HTML content here -->
 
  <!-- Include the main.js file -->
  <script type="module" src="path/to/main.js"></script>
</body>
</html>