(function(){
    function run(){
        var tables = document.querySelectorAll('table.cs-fin-table, table.veh-table');
        for (var t = 0; t < tables.length; t++) {
            var table = tables[t];
            var heads = [];
            var ths = table.querySelectorAll(':scope > thead > tr > th');
            for (var h = 0; h < ths.length; h++) { heads.push(ths[h].textContent.trim()); }
            if (!heads.length) { continue; }
            var rows = table.querySelectorAll(':scope > tbody > tr');
            for (var r = 0; r < rows.length; r++) {
                var idx = 0, cells = rows[r].children;
                for (var c = 0; c < cells.length; c++) {
                    var cell = cells[c];
                    if (cell.tagName !== 'TD') { continue; }
                    var span = cell.colSpan || 1;
                    if (span === 1 && heads[idx] && !cell.hasAttribute('data-label')) {
                        cell.setAttribute('data-label', heads[idx]);
                    }
                    idx += span;
                }
            }
        }
    }
    if (document.readyState !== 'loading') { run(); }
    else { document.addEventListener('DOMContentLoaded', run); }
})();
