-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
277 lines (237 loc) · 10.2 KB
/
Copy pathscript.js
File metadata and controls
277 lines (237 loc) · 10.2 KB
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
(() => {
const table = document.querySelector("table");
if (!table) return alert("Table not found!");
const tbody = table.querySelector("tbody");
const rows = Array.from(tbody.querySelectorAll("tr"));
let sortState = { col: -1, dir: 1 };
const headers = ["Host", "Title", "Status Code", "Technologies"];
// Нормализация текста для сравнения
function normalizeText(text) {
return text.replace(/\s+/g, ' ').trim().toLowerCase();
}
const extractors = {
"Host": row => {
const element = row.querySelector("ul li:nth-child(1) a");
return normalizeText(element?.textContent || "");
},
"Title": row => {
const element = row.querySelector("ul li:nth-child(2) a");
return normalizeText(element?.textContent || "");
},
"Status Code": row => {
const element = row.querySelector("ul li:nth-child(3) a");
return normalizeText(element?.textContent || "");
},
"Technologies": row => {
const element = row.querySelector("ul li:nth-child(4) a");
const text = element?.textContent || "";
if (!text || text.trim() === '[]') return [];
return text.replace(/[\[\]]/g, "").split(/\s+/).map(t => normalizeText(t)).filter(Boolean);
}
};
// Храним оригинальные значения для отображения
const displayValues = {
"Host": new Map(),
"Status Code": new Map(),
"Technologies": new Map()
};
const filters = {
"Host": new Set(),
"Status Code": new Set(),
"Technologies": new Set()
};
const selectedFilters = {
"Host": new Set(),
"Status Code": new Set(),
"Technologies": new Set()
};
function initFilters() {
// Сначала собираем все значения
rows.forEach(row => {
const host = extractors["Host"](row);
const status = extractors["Status Code"](row);
const techs = extractors["Technologies"](row);
// Сохраняем оригинальные значения для отображения
if (host) {
const originalHost = row.querySelector("ul li:nth-child(1) a")?.textContent.trim() || "";
displayValues["Host"].set(host, originalHost);
filters["Host"].add(host);
}
if (status) {
const originalStatus = row.querySelector("ul li:nth-child(3) a")?.textContent.trim() || "";
displayValues["Status Code"].set(status, originalStatus);
filters["Status Code"].add(status);
}
techs.forEach(t => {
if (t) {
displayValues["Technologies"].set(t, t);
filters["Technologies"].add(t);
}
});
});
// Инициализируем выбранные фильтры
Object.entries(filters).forEach(([key, values]) => {
selectedFilters[key] = new Set(values);
});
}
function applyFilters() {
rows.forEach(row => {
const host = extractors["Host"](row);
const status = extractors["Status Code"](row);
const techs = extractors["Technologies"](row);
const hostMatch = selectedFilters["Host"].has(host);
const statusMatch = selectedFilters["Status Code"].has(status);
const techsMatch = techs.length === 0 || techs.some(t => selectedFilters["Technologies"].has(t));
row.style.display = (hostMatch && statusMatch && techsMatch) ? "" : "none";
});
}
function createCheckboxes(label, items, key) {
const wrapper = document.createElement("div");
wrapper.style.flex = "0 0 250px";
wrapper.style.marginRight = "10px";
wrapper.style.maxHeight = "180px";
wrapper.style.overflowY = "auto";
wrapper.style.fontSize = "12px";
wrapper.style.display = "flex";
wrapper.style.flexDirection = "column";
const title = document.createElement("div");
title.innerHTML = `<strong>${label}</strong>`;
title.style.marginBottom = "4px";
wrapper.appendChild(title);
const btnWrap = document.createElement("div");
btnWrap.style.marginBottom = "6px";
btnWrap.style.display = "flex";
btnWrap.style.gap = "4px";
const selectAll = document.createElement("button");
selectAll.textContent = "All";
selectAll.style.fontSize = "11px";
selectAll.style.padding = "1px 4px";
selectAll.addEventListener("click", () => {
wrapper.querySelectorAll("input[type=checkbox]").forEach(cb => {
cb.checked = true;
selectedFilters[key].add(normalizeText(cb.dataset.value));
});
applyFilters();
});
const deselectAll = document.createElement("button");
deselectAll.textContent = "None";
deselectAll.style.fontSize = "11px";
deselectAll.style.padding = "1px 4px";
deselectAll.addEventListener("click", () => {
wrapper.querySelectorAll("input[type=checkbox]").forEach(cb => {
cb.checked = false;
selectedFilters[key].delete(normalizeText(cb.dataset.value));
});
applyFilters();
});
btnWrap.appendChild(selectAll);
btnWrap.appendChild(deselectAll);
wrapper.appendChild(btnWrap);
// Используем Map для сортировки по оригинальным значениям
const sortedItems = Array.from(items)
.map(value => ({
normalized: value,
original: displayValues[key].get(value) || value
}))
.sort((a, b) => a.original.localeCompare(b.original));
sortedItems.forEach(({normalized, original}) => {
if (!normalized) return;
const id = `${key}-${normalized}`;
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.checked = true;
checkbox.id = id;
checkbox.dataset.value = normalized;
checkbox.style.marginRight = "4px";
checkbox.addEventListener("change", () => {
if (checkbox.checked) {
selectedFilters[key].add(normalized);
} else {
selectedFilters[key].delete(normalized);
}
applyFilters();
});
const labelEl = document.createElement("label");
labelEl.htmlFor = id;
labelEl.textContent = original;
labelEl.style.display = "flex";
labelEl.style.alignItems = "center";
labelEl.style.whiteSpace = "nowrap";
const line = document.createElement("div");
line.appendChild(checkbox);
line.appendChild(labelEl);
wrapper.appendChild(line);
});
return wrapper;
}
function getCellText(row, index) {
const ulItems = row.querySelectorAll("ul > li");
if (!ulItems[index]) return "";
const text = ulItems[index].textContent || "";
return normalizeText(text.replace(/^.*?:\s*/, ""));
}
function sortTableByColumn(colIndex) {
const dir = (sortState.col === colIndex) ? -sortState.dir : 1;
sortState = { col: colIndex, dir };
const sortedRows = [...rows].sort((a, b) => {
const aVal = getCellText(a, colIndex);
const bVal = getCellText(b, colIndex);
const aNum = parseFloat(aVal);
const bNum = parseFloat(bVal);
if (!isNaN(aNum) && !isNaN(bNum)) return (aNum - bNum) * dir;
return aVal.localeCompare(bVal) * dir;
});
sortedRows.forEach(row => tbody.appendChild(row));
}
initFilters();
// === Сортировка ===
const sortPanel = document.createElement("div");
sortPanel.style.position = "fixed";
sortPanel.style.top = "0";
sortPanel.style.right = "0";
sortPanel.style.width = "150px";
sortPanel.style.padding = "10px";
sortPanel.style.background = "#f9f9f9";
sortPanel.style.borderBottom = "2px solid #ccc";
sortPanel.style.borderLeft = "2px solid #ccc";
sortPanel.style.zIndex = "10000";
sortPanel.style.fontFamily = "sans-serif";
sortPanel.style.height = "200px";
const sortTitle = document.createElement("div");
sortTitle.innerHTML = `<strong>Sort by:</strong><br>`;
sortPanel.appendChild(sortTitle);
headers.forEach((name, idx) => {
const btn = document.createElement("button");
btn.textContent = name;
btn.style.margin = "4px 4px";
btn.style.padding = "4px 8px";
btn.style.border = "1px solid #888";
btn.style.borderRadius = "5px";
btn.style.cursor = "pointer";
btn.style.background = "#eee";
btn.addEventListener("click", () => sortTableByColumn(idx));
sortPanel.appendChild(btn);
});
document.body.appendChild(sortPanel);
// === Фильтры ===
const filterPanel = document.createElement("div");
filterPanel.style.position = "fixed";
filterPanel.style.top = "0";
filterPanel.style.left = "0";
filterPanel.style.right = "160px";
filterPanel.style.height = "200px";
filterPanel.style.display = "flex";
filterPanel.style.flexDirection = "row";
filterPanel.style.padding = "10px";
filterPanel.style.background = "#fff";
filterPanel.style.borderBottom = "2px solid #ccc";
filterPanel.style.borderRight = "2px solid #ccc";
filterPanel.style.zIndex = "10000";
filterPanel.style.fontFamily = "sans-serif";
filterPanel.style.overflowX = "auto";
filterPanel.appendChild(createCheckboxes("Host", filters["Host"], "Host"));
filterPanel.appendChild(createCheckboxes("Status Code", filters["Status Code"], "Status Code"));
filterPanel.appendChild(createCheckboxes("Technologies", filters["Technologies"], "Technologies"));
document.body.appendChild(filterPanel);
document.body.style.paddingTop = "250px";
})();