Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some code does not work minifed as a bookmarklet #5

Open
yungztrunks opened this issue Oct 16, 2024 · 0 comments
Open

Some code does not work minifed as a bookmarklet #5

yungztrunks opened this issue Oct 16, 2024 · 0 comments

Comments

@yungztrunks
Copy link
Owner

yungztrunks commented Oct 16, 2024

I found out, that there are code snippets that just don't work minified. I am unable to find the exact reason why.
The code just does not work
Here is one example

function applyTableStyles() {
    const tables = document.querySelectorAll('table');

    tables.forEach(table => {
        table.addEventListener('click', (event) => {
            event.stopPropagation();
            console.log('Table clicked');
            alert('Table clicked!');

            exportToExcel(table);
        }, true);
    });
}

function exportToExcel(table) {
    let tableData = table.outerHTML; // Capture the table HTML
    tableData = tableData.replace(/<input[^>]*>|<\/input>/gi, ""); // Remove input elements if any

    let a = document.createElement('a');
    a.href = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(tableData);
    a.download = `table_${get_suffix()}.xls`;
    a.click();
}

function get_suffix() {
    let dateObj = new Date();
    let dateTime = `${dateObj.getHours()}${dateObj.getMinutes()}${dateObj.getSeconds()}`;
    return `${dateTime}${Math.floor(Math.random() * 100)}`;
}

document.addEventListener('DOMContentLoaded', () => {
    applyTableStyles();

    const observer = new MutationObserver(applyTableStyles);
    observer.observe(document.body, { childList: true, subtree: true });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant