document.addEventListener("DOMContentLoaded", function () {
function updatePropertyTitle() {
// Select the target h2 element inside the lp-title-group
const titleElement = document.querySelector(".lp-title-group h2.lp-h2.title");
if (titleElement) {
// Extract the location from the URL path
const path = window.location.pathname;
const locationMatch = path.match(/\/neighborhoods\/([^/]+)/);
if (locationMatch && locationMatch[1]) {
// Format the location name (replace hyphens and capitalize words)
const location = locationMatch[1]
.replace(/-/g, " ") // Replace hyphens with spaces
.replace(/\b\w/g, (char) => char.toUpperCase()); // Capitalize each word
// Update the content of the h2 element
titleElement.textContent = `Property Listings in ${location}`;
}
}
}
// Run the function to update the title
updatePropertyTitle();
// Use MutationObserver to watch for changes if the content is dynamically loaded
const observer = new MutationObserver(updatePropertyTitle);
observer.observe(document.body, { childList: true, subtree: true });
});