PageSourceSearch

https://veracruz.ba.gov.br/wp-includes/ExternalApps/resources/js/datatable_btn.js?d=202311221127

js veracruz.ba.gov.br collected 2026-09-25 09:31:17 UTC 5,702 bytes, 185 lines download raw bytes

1window.addEventListener('DOMContentLoaded', function () {   
2    let buttonsDefault = [];
3    
4    buttonsDefault = [
5        {'text': 'HTML'},
6        {'text': 'XML'},
7        {'text': 'TXT'},
8    ];
9
10    const defineBtn = function (name, onclick) {
11        return new Promise(function (resolve, reject) {
12            let tries = 0;
13
14            const  waitButtons = setInterval(function () {
15                const buttons = document.querySelector('.dt-buttons');
16    
17                tries ++;
18                if (buttons) {
19                    clearInterval(waitButtons);
20
21                    resolve(buttons);
22                }
23
24                if (tries > 30) {
25                    clearInterval(waitButtons);
26                    reject(tries)
27                }
28            }, 300);
29        }).then(function (buttons) {
30            const bt = document.createElement('a');
31            bt.onclick = onclick;
32            bt.setAttribute('class', buttons.children[0].getAttribute('class'));
33            bt.setAttribute('tabindex', '0');
34            bt.setAttribute('aria-controls', 'dataTableBuilder');
35            bt.dataset.dt = name;
36            bt.innerHTML = `<span>${name.toUpperCase()}</span>`;
37            buttons.appendChild(bt);
38        })
39        .catch(function () {})
40    }
41
42    const getJSON = function () {
43        const table = document.querySelector('table');
44        let data = [...table.rows].map(t => [...t.children].map(u => u.innerText));
45
46        const head = data[0];
47        const body = data.filter((d, i) => i != 0);
48
49        data = {head, body};
50
51        return data;
52        
53    }
54
55    const getFields = function () {
56        const table = document.querySelector('table');
57        let data = [...table.rows].map(t => [...t.children].map(u => u.innerText));
58        const head = data[0];
59        const fields = data.filter((d, i) => i != 0);
60
61        data = [];
62
63        fields.forEach(field => {
64            let vfield = [];
65            field.forEach((value, index) => {
66                vfield.push({head: clearHead(head[index]), body: clear(value)});
67            });
68            data.push(vfield);
69        })
70
71        return data;
72    }
73
74    const createBlob = function (content, mimeType) {
75        mimeType = mimeType ?? 'text/plain';
76        const blob = new Blob([content], {type: mimeType});
77        return blob;
78    }
79
80    const download = function (content, ext, filename, blob) {
81        filename = filename ?? new Date().getTime();
82        blob = blob ?? createBlob(content);
83        const url = window.URL.createObjectURL(blob);
84        const link = document.createElement('a');
85        link.href = url;
86        link.download = `${filename}.${ext}`;                        
87        document.body.append(link);
88        link.click();
89    }
90
91    const clearHead = function (text) {
92        text = clear(text);
93        text = text.replace(/[\/]/g, '');
94
95        return text;
96    }
97
98    const clear = function  (text) {       
99        text = text.toLowerCase();                                                         
100        text = text.replace(new RegExp('[ÁÀÂÃ]','gi'), 'a');
101        text = text.replace(new RegExp('[ÉÈÊ]','gi'), 'e');
102        text = text.replace(new RegExp('[ÍÌÎ]','gi'), 'i');
103        text = text.replace(new RegExp('[ÓÒÔÕ]','gi'), 'o');
104        text = text.replace(new RegExp('[ÚÙÛ]','gi'), 'u');
105        text = text.replace(new RegExp('[Ç]','gi'), 'c');
106        text = text.replace(/[ÀÁÂÃÄÅ]/g,"A");
107        text = text.replace(/[àáâãäå]/g,"a");
108        text = text.replace(/[ÈÉÊË]/g,"E");
109        text = text.replaceAll('º', '');
110        text = text.replaceAll(' ', '_');
111        text = text.replace(/[¿½ï$\(\)]/g, '');
112        return text;                 
113    }
114
115    const TXT = function () {
116        const json = getJSON();
117        let content = '0';
118        let space = 300;
119
120        json.head.forEach(v => {
121            content += `${v}`.padEnd(space, ' ');
122        });
123
124        json.body.forEach((record, i) => {
125            if(i == 0) {
126                content += '\n1';
127            }else {
128                content += '\n';
129            }
130            record.forEach((r, ri) => {
131                content += `${r}`.padEnd(space, ' ');
132            });
133        });
134
135        return content;
136    }
137
138    const XML = function () {
139        let fields = getFields();
140        let content = '<\?xml version="1.0"\?>\n';
141
142        content += '<itens>\n';
143        fields.forEach((record, i) => {
144            content += `\t<item id="${i}">\n`;
145            record.forEach((r, ri) => {
146                content += `\t\t<${r.head == '' ? 'campo_nulo' : r.head}>\n`;
147                content += `\t\t ${r.body == '' ? '-' : r.body}`;
148                content += `\n\t\t</${r.head == '' ? 'campo_nulo' : r.head}>\n`;
149            });
150            content += `\t</item>\n`;
151        });
152        content += '</itens>\n';
153
154        return content;
155        
156    }
157
158    const HTML = function () {
159        const json = getJSON();
160        let content = '';
161
162        content += '<table border="1" align="center" style="white-space:nowrap;">\n';
163        content += '<tr>\n';
164        json.head.forEach(v => {
165            content += `<th>${v}</th>\n`;
166        });
167        content += '</tr>\n';
168
169        json.body.forEach(v => {
170            content += '<tr>\n';
171            v.forEach((value) => {
172                content += `<td>${value}</td>\n`;
173            });
174            content += '</tr>';
175        });
176
177        content += '</table>\n';
178
179        return content;
180    }
181    
182    defineBtn('html', () => download(HTML(), 'html'))
183    defineBtn('xml', () => download(XML(), 'xml'))
184    defineBtn('txt', () => download(TXT(), 'txt'))
185})

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.