Skip to content

Some code does not work minifed as a bookmarklet #5

@yungztrunks

Description

@yungztrunks

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 });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions