Use for...of in more places

Signed-off-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
XhmikosR
2025-04-03 09:13:21 +03:00
parent 408334380e
commit 44226e1bec
5 changed files with 20 additions and 27 deletions
+4 -4
View File
@@ -76,16 +76,16 @@ function parseLines(ta, str) {
// Splitting the text on "\r"
const lines = str.split(/(?=\r)/g);
for (let i = 0; i < lines.length; i++) {
if (lines[i][0] === "\r") {
for (let line of lines) {
if (line[0] === "\r") {
// This line starts with the "OVER" sequence. Replace them with "\n" before print
lines[i] = lines[i].replaceAll("\r", "\n").replaceAll("\r", "\n");
line = line.replaceAll("\r", "\n").replaceAll("\r", "\n");
// Last line from the textarea will be overwritten, so we remove it
ta.text(ta.text().substring(0, ta.text().lastIndexOf("\n")));
}
// Append the new text to the end of the output
ta.append(lines[i]);
ta.append(line);
}
}
+5 -10
View File
@@ -29,8 +29,7 @@ function reloadClientSuggestions() {
sel.append($("<option />"));
// Add data obtained from API
for (let i = 0; i < data.clients.length; i++) {
const client = data.clients[i];
for (const client of data.clients) {
let mockDevice = false;
let text = client.hwaddr.toUpperCase();
let key = text;
@@ -370,15 +369,11 @@ function addClient() {
// - IPv6 address (with and without CIDR)
// - MAC address (in the form AA:BB:CC:DD:EE:FF)
// - host name (arbitrary form, we're only checking against some reserved characters)
for (let i = 0; i < ips.length; i++) {
if (
utils.validateIPv4CIDR(ips[i]) ||
utils.validateIPv6CIDR(ips[i]) ||
utils.validateMAC(ips[i])
) {
for (const [index, ip] of ips.entries()) {
if (utils.validateIPv4CIDR(ip) || utils.validateIPv6CIDR(ip) || utils.validateMAC(ip)) {
// Convert input to upper case (important for MAC addresses)
ips[i] = ips[i].toUpperCase();
} else if (!utils.validateHostname(ips[i])) {
ips[index] = ip.toUpperCase();
} else if (!utils.validateHostname(ip)) {
utils.showAlert(
"warning",
"",
+3 -3
View File
@@ -503,12 +503,12 @@ function addDomain() {
// Check if the wildcard checkbox was marked and transform the domains into regex
if (kind === "exact" && wildcardChecked) {
for (let i = 0; i < domains.length; i++) {
for (const [index, domain] of domains.entries()) {
// Strip leading "*." if specified by user in wildcard mode
if (domains[i].startsWith("*.")) domains[i] = domains[i].substr(2);
if (domain.startsWith("*.")) domains[index] = domain.substr(2);
// Transform domain into a wildcard regex
domains[i] = "(\\.|^)" + domains[i].replaceAll(".", "\\.") + "$";
domains[index] = "(\\.|^)" + domains[index].replaceAll(".", "\\.") + "$";
}
kind = "regex";
+6 -8
View File
@@ -96,7 +96,6 @@ $(() => {
tableApi = $("#network-entries").DataTable({
rowCallback(row, data) {
let color;
let index;
let iconClasses;
const lastQuery = Number.parseInt(data.lastQuery, 10);
const diff = getTimestamp() - lastQuery;
@@ -153,19 +152,18 @@ $(() => {
return a.ip.localeCompare(b.ip);
});
for (index = 0; index < data.ips.length; index++) {
const ip = data.ips[index];
let iptext = ip.ip;
for (const { ip, name } of data.ips) {
let iptext = ip;
if (ip.name !== null && ip.name.length > 0) {
iptext = iptext + " (" + ip.name + ")";
if (name !== null && name.length > 0) {
iptext = `${iptext} (${name})`;
}
iptitles.push(iptext);
// Only add IPs to the table if we have not reached the maximum
if (index < MAXIPDISPLAY) {
ips.push('<a href="queries?client_ip=' + ip.ip + '">' + iptext + "</a>");
if (ips.length < MAXIPDISPLAY) {
ips.push(`<a href="queries?client_ip=${ip}">${iptext}</a>`);
}
}
+2 -2
View File
@@ -59,8 +59,8 @@ function importZIP() {
$("#modal-import-success").show();
$("#modal-import-success-title").text("Import successful");
let text = "<p>Processed files:</p><ul>";
for (let i = 0; i < data.files.length; i++) {
text += "<li>" + utils.escapeHtml(data.files[i]) + "</li>";
for (const file of data.files) {
text += "<li>" + utils.escapeHtml(file) + "</li>";
}
text += "</ul>";