window.addEventListener("load", function () {
// Add "openXtime" class to buttons with Schedule Service text or href ending
var links = Array.from(document.querySelectorAll('a')).filter(function(link) {
return link.href.endsWith("/schedule-service/") ||
link.textContent.toLowerCase().includes("schedule service");
});
links.forEach(function(link) {
link.classList.add("openXtime");
link.addEventListener("click", function(event) {
event.preventDefault();
if (window.xtime && typeof window.xtime.showC8Modal === "function") {
window.xtime.showC8Modal(true);
}
});
});
// Check for URL parameter or path to auto-open service modal
function checkAndOpenServiceModal() {
var shouldOpen = false;
var urlParams = new URLSearchParams(window.location.search);
var intsrc = urlParams.get('intsrc');
var currentPath = window.location.pathname;
// Check if URL parameter is present
if (intsrc === 'tcom:maps:dealervisit:service') {
shouldOpen = true;
}
// OR check if we're on the schedule-service page
else if (currentPath.includes('/schedule-service/') || currentPath.includes('/service/schedule-service/')) {
shouldOpen = true;
}
if (shouldOpen) {
// Function to attempt opening the modal
function attemptOpenModal() {
if (window.xtime && typeof window.xtime.showC8Modal === "function") {
window.xtime.showC8Modal(true);
return true; // Successfully opened
}
return false; // xtime not ready yet
}
// Try immediately
if (attemptOpenModal()) {
return; // Success!
}
// If not ready, set up retry mechanism
var attempts = 0;
var maxAttempts = 50; // Try for up to 5 seconds (50 * 100ms)
var retryInterval = setInterval(function() {
attempts++;
if (attemptOpenModal() || attempts >= maxAttempts) {
clearInterval(retryInterval);
}
}, 100);
}
}
// Check URL parameter/path on page load
checkAndOpenServiceModal();
});