var rows confluenceTable find tr var category category_code var is_fir

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var rows = $('.confluenceTable').find('tr');
var category, category_code;
var is_first = 1;
var code_switch = "\nfunction getMessage(code) {\n" +
"\tswitch (code) {\n";
var code = "var Codes = {\n";
for (var i = 0; i < rows.length; ++i) {
var cols = $(rows[i]).find('td');
if (!cols.length)
continue;
if (cols.length == 7) {
category = cols[0].textContent;
category_code = parseInt(cols[1].textContent);
if (!is_first) {
code += "\t}, \n\n";
} else
is_first = 0;
code += "\t" + category + ": {\n";
code += "\t\tcode: " + category_code + ", \n";
}
code += "\t\t" + cols[cols.length - 5].textContent + ": " + parseInt(cols[cols.length - 3].textContent) + ", \n";
code_switch += "\t\tcase Codes." + category + "." + cols[cols.length - 5].textContent + ":\n\t\t\treturn \"" + cols[cols.length - 2].textContent + "\";\n";
}
code += "\t}\n};\n";
code_switch += "\t\tdefault: \"Ошибка\";\n\t}\n}\n";
console.log(code + code_switch);
// eval(code + code_switch);