-
Notifications
You must be signed in to change notification settings - Fork 18
/
htmlCompare.js
326 lines (296 loc) · 13 KB
/
htmlCompare.js
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
const fs = require("fs");
const ConstantsCompare = require("./htmlConstantsCompare.js");
let newRawDataCompare = ConstantsCompare.rawData;
// let defaultTemp = "celsius";
// let defaultPunc = "comma";
const writeFile = (lang, langValues, page, punc, defaultHead, metaTags, defaultNav, nav4, defaultFooter) => {
let writeStream = fs.createWriteStream(lang + "/" + page + ".html");
defaultHead.forEach((heads) => {
writeStream.write(heads);
});
metaTags.forEach((tags) => {
writeStream.write(tags);
});
defaultNav.forEach((navs) => {
writeStream.write(navs);
});
writeStream.write("<h1 class='truncate'>" + langValues[page] + "</h1>");
nav4.forEach((navs) => {
writeStream.write(navs);
});
function getNum(value) {
if (punc === "comma") value = value.toString().replace(/\./g, ",");
if (lang === "ar") {
// Arabic
value = value.toString().replace(/\./g, "٫");
var id = ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"];
return value.toString().replace(/[0-9]/g, function (w) {
return id[+w];
});
} else if (lang === "fa") {
// Persian
value = value.toString().replace(/\./g, "٫");
var id = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"];
return value.toString().replace(/[0-9]/g, function (w) {
return id[+w];
});
} else return value;
}
function getTemp(tempValue) {
var newTemp;
if (tempValue == "-") newTemp = "-";
else {
if (lang === "ar" || lang === "fa" || lang === "he")
newTemp =
getNum(Math.round((tempValue + 273.15) * 100) / 100) +
" K " +
getNum(tempValue) +
" | °C " +
getNum(Math.round((tempValue * 1.8 + 32) * 100) / 100) +
" °F";
else
newTemp =
Math.round((tempValue + 273.15) * 100) / 100 + " K | " + tempValue + " °C | " + Math.round((tempValue * 1.8 + 32) * 100) / 100 + " °F";
}
if (punc === "comma") newTemp = newTemp.replace(/\./g, ",");
return newTemp;
}
newRawDataCompare.sort(function (a, b) {
if (langValues[a.nme] < langValues[b.nme]) return -1;
else if (langValues[a.nme] > langValues[b.nme]) return 1;
return 0;
});
writeStream.write("<div class='content-wrapper'>");
writeStream.write("<div class='container'>");
writeStream.write("<div class='row'>");
writeStream.write("<div id='compareBg' class='box-content'>");
writeStream.write("<div id='topRowCompare'>");
writeStream.write("<div id='compareTop' class='square'>");
writeStream.write("<div></div>");
writeStream.write("<div>");
// writeStream.write("<select aria-label='First Element' bind:value={firstElement} on:change={() => (firstEle = getElement(firstElement))}>");
writeStream.write("<select id='firstElement' class='select-css' onchange='firstChanged()' aria-label='First Element'>");
newRawDataCompare.forEach((ele) => {
writeStream.write(" <option value=" + ele.id + ">" + langValues[ele.nme] + "</option>");
});
writeStream.write("</select>");
writeStream.write("</div>");
// writeStream.write("</div>");
writeStream.write("<div>");
// writeStream.write("<select aria-label='Second Element' bind:value={secondElement} on:change={() => (secondEle = getElement(secondElement))}>");
writeStream.write("<select id='secondElement' class='select-css' onchange='secondChanged()' aria-label='Second Element'>");
newRawDataCompare.forEach((ele) => {
writeStream.write(" <option value=" + ele.id + ">" + langValues[ele.nme] + "</option>");
});
writeStream.write("</select>");
writeStream.write("</div>");
writeStream.write("</div>");
writeStream.write("</div>");
writeStream.write("<div id='mainCompare'>");
let element = newRawDataCompare[0];
// writeStream.write("<div class='row'>");
writeStream.write("<div class='grayText'>" + langValues.labelName + "</div>");
writeStream.write("<a id='compEle1' href='element-" + element.num + "'>");
writeStream.write("<div class='compareLink'><span id='name1' class='underlineLink'>" + langValues[element.nme] + "</span></div>");
writeStream.write("</a>");
writeStream.write("<a id='compEle2' href='element-" + element.num + "'>");
writeStream.write("<div class='compareLink'><span id='name2' class='underlineLink'>" + langValues[element.nme] + "</span></div>");
writeStream.write("</a>");
// writeStream.write("</div>");
let compare1Links = [
{ label: "labelSymbol", id: "symbol", value: element.sym },
{ label: "labelAtmNoMain", id: "atmNo", value: getNum(element.num) },
{ label: "group", id: "groups", value: element.grp === "na" ? langValues.na : getNum(element.grp) },
{ label: "period", id: "periods", value: getNum(element.prd) },
{ label: "block", id: "block", value: element.blk },
{ label: "labelCrustMain", id: "crust", value: element.crt === "na" ? langValues.na : getNum(element.crt) },
{ label: "labelUniverseMain", id: "universe", value: element.uni === "na" ? langValues.na : getNum(element.uni) },
];
compare1Links.forEach((compareLink) => {
// writeStream.write("<div class='row'>");
writeStream.write("<div class='grayText'>" + langValues[compareLink.label] + "</div>");
writeStream.write("<div id='" + compareLink.id + "1'>" + compareLink.value + "</div>");
writeStream.write("<div id='" + compareLink.id + "2'>" + compareLink.value + "</div>");
// writeStream.write("</div>");
});
writeStream.write("<div class='span-3 pt-8'>");
writeStream.write("<div class='headerOutline text-upper'>" + langValues.labelGeneralProp + "</div>");
writeStream.write("</div>");
let compare2Links = [
{ label: "labelAtmWtMain", id: "atmWeight", value: getNum(element.aWt) },
{ label: "labelCategoryMain", id: "category", value: langValues[element.ctg] },
{ label: "labelColorMain", id: "eleColor", value: langValues[element.clr] },
{ label: "labelRadioMain", id: "radioactive", value: langValues[element.rdo] },
{ label: "labelStructureMain", id: "structure", value: langValues[element.stc] },
];
compare2Links.forEach((compareLink) => {
// writeStream.write("<div class='row'>");
writeStream.write("<div class='grayText'>" + langValues[compareLink.label] + "</div>");
writeStream.write("<div id='" + compareLink.id + "1'>" + compareLink.value + "</div>");
writeStream.write("<div id='" + compareLink.id + "2'>" + compareLink.value + "</div>");
// writeStream.write("</div>");
});
writeStream.write("<div class='span-3 pt-8'>");
writeStream.write("<div class='headerOutline text-upper'>" + langValues.labelPhysicalProp + "</div>");
writeStream.write("</div>");
let compare3Links = [
{ label: langValues["labelDensityMain"] + " (" + langValues["labelDensity"] + ")", id: "density", value: getNum(element.dns) },
{ label: langValues["labelPhaseMain"], id: "phase", value: langValues[element.phs] },
{ label: langValues["labelMeltingMain"], id: "meltPoint", value: getTemp(element.mlt) },
{ label: langValues["labelBoilingMain"], id: "boilPoint", value: getTemp(element.bln) },
{
label: langValues["labelFusionMain"] + " (" + langValues["labelFusion"] + ")",
id: "fusion",
value: element.fsn === "na" ? langValues.na : getNum(element.fsn),
},
{
label: langValues["labelVaporizationMain"] + " (" + langValues["labelFusion"] + ")",
id: "vaporization",
value: element.vpn === "na" ? langValues.na : getNum(element.vpn),
},
{ label: langValues["labelSpecificMain"] + " (" + langValues["labelSpecific"] + ")", id: "spHeat", value: getNum(element.spc) },
];
compare3Links.forEach((compareLink) => {
// writeStream.write("<div class='row'>");
writeStream.write("<div class='grayText'>" + compareLink.label + "</div>");
if (compareLink.id === "meltPoint")
writeStream.write("<div id='" + compareLink.id + "1'><div id='outputMeltingMain'>" + compareLink.value + "</div></div>");
else if (compareLink.id === "boilPoint")
writeStream.write("<div id='" + compareLink.id + "1'><div id='outputBoilingMain'>" + compareLink.value + "</div></div>");
else writeStream.write("<div id='" + compareLink.id + "1'>" + compareLink.value + "</div>");
writeStream.write("<div id='" + compareLink.id + "2'>" + compareLink.value + "</div>");
// writeStream.write("</div>");
});
writeStream.write("<div class='span-3 pt-8'>");
writeStream.write("<div class='headerOutline text-upper'>" + langValues.labelAtomicProp + "</div>");
writeStream.write("</div>");
let compare4Links = [
{ label: langValues["labelRadiusMain"], id: "atmRadius", value: element.aRd === "-" ? "-" : getNum(element.aRd) + " pm" },
{ label: langValues["labelCovalentMain"], id: "covRadius", value: element.cRd === "-" ? "-" : getNum(element.cRd) + " pm" },
{ label: langValues["labelElectronegativityMain"] + " (" + langValues["pauling"] + ")", id: "eleNeg", value: getNum(element.eNg) },
{ label: langValues["labelIonizationMain"] + " (" + langValues["labelIonization"] + ")", id: "ionization", value: getNum(element.ion) },
{ label: langValues["labelVolumeMain"] + " (" + langValues["labelVolume"] + ")", id: "volume", value: getNum(element.vol) },
{ label: langValues["labelThermalMain"] + " (" + langValues["labelThermal"] + ")", id: "theCond", value: getNum(element.trm) },
{ label: langValues["labelOxidationMain"], id: "oxidation", value: getNum(element.oxi) },
{ label: langValues["labelConfigMain"], id: "elecConfig", value: element.cnf },
{ label: langValues["labelElectronsMain"], id: "electrons", value: getNum(element.elc) },
];
compare4Links.forEach((compareLink) => {
// writeStream.write("<div class='row'>");
writeStream.write("<div class='grayText'>" + compareLink.label + "</div>");
writeStream.write("<div id='" + compareLink.id + "1'>" + compareLink.value + "</div>");
writeStream.write("<div id='" + compareLink.id + "2'>" + compareLink.value + "</div>");
// writeStream.write("</div>");
});
writeStream.write("</div>");
writeStream.write("</div>");
writeStream.write("</div>");
writeStream.write("</div>");
writeStream.write("</div>");
defaultFooter.forEach((footers) => {
writeStream.write(footers);
});
writeStream.write("<script>");
writeStream.write(
"let colorsList = {colorLess: '" +
langValues["colorLess"] +
"', colorSilver: '" +
langValues["colorSilver"] +
"', colorGold: '" +
langValues["colorGold"] +
"', colorRed: '" +
langValues["colorRed"] +
"', colorCopper: '" +
langValues["colorCopper"] +
"', colorBlack: '" +
langValues["colorBlack"] +
"', colorYellow: '" +
langValues["colorYellow"] +
"', colorSlateGray: '" +
langValues["colorSlateGray"] +
"', colorGray: '" +
langValues["colorGray"] +
"', na: '" +
langValues["na"] +
"'};"
);
writeStream.write(
"let structureList = {crystalSH: '" +
langValues["crystalSH"] +
"', crystalFCC: '" +
langValues["crystalFCC"] +
"', crystalBCC: '" +
langValues["crystalBCC"] +
"', crystalBCM: '" +
langValues["crystalBCM"] +
"', crystalFCO: '" +
langValues["crystalFCO"] +
"', crystalBCO: '" +
langValues["crystalBCO"] +
"', crystalSTG: '" +
langValues["crystalSTG"] +
"', crystalTP: '" +
langValues["crystalTP"] +
"', crystalSTC: '" +
langValues["crystalSTC"] +
"', crystalSC: '" +
langValues["crystalSC"] +
"', crystalSO: '" +
langValues["crystalSO"] +
"', crystalSM: '" +
langValues["crystalSM"] +
"', crystalCT: '" +
langValues["crystalCT"] +
"', na: '" +
langValues["na"] +
"'};"
);
writeStream.write(
"let categoriesList = {cat1: '" +
langValues["cat1"] +
"', cat2: '" +
langValues["cat2"] +
"', cat3: '" +
langValues["cat3"] +
"', cat4: '" +
langValues["cat4"] +
"', cat5: '" +
langValues["cat5"] +
"', cat6: '" +
langValues["cat6"] +
"', cat7: '" +
langValues["cat7"] +
"', cat8: '" +
langValues["cat8"] +
"', lanthanides: '" +
langValues["lanthanides"] +
"', actinides: '" +
langValues["actinides"] +
"', na: '" +
langValues["na"] +
"'};"
);
writeStream.write(
"let phaseList = {phaseGas: '" +
langValues["phaseGas"] +
"', phaseSolid: '" +
langValues["phaseSolid"] +
"', phaseLiquid: '" +
langValues["phaseLiquid"] +
"', unknown: '" +
langValues["unknown"] +
"', na: '" +
langValues["na"] +
"'};"
);
writeStream.write("let radioactiveList = {yes: '" + langValues["yes"] + "', no: '" + langValues["no"] + "', na: '" + langValues["na"] + "'};");
writeStream.write("let na= '" + langValues["na"] + "';");
writeStream.write("</script>");
// the finish event is emitted when all data has been flushed from the stream
writeStream.on("finish", () => {
console.log("Created " + lang + "-" + page);
});
// close the stream
writeStream.end();
};
exports.writeFile = writeFile;