From 5eec0c02136f27447d2cbe7a94b08d7b14d43a0a Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 23 Nov 2024 03:40:12 +0800 Subject: [PATCH] WebUI: use idiomatic string methods --- src/webui/www/private/scripts/client.js | 2 +- src/webui/www/private/scripts/misc.js | 6 +++--- src/webui/www/private/scripts/prop-trackers.js | 2 +- src/webui/www/private/views/log.html | 8 ++++---- src/webui/www/private/views/preferences.html | 2 +- src/webui/www/private/views/rssDownloader.html | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index bf6a9cea7..70381f547 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -1492,7 +1492,7 @@ window.addEventListener("DOMContentLoaded", () => { const handleDownloadParam = () => { // Extract torrent URL from download param in WebUI URL hash const downloadHash = "#download="; - if (location.hash.indexOf(downloadHash) !== 0) + if (!location.hash.startsWith(downloadHash)) return; const url = decodeURIComponent(location.hash.substring(downloadHash.length)); diff --git a/src/webui/www/private/scripts/misc.js b/src/webui/www/private/scripts/misc.js index 94f0eebcf..6313adfe2 100644 --- a/src/webui/www/private/scripts/misc.js +++ b/src/webui/www/private/scripts/misc.js @@ -255,8 +255,8 @@ window.qBittorrent.Misc ??= (() => { const containsAllTerms = (text, terms) => { const textToSearch = text.toLowerCase(); return terms.every((term) => { - const isTermRequired = (term[0] === "+"); - const isTermExcluded = (term[0] === "-"); + const isTermRequired = term.startsWith("+"); + const isTermExcluded = term.startsWith("-"); if (isTermRequired || isTermExcluded) { // ignore lonely +/- if (term.length === 1) @@ -265,7 +265,7 @@ window.qBittorrent.Misc ??= (() => { term = term.substring(1); } - const textContainsTerm = (textToSearch.indexOf(term) !== -1); + const textContainsTerm = textToSearch.includes(term); return isTermExcluded ? !textContainsTerm : textContainsTerm; }); }; diff --git a/src/webui/www/private/scripts/prop-trackers.js b/src/webui/www/private/scripts/prop-trackers.js index 44bba126c..ab9cec75b 100644 --- a/src/webui/www/private/scripts/prop-trackers.js +++ b/src/webui/www/private/scripts/prop-trackers.js @@ -146,7 +146,7 @@ window.qBittorrent.PropTrackers ??= (() => { onShow: function() { const selectedTrackers = torrentTrackersTable.selectedRowsIds(); const containsStaticTracker = selectedTrackers.some((tracker) => { - return (tracker.indexOf("** [") === 0); + return tracker.startsWith("** ["); }); if (containsStaticTracker || (selectedTrackers.length === 0)) { diff --git a/src/webui/www/private/views/log.html b/src/webui/www/private/views/log.html index c88da6ac8..dc757dbe8 100644 --- a/src/webui/www/private/views/log.html +++ b/src/webui/www/private/views/log.html @@ -343,10 +343,10 @@ if (curTab === "main") { url = new URI("api/v2/log/main"); url.setData({ - normal: selectedLogLevels.indexOf("1") !== -1, - info: selectedLogLevels.indexOf("2") !== -1, - warning: selectedLogLevels.indexOf("4") !== -1, - critical: selectedLogLevels.indexOf("8") !== -1 + normal: selectedLogLevels.includes("1"), + info: selectedLogLevels.includes("2"), + warning: selectedLogLevels.includes("4"), + critical: selectedLogLevels.includes("8") }); } else { diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index b1fee4bf7..7c21a7675 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -2138,7 +2138,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD languages.push($("locale_select").options[i].value); if (!languages.includes(selected)) { - const lang = selected.slice(0, selected.indexOf("_")); + const lang = selected.split("_", 1)[0]; selected = languages.includes(lang) ? lang : "en"; } $("locale_select").value = selected; diff --git a/src/webui/www/private/views/rssDownloader.html b/src/webui/www/private/views/rssDownloader.html index 243915902..d644fe0dc 100644 --- a/src/webui/www/private/views/rssDownloader.html +++ b/src/webui/www/private/views/rssDownloader.html @@ -388,7 +388,7 @@ Supports the formats: S01E01, 1x1, 2017.12.31 and 31.12.2017 (Date formats also $("rssDownloaderFeeds").style.height = "calc(100% - " + centerRowNotTableHeight + "px)"; // firefox calculates the height of the table inside fieldset differently and thus doesn't need the offset - if (navigator.userAgent.toLowerCase().indexOf("firefox") > -1) { + if (navigator.userAgent.toLowerCase().includes("firefox")) { $("rssDownloaderFeedsTable").style.height = "100%"; } else {