-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.html
199 lines (182 loc) · 6.17 KB
/
parse.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html>
<script type="text/javascript">
window.onload = function () {
function readSingleFile(event) {
let file = event.target.files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function (event) {
let content = event.target.result;
displayContent(content);
};
reader.readAsText(file, 'windows-1251');
}
function displayContent(contents) {
let element = document.getElementById('data');
element.innerHTML = contents;
// Check which radio button is selected
let selectedFunction = document.querySelector(
'input[name="functionChoice"]:checked'
).value;
// Call the selected function
if (selectedFunction === 'build17') {
createArrayBuild17();
} else if (selectedFunction === 'build17Oriented') {
createArrayBuild17Oriented();
}
}
function isFirstCharacterEnglishLetter(text) {
const regex = /^[A-Za-z]/;
return regex.test(text.trim());
}
function createArrayBuild17() {
let arr = [];
let table = document.getElementsByClassName('xl9117826')[0];
let count = 0;
for (var i = 0; i < table.rows.length; i++) {
append = 0;
for (var j = 0; j < table.rows[i].cells.length - 2; j++) {
if (table.rows[i].className != 'xl10617826') break;
if (table.rows[i].cells[j].innerHTML != ' ') {
if (append == 0 && table.rows[i].cells[j].rowSpan == '2')
arr.push([j]);
if (append == 0 && table.rows[i].cells[j].rowSpan != '2') {
if (j != 0) {
arr.push([j - 1]);
arr[arr.length - 1].push('-');
} else arr.push([j]);
}
if (table.rows[i].cells[j].innerText != '') {
let line = table.rows[i].cells[j].innerText
.replace('"', '')
.replace(String.fromCharCode(160), '')
.split(String.fromCharCode(160));
for (k = 0; k < line.length; k++) {
let str = line[k];
if (str[0] == ' ') str = str.substr(1);
if (str != '') arr[arr.length - 1].push(str);
}
}
append = 1;
}
}
}
navigator.clipboard.writeText(JSON.stringify(arr));
let element = document.getElementById('data');
element.innerHTML = "The JSON array is copied to the clipboard. Now just paste it into a regular .txt file (Ctrl+V) and save it. Then open this file using the Python script.";
}
function createArrayBuild17Oriented() {
let arr = [];
let table = document.getElementsByClassName('xl9132247')[0];
let count = 0;
for (var i = 0; i < table.rows.length; i++) {
append = 0;
for (var j = 0; j < table.rows[i].cells.length - 2; j++) {
if (table.rows[i].className != 'xl10532247') break;
if (table.rows[i].cells[j].innerHTML != ' ') {
if (
append == 0 &&
isFirstCharacterEnglishLetter(table.rows[i].cells[j].innerText)
)
arr.push([j]);
if (
append == 0 &&
!isFirstCharacterEnglishLetter(
table.rows[i].cells[j].innerText
)
) {
arr.push([j - 1]);
arr[arr.length - 1].push('-');
}
if (table.rows[i].cells[j].innerText != '') {
let line = table.rows[i].cells[j].innerText
.replace('"', '')
.replace(String.fromCharCode(160), '')
.split(String.fromCharCode(160));
for (k = 0; k < line.length; k++) {
let str = line[k];
if (str[0] == ' ') str = str.substr(1);
if (str != '') arr[arr.length - 1].push(str);
}
}
append = 1;
}
}
}
navigator.clipboard.writeText(JSON.stringify(arr));
let element = document.getElementById('data');
element.innerHTML =
'The JSON array is copied to the clipboard. Now just paste it into a regular .txt file (Ctrl+V) and save it. Then open this file using the Python script.';
}
// Add event listener to the file input
document
.getElementById('file-input')
.addEventListener('change', readSingleFile, false);
};
</script>
<style type="text/css">
.all_in_all {
width: 100%;
height: 100vh;
display:
flex;
justify-content:
center;
align-items:
center;
flex-direction:
column;
}
.button {
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
-khtml-border-radius: 50px;
border-radius: 50px;
background-color:
#007d3a;
color:
#ffffff;
font-family:
sans-serif;
padding: 20px;
}
#data {
font-family:
sans-serif;
}
.radio-group {
margin-bottom: 20px;
}
.radio-group label {
margin-right: 10px;
font-family:
sans-serif;
}
</style>
<body>
<div class="all_in_all">
<!-- Radio buttons to choose the function -->
<div class="radio-group">
<label>
<input type="radio" name="functionChoice" value="build17" checked />
For Build17
</label>
<label>
<input
type="radio"
name="functionChoice"
value="build17Oriented"
/>
For Build17 rCRS-oriented
</label>
</div>
<!-- File input and display content -->
<label for="file-input" class="button">Choose file</label>
<input type="file" id="file-input" style="visibility: hidden" />
<div id="data"></div>
</div>
</body>
</html>