<script>
(function() {
const targetNode = document.getElementById('create-location');
if (!targetNode) return;
const config = { childList: true, subtree: true };
const callback = function(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
// Detecting the Voxel success message
if (targetNode.innerText.includes("Your post has been submitted for review")) {
const links = targetNode.querySelectorAll('a');
let newPostId = null;
// Extracting the ID from the "Back to editing" button link
links.forEach(link => {
const href = link.getAttribute('href');
const match = href.match(/(?:post_id=|posts\/)(\d+)/);
if (match && match[1]) {
newPostId = match[1];
}
});
observer.disconnect();
if (newPostId) {
// Uses the current domain automatically
const baseUrl = window.location.origin;
const finalUrl = `${baseUrl}/?post_type=location-directory&p=${newPostId}`;
window.location.href = finalUrl;
} else {
// Fallback to the current page/home if ID is missed
window.location.href = '/';
}
}
}
}
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
})();
</script>