document.addEventListener('DOMContentLoaded', (event) => {
const updateTableContent = () => {
// Change the column header from "Suite" to "Address"
const suiteHeader = document.querySelector('th.react-suitelist-header');
if (suiteHeader && suiteHeader.textContent.trim() === 'Suite') {
suiteHeader.textContent = 'Address';
}
// Update "Suite" to "Montana Ave" and prepare rows for sorting
const rows = Array.from(document.querySelectorAll('.react-suitelist-table tbody tr'));
rows.forEach(row => {
const suiteCell = row.querySelector('td.react-suitelist-content');
if (suiteCell && suiteCell.textContent.includes('Suite')) {
suiteCell.textContent = suiteCell.textContent.split(' ')[1] + ' Montana Ave ';
}
});
// Sort the rows numerically based on the suite numbers
const sortedRows = rows.sort((a, b) => {
const numA = a.querySelector('td.react-suitelist-content').textContent.match(/\d+/g);
const numB = b.querySelector('td.react-suitelist-content').textContent.match(/\d+/g);
return numA && numB ? parseInt(numA[0], 10) - parseInt(numB[0], 10) : 0;
});
// Re-append sorted rows back to the table body
const tableBody = document.querySelector('.react-suitelist-table tbody');
sortedRows.forEach(row => {
tableBody.appendChild(row);
});
// Update the divider lines to dark blue
const allCells = document.querySelectorAll('.react-suitelist-table th, .react-suitelist-table td');
allCells.forEach(cell => {
cell.style.borderBottom = '1px solid #020E56';
});
};
// Options for the observer (which mutations to observe)
const config = { attributes: false, childList: true, subtree: true };
// Callback function to execute when mutations are observed
const callback = (mutationsList, observer) => {
for (let mutation of mutationsList) {
if (mutation.addedNodes.length > 0 && document.querySelector('.react-suitelist-table')) {
console.log("table detected, updating content");
updateTableContent();
observer.disconnect(); // Stop observing after making the changes
break;
}
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(document.body, config);
});