-
Notifications
You must be signed in to change notification settings - Fork 0
/
elements.js
139 lines (121 loc) · 3.4 KB
/
elements.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
function find_el() {
var cola = document.getElementById("cola");
var colb = document.getElementById("colb");
var result = document.getElementById("result");
var msg = document.getElementById("msg");
var rea = document.getElementById("rea");
var reb = document.getElementById("reb");
var a_lines = cola.value.split("\n");
var b_lines = colb.value.split("\n");
var a_values = [];
var b_matches = [];
for (i = 0; i < a_lines.length; i++) {
l = a_lines[i];
re = new RegExp(rea.value);
m = l.match(re);
if (m != null) {
if (m[1]) {
a_values.push(m[1]);
} else {
a_values.push(m[0]);
}
}
}
for (i = 0; i < b_lines.length; i++) {
l = b_lines[i];
re = new RegExp(reb.value);
m = l.match(re);
if (m != null) {
if (m[1]) {
for (j = 0; j < a_values.length; j++) {
key = a_values[j];
if (m[1] == key) {
b_matches.push(l);
}
}
} else {
for (j = 0; j < a_values.length; j++) {
key = a_values[j];
if (m[0] == key) {
b_matches.push(l);
}
}
}
}
}
result.value = uniq(b_matches).join("\n");
msg.style.display = "";
msg.innerHTML = "<p>Total number of matches found: " + uniq(b_matches).length + "</p>";
}
function uniq(a) {
tmp = new Array(0);
for(i=0;i<a.length;i++) {
if(!contains(tmp, a[i])) {
tmp.length+=1;
tmp[tmp.length-1]=a[i];
}
}
return tmp;
}
function contains(a, e) {
for(j=0;j<a.length;j++)if(a[j]==e)return true;
return false;
}
function toggle_options() {
options = document.getElementById("options_div");
if (options.style.display != "none") {
options.style.display = "none";
} else {
options.style.display = "";
}
}
function dict_lookup() {
var cola = document.getElementById("cola");
var colb = document.getElementById("colb");
var result = document.getElementById("result");
var msg = document.getElementById("msg");
var listd = document.getElementById("listd").value;
var outd = document.getElementById("outd").value;
var a_lines = cola.value.split("\n");
var b_lines = colb.value.split("\n");
var a_values = [];
var b_matches = [];
collector = colb.value;
result.value = "";
for (i = 0; i < a_lines.length; i++) {
l = a_lines[i];
re = new RegExp("(.*)" + listd + "(.*)");
m = l.match(re);
if (m == null) {
continue;
}
if (outd == "\\t") {
outd = "\t";
}
if (m.length == 3) {
test1 = m[1];
test2 = m[2];
result_regex = new RegExp("^" + test1 + "$", "gm");
collector = collector.replace(result_regex, test1 + outd + test2);
}
}
result.value = collector;
}
function toggle_mode() {
if (window.dictmode.checked) {
window.cola.setAttribute("onkeyup", "dict_lookup()");
window.colb.setAttribute("onkeyup", "dict_lookup()");
window.findbtn.setAttribute("onclick", "dict_lookup()");
window.findbtn.value = "Find matching items from list";
window.regopts.style.display = "none";
window.msg.style.display = "none";
window.dictopts.style.display = "";
} else {
window.cola.setAttribute("onkeyup", "find_el()");
window.colb.setAttribute("onkeyup", "find_el()");
window.findbtn.setAttribute("onclick", "find_el()");
window.dictopts.style.display = "none";
window.regopts.style.display = "";
window.msg.style.display = "";
}
}