A lovely case of a dynamically loaded table with a ridiculously long class name on the button!
Here's a JavaScript snippet that you can paste into the console. It will download the table as an HTML file every time the button is pressed. I've added comments for clarity.
(function() {
// Select the table and the button using their class names
const table = document.querySelector('.table_table__8D7gp');
const button = document.querySelector('.MuiButtonBase-root.MuiButton-root'); // shortened the selector, see notes
// Function to download the table as HTML file
function downloadTableAsHtml() {
// Get the outerHTML of the table (includes the table tag itself)
const tableHtml = table.outerHTML;
// Create a blob with the HTML content
const blob = new Blob([tableHtml], { type: 'text/html' });
// Create a link element to trigger the download
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
// Set the file name with a timestamp to avoid overwrites
link.download = `table_${new Date().toISOString().replace(/:/g, '-').split('.')[0]}.html`;
// Simulate a click on the link to start the download
link.click();
// Clean up
URL.revokeObjectURL(link.href);
link.remove();
}
// Function to handle button clicks
function handleButtonClick() {
// Wait a brief moment for the table content to update (adjust the timeout if needed)
setTimeout(downloadTableAsHtml, 200); // 200ms should be enough, but tweak if necessary
}
// Add an event listener to the button
button.addEventListener('click', handleButtonClick);
// Optional: download the initial table state immediately
downloadTableAsHtml();
// To avoid polluting the global scope, we return a function to stop the script
return function stopScript() {
button.removeEventListener('click', handleButtonClick);
console.log('Table download script stopped.');
};
})();
Notes:
- Shortened button selector: Since the button's class list is enormous and generated by Material-UI, it's reasonable to assume that
MuiButtonBase-root and MuiButton-root are stable parts of the class list. If this doesn't work because the classes change dynamically on your site, try using document.querySelector('[class*="MuiButton-containedSecondary"]') or another part of the class name that's unique and stable.
- Timeout adjustment: The
setTimeout delay (200ms in the example) allows the table content to update before downloading. If your table takes longer to load the next part, increase this value.
- Stopping the script: The script returns a
stopScript function. If you want to stop the automatic downloads, just call stopScript() in the console.
- Initial download: The script downloads the table immediately once it's pasted into the console. If you don't want this initial download, comment out or remove the line
downloadTableAsHtml();.
How to use:
- Open your browser's Developer Tools (F12 or Ctrl+Shift+I / Cmd+Opt+I).
- Switch to the Console tab.
- Paste the provided JavaScript code into the console and press Enter.
- Now, every time you click the button to switch to the next part of the table, it should automatically trigger a download of the updated table as an HTML file.
Happy downloading!