From 7528e52a4ef0c5c6813d0d891c19dd67c00ea77b Mon Sep 17 00:00:00 2001 From: skomerko <168652295+skomerko@users.noreply.github.com> Date: Fri, 31 Jan 2025 21:35:13 +0100 Subject: [PATCH] apply review comments --- src/webui/www/private/scripts/client.js | 9 +++------ src/webui/www/private/scripts/contextmenu.js | 8 ++------ src/webui/www/private/scripts/dynamicTable.js | 18 +++--------------- src/webui/www/private/views/preferences.html | 6 ++---- src/webui/www/private/views/rss.html | 3 +-- 5 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index cd6d5a1a2..7fac8f415 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -491,8 +491,7 @@ window.addEventListener("DOMContentLoaded", () => { if (!categoryList) return; - for (const category of categoryList.querySelectorAll("li")) - category.destroy(); + [...categoryList.children].forEach((el) => { el.destroy(); }); const categoryItemTemplate = document.getElementById("categoryFilterItem"); @@ -613,8 +612,7 @@ window.addEventListener("DOMContentLoaded", () => { if (tagFilterList === null) return; - for (const tag of tagFilterList.querySelectorAll("li")) - tag.destroy(); + [...tagFilterList.children].forEach((el) => { el.destroy(); }); const tagItemTemplate = document.getElementById("tagFilterItem"); @@ -667,8 +665,7 @@ window.addEventListener("DOMContentLoaded", () => { if (trackerFilterList === null) return; - for (const tracker of trackerFilterList.querySelectorAll("li")) - tracker.destroy(); + [...trackerFilterList.children].forEach((el) => { el.destroy(); }); const trackerItemTemplate = document.getElementById("trackerFilterItem"); diff --git a/src/webui/www/private/scripts/contextmenu.js b/src/webui/www/private/scripts/contextmenu.js index 6adb93d72..542a8d057 100644 --- a/src/webui/www/private/scripts/contextmenu.js +++ b/src/webui/www/private/scripts/contextmenu.js @@ -478,8 +478,7 @@ window.qBittorrent.ContextMenu ??= (() => { updateCategoriesSubMenu(categories) { const contextCategoryList = $("contextCategoryList"); - for (const category of contextCategoryList.querySelectorAll("li")) - category.destroy(); + [...contextCategoryList.children].forEach((el) => { el.destroy(); }); const createMenuItem = (text, imgURL, clickFn) => { const anchor = document.createElement("a"); @@ -635,10 +634,7 @@ window.qBittorrent.ContextMenu ??= (() => { updateMenuItems() { const enabledColumnIndex = (text) => { const columns = document.querySelectorAll("#searchPluginsTableFixedHeaderRow th"); - for (let i = 0; i < columns.length; ++i) { - if (columns[i].textContent === "Enabled") - return i; - } + return Array.prototype.findIndex.call(columns, (column => column.textContent === "Enabled")); }; this.showItem("Enabled"); diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index 59800e010..f45ff51a3 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -819,11 +819,7 @@ window.qBittorrent.DynamicTable ??= (() => { }, getTrByRowId: function(rowId) { - for (const tr of this.getTrs()) { - if (tr.rowId === rowId) - return tr; - } - return null; + return Array.prototype.find.call(this.getTrs(), (tr => tr.rowId === rowId)); }, updateTable: function(fullUpdate = false) { @@ -943,11 +939,7 @@ window.qBittorrent.DynamicTable ??= (() => { }, selectNextRow: function() { - const visibleRows = []; - for (const tr of this.getTrs()) { - if (!tr.classList.contains("invisible") && (tr.style.display !== "none")) - visibleRows.push(tr); - } + const visibleRows = Array.prototype.filter.call(this.getTrs(), (tr => !tr.classList.contains("invisible") && (tr.style.display !== "none"))); const selectedRowId = this.getSelectedRowId(); let selectedIndex = -1; @@ -969,11 +961,7 @@ window.qBittorrent.DynamicTable ??= (() => { }, selectPreviousRow: function() { - const visibleRows = []; - for (const tr of this.getTrs()) { - if (!tr.classList.contains("invisible") && (tr.style.display !== "none")) - visibleRows.push(tr); - } + const visibleRows = Array.prototype.filter.call(this.getTrs(), (tr => !tr.classList.contains("invisible") && (tr.style.display !== "none"))); const selectedRowId = this.getSelectedRowId(); let selectedIndex = -1; diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index a8e27fc3a..78b2afa6a 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -2102,8 +2102,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD // Advanced Tab const updateNetworkInterfaces = (default_iface, default_iface_name) => { - for (const option of document.querySelectorAll("#networkInterface option")) - option.destroy(); + [...document.getElementById("networkInterface").children].forEach((el) => { el.destroy(); }); fetch("api/v2/app/networkInterfaceList", { method: "GET", @@ -2132,8 +2131,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD }; const updateInterfaceAddresses = (iface, default_addr) => { - for (const option of document.querySelectorAll("#optionalIPAddressToBind option")) - option.destroy(); + [...document.getElementById("optionalIPAddressToBind").children].forEach((el) => { el.destroy(); }); const url = new URL("api/v2/app/networkInterfaceAddressList", window.location); url.search = new URLSearchParams({ diff --git a/src/webui/www/private/views/rss.html b/src/webui/www/private/views/rss.html index 4e44ec534..e1aa96bf0 100644 --- a/src/webui/www/private/views/rss.html +++ b/src/webui/www/private/views/rss.html @@ -422,8 +422,7 @@ }; const clearDetails = () => { - for (const element of [...document.getElementById("rssDetailsView").children]) - element.destroy(); + [...document.getElementById("rssDetailsView").children].forEach((el) => { el.destroy(); }); }; const showDetails = (feedUid, articleID) => {