From c622d50814f4fea5c4fbe13b9bde360dea60ec9b Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 12 Jan 2025 21:36:59 +0800 Subject: [PATCH] WebUI: use native API for accessing query string PR #22141. --- src/webui/www/private/addpeers.html | 4 +- src/webui/www/private/addtrackers.html | 2 +- src/webui/www/private/addwebseeds.html | 2 +- .../www/private/confirmfeeddeletion.html | 6 +- src/webui/www/private/confirmruleclear.html | 7 +- .../www/private/confirmruledeletion.html | 7 +- .../www/private/confirmtrackerdeletion.html | 9 +- src/webui/www/private/download.html | 11 +- src/webui/www/private/downloadlimit.html | 2 +- src/webui/www/private/editfeedurl.html | 5 +- src/webui/www/private/edittracker.html | 7 +- src/webui/www/private/editwebseed.html | 5 +- src/webui/www/private/newcategory.html | 9 +- src/webui/www/private/newfeed.html | 4 +- src/webui/www/private/newfolder.html | 4 +- src/webui/www/private/newtag.html | 10 +- src/webui/www/private/rename.html | 9 +- src/webui/www/private/rename_feed.html | 2 +- src/webui/www/private/rename_file.html | 7 +- src/webui/www/private/rename_rule.html | 2 +- src/webui/www/private/scripts/client.js | 9 +- src/webui/www/private/scripts/mocha-init.js | 319 +++++++++++------- src/webui/www/private/scripts/prop-peers.js | 8 +- src/webui/www/private/setlocation.html | 7 +- src/webui/www/private/shareratio.html | 6 +- src/webui/www/private/uploadlimit.html | 2 +- src/webui/www/private/views/log.html | 27 +- src/webui/www/private/views/rss.html | 7 +- 28 files changed, 294 insertions(+), 205 deletions(-) diff --git a/src/webui/www/private/addpeers.html b/src/webui/www/private/addpeers.html index 5ef01c2a4f0b..ad645b3d9e63 100644 --- a/src/webui/www/private/addpeers.html +++ b/src/webui/www/private/addpeers.html @@ -22,8 +22,8 @@ } }); - const hash = new URI().getData("hash"); - if (!hash) + const hash = new URLSearchParams(window.location.search).get("hash"); + if (hash === null) return; $("peers").focus(); diff --git a/src/webui/www/private/addtrackers.html b/src/webui/www/private/addtrackers.html index df84f1443998..818f20f09bcd 100644 --- a/src/webui/www/private/addtrackers.html +++ b/src/webui/www/private/addtrackers.html @@ -30,7 +30,7 @@ fetch("api/v2/torrents/addTrackers", { method: "POST", body: new URLSearchParams({ - hash: new URI().getData("hash"), + hash: new URLSearchParams(window.location.search).get("hash"), urls: $("trackersUrls").value }) }) diff --git a/src/webui/www/private/addwebseeds.html b/src/webui/www/private/addwebseeds.html index c03f7687bf92..c87c171467f9 100644 --- a/src/webui/www/private/addwebseeds.html +++ b/src/webui/www/private/addwebseeds.html @@ -29,7 +29,7 @@ fetch("api/v2/torrents/addWebSeeds", { method: "POST", body: new URLSearchParams({ - hash: new URI().getData("hash"), + hash: new URLSearchParams(window.location.search).get("hash"), urls: $("urls").value.split("\n").map(w => encodeURIComponent(w.trim())).filter(w => (w.length > 0)).join("|") }) }) diff --git a/src/webui/www/private/confirmfeeddeletion.html b/src/webui/www/private/confirmfeeddeletion.html index bfd19d661a94..b0f2abe5c6e5 100644 --- a/src/webui/www/private/confirmfeeddeletion.html +++ b/src/webui/www/private/confirmfeeddeletion.html @@ -13,7 +13,6 @@ "use strict"; window.addEventListener("DOMContentLoaded", () => { - const paths = new URI().getData("paths").split("|"); $("cancelBtn").focus(); $("cancelBtn").addEventListener("click", (e) => { e.preventDefault(); @@ -25,7 +24,8 @@ e.stopPropagation(); let completionCount = 0; - paths.forEach((path) => { + const paths = new URLSearchParams(window.location.search).get("paths").split("|"); + for (const path of paths) { fetch("api/v2/rss/removeItem", { method: "POST", body: new URLSearchParams({ @@ -42,7 +42,7 @@ window.parent.qBittorrent.Client.closeFrameWindow(window); } }); - }); + } }); }); diff --git a/src/webui/www/private/confirmruleclear.html b/src/webui/www/private/confirmruleclear.html index 8b562b2573e5..9817d3c1d25e 100644 --- a/src/webui/www/private/confirmruleclear.html +++ b/src/webui/www/private/confirmruleclear.html @@ -13,8 +13,6 @@ "use strict"; window.addEventListener("DOMContentLoaded", () => { - const rules = new URI().getData("rules").split("|"); - $("cancelBtn").focus(); $("cancelBtn").addEventListener("click", (e) => { e.preventDefault(); @@ -26,7 +24,8 @@ e.stopPropagation(); let completionCount = 0; - rules.forEach((rule) => { + const rules = new URLSearchParams(window.location.search).get("rules").split("|"); + for (const rule of rules) { window.parent.qBittorrent.RssDownloader.modifyRuleState(decodeURIComponent(rule), "previouslyMatchedEpisodes", [], () => { ++completionCount; if (completionCount === rules.length) { @@ -34,7 +33,7 @@ window.parent.qBittorrent.Client.closeFrameWindow(window); } }); - }); + } }); }); diff --git a/src/webui/www/private/confirmruledeletion.html b/src/webui/www/private/confirmruledeletion.html index b47608f00fb4..cf9f7d874916 100644 --- a/src/webui/www/private/confirmruledeletion.html +++ b/src/webui/www/private/confirmruledeletion.html @@ -13,8 +13,6 @@ "use strict"; window.addEventListener("DOMContentLoaded", () => { - const rules = new URI().getData("rules").split("|"); - $("cancelBtn").focus(); $("cancelBtn").addEventListener("click", (e) => { e.preventDefault(); @@ -26,7 +24,8 @@ e.stopPropagation(); let completionCount = 0; - rules.forEach((rule) => { + const rules = new URLSearchParams(window.location.search).get("rules").split("|"); + for (const rule of rules) { fetch("api/v2/rss/removeRule", { method: "POST", body: new URLSearchParams({ @@ -43,7 +42,7 @@ window.parent.qBittorrent.Client.closeFrameWindow(window); } }); - }); + } }); }); diff --git a/src/webui/www/private/confirmtrackerdeletion.html b/src/webui/www/private/confirmtrackerdeletion.html index ecf51b3f5e88..4324f528f51f 100644 --- a/src/webui/www/private/confirmtrackerdeletion.html +++ b/src/webui/www/private/confirmtrackerdeletion.html @@ -13,9 +13,10 @@ "use strict"; window.addEventListener("DOMContentLoaded", () => { - const host = new URI().getData("host"); - const urls = new URI().getData("urls"); - $("confirmDeleteTrackerText").textContent = "QBT_TR(Are you sure you want to remove tracker %1 from all torrents?)QBT_TR[CONTEXT=TrackersFilterWidget]".replace("%1", `"${host}"`); + const searchParams = new URLSearchParams(window.location.search); + const host = searchParams.get("host"); + + $("confirmDeleteTrackerText").textContent = "QBT_TR(Are you sure you want to remove tracker %1 from all torrents?)QBT_TR[CONTEXT=TrackersFilterWidget]".replace("%1", host); $("cancelBtn").focus(); $("cancelBtn").addEventListener("click", (e) => { @@ -29,7 +30,7 @@ method: "POST", body: new URLSearchParams({ hash: "*", - urls: urls + urls: searchParams.get("urls") }) }) .then((response) => { diff --git a/src/webui/www/private/download.html b/src/webui/www/private/download.html index 5f481a735f74..ecd1bb6bbb28 100644 --- a/src/webui/www/private/download.html +++ b/src/webui/www/private/download.html @@ -163,13 +163,10 @@