// Wait for the DOM content to be fully loaded
window.onload = function() {
if (window.self !== window.top) {
return;
}
// Function to simulate clicking the next arrow
function clickNext(arrow) {
arrow.click();
}
// Query all elements with the class for carousel next arrows
var nextArrows = document.querySelectorAll('[data-test="gallery-reel-control-btn-next"]');
// Set auto-scrolling for each carousel
nextArrows.forEach(function(arrow) {
var intervalId; // Variable to hold the interval ID
// Define a function to handle auto-scrolling for a specific carousel
function autoScroll() {
clickNext(arrow);
}
// Start the auto-scrolling for the current carousel
intervalId = setInterval(autoScroll, 2000);
// Stop autoplay when the arrow is clicked
arrow.addEventListener("click", function(e) {
// Stop autoplay when it is user-triggered event
if (e.offsetX || e.offsetY) {
clearInterval(intervalId);
}
});
});
};