-
Notifications
You must be signed in to change notification settings - Fork 22
/
ignval.html
94 lines (76 loc) · 2.22 KB
/
ignval.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ignite Values Formatting</title>
<link rel="icon" href="img/leaf-icon-png-7066.png">
<script>
var storIdx = 'ignValData'; // Define friendly index name
function nl(t) {
var res = "<br>";
for (var j = 0; j < t; j++)
res += " ";
return res;
}
function doConvert() {
var value = document.getElementById("taInput").value;
var res = "";
var t = 0;
var ll = 0;
for (var i = 0; i < value.length; i++) {
var ch = value.charAt(i);
if (ch === "[") {
t++;
res += ch + nl(t);
ll=0;
continue;
}
if (ch === "]") {
t--;
res += nl(t) + ch;
ll=100;
continue;
}
if (ch === "\n") {
res += nl(t);
ll=0;
continue;
}
if(ch === "," && ll>2) {
res += ch+ nl(t);
ll=0;
continue;
}
res += ch;
ll++;
}
document.getElementById("divResult").innerHTML = res;
try {
window.sessionStorage.setItem(storIdx, value);
} catch (e) {}
}
function load() {
try {
// getter: Fetch previous value
var oldValue = window.sessionStorage.getItem(storIdx);
if (oldValue != null) {
document.getElementById("taInput").value = oldValue;
doConvert();
}
} catch (e) {
// getter: Always default to first tab in error state
var oldIndex = 0;
}
}
document.addEventListener("DOMContentLoaded", function(event) {
load();
});
</script>
</head>
<body>
<textarea rows="6" cols="150" id="taInput"></textarea><br>
<button onclick="doConvert()">Format</button>
<br>
<div id="divResult" style=" font-family: monospace;"></div>
</body>
</html>