-
Notifications
You must be signed in to change notification settings - Fork 0
/
segment_search.js
128 lines (104 loc) · 3.85 KB
/
segment_search.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
// Segment Search
console.log("Segment Search Content Script");
document.addEventListener("searchSegments", function(e) {
searchSegments(e);
});
if (currentUrl.includes("&btns=disable")) {
// Skip creating the buttons!
} else {
addButtonBar(document);
buttonBarStyle(document);
searchSegmentsButton(document);
}
const keys = ["ArrowUp", "ArrowRight", "ArrowDown", "ArrowLeft", "Control", "Shift"]
let highlighted = false;
function searchSegments(e) {
let key = e.keyUpEvent.key;
let eValue = e.keyUpEvent.target.value;
if (keys.includes(key)) {
//console.log(e.key, "skipped")
return
}
let textSearch = eValue.toLowerCase();
textSearch = textSearch.replace(/\s/gm, " ");
let textSearchLength = textSearch.length;
let segmentRows = document.getElementsByClassName("EDIDocumentTableRow");
if ((key == "Enter") && (eValue == '')) {
if (document.getElementById('whiz').style.display == "none") {
e.searchSegmentsBtn.style.display = "inherit";
} else {
e.searchSegmentsBtn.style.display = "none";
}
e.searchInput.style.display = "none";
e.searchlabel.style.display = "none";
} else {
if (textSearch[0] == "\\") {
let textSearchArray = textSearch.match(/^\\(...)\\(.*)/)
console.log("textSearchArray", textSearchArray, textSearch);
if ((textSearchArray != null) && (textSearchArray[2] != "")) {
for (var i = 0, row; row = segmentRows[i]; i++) {
console.log((row.childNodes[4].innerText.toUpperCase() == (textSearchArray[1].toUpperCase())));
if (row.childNodes[4].innerText.toUpperCase() == (textSearchArray[1].toUpperCase())) {
let compareText = row.innerText.toLowerCase()
compareText = compareText.replace(/\s/gm, " ");
if (compareText.includes(textSearchArray[2])) {
row.style.display = "";
} else {
row.style.display = "none";
}
} else {
//row.style.display = "none";
}
}
} else {
}
} else {
for (var i = 0, row; row = segmentRows[i]; i++) {
let compareText = row.innerText.toLowerCase()
compareText = compareText.replace(/\s/gm, " ");
compareText = compareText.replace(/\t/gm, ""); //..·.
compareText = compareText.replace(/\s?\s?\|\s?\s?·?/gm, "|");
compareText = compareText.replace(/\s?\s?\^\s?\s?·?/gm, "^");
console.log("compareText", compareText);
if (compareText.includes(textSearch)) {
row.style.display = "";
} else {
row.style.display = "none";
}
}
}
}
}
/*
function contractSegments() {
/*
let expandedSchema = document.getElementsByClassName("additionaltable")
//console.log("expandedSchema", expandedSchema);
let expandedSchemaLength = expandedSchema.length;
for (let i = expandedSchemaLength; i > 0; i--) {
//console.log("expandedSchema", i, expandedSchema[i-1]);
if (expandedSchema[i-1].childNodes[0].childNodes[0].childNodes[0].className == "searchSegment") {
//if (expandedSchema[i-1].childNodes[0].childNodes[0].childNodes[1].childNodes[1].value == "") {
//expandedSchema[i-1].remove();
//}
} else {
expandedSchema[i-1].remove();
}
}
}
/// Expands the contents of the given Table Row (requires the main table row, not the sub-table used to display the segment fields)
function expandRow(row) {
if (!row.innerText.includes())
//console.log("newExpansionTable", newExpansionTable);
//console.log("segmentTable1 ", segmentTable, segmentTable.childNodes[0].childNodes[0].childNodes.length);
if (segmentTable.childNodes.length < 2) {
}
}
// Add event listeners
let expansionElementClassnames = ["EDIDocumentTableExpandor", "EDIDocumentTableSegnum", "EDIDocumentTableSegid",]
// Add an event listener
document.addEventListener("addExpansion", function(e) {
//console.log("addExpasion Listener Triggered");
addExpansionListeners();
});
*/