WebUI: use native API for accessing query string

This commit is contained in:
Chocobo1 2025-01-07 18:13:25 +08:00
commit 3f052cae14
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
28 changed files with 292 additions and 203 deletions

View file

@ -22,8 +22,8 @@
} }
}); });
const hash = new URI().getData("hash"); const hash = new URLSearchParams(window.location.search).get("hash");
if (!hash) if (hash === null)
return; return;
$("peers").focus(); $("peers").focus();

View file

@ -30,7 +30,7 @@
fetch("api/v2/torrents/addTrackers", { fetch("api/v2/torrents/addTrackers", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
hash: new URI().getData("hash"), hash: new URLSearchParams(window.location.search).get("hash"),
urls: $("trackersUrls").value urls: $("trackersUrls").value
}) })
}) })

View file

@ -29,7 +29,7 @@
fetch("api/v2/torrents/addWebSeeds", { fetch("api/v2/torrents/addWebSeeds", {
method: "POST", method: "POST",
body: new URLSearchParams({ 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("|") urls: $("urls").value.split("\n").map(w => encodeURIComponent(w.trim())).filter(w => (w.length > 0)).join("|")
}) })
}) })

View file

@ -13,7 +13,6 @@
"use strict"; "use strict";
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
const paths = new URI().getData("paths").split("|");
$("cancelBtn").focus(); $("cancelBtn").focus();
$("cancelBtn").addEventListener("click", (e) => { $("cancelBtn").addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
@ -25,7 +24,8 @@
e.stopPropagation(); e.stopPropagation();
let completionCount = 0; 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", { fetch("api/v2/rss/removeItem", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
@ -42,7 +42,7 @@
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} }
}); });
}); }
}); });
}); });
</script> </script>

View file

@ -13,8 +13,6 @@
"use strict"; "use strict";
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
const rules = new URI().getData("rules").split("|");
$("cancelBtn").focus(); $("cancelBtn").focus();
$("cancelBtn").addEventListener("click", (e) => { $("cancelBtn").addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
@ -26,7 +24,8 @@
e.stopPropagation(); e.stopPropagation();
let completionCount = 0; 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", [], () => { window.parent.qBittorrent.RssDownloader.modifyRuleState(decodeURIComponent(rule), "previouslyMatchedEpisodes", [], () => {
++completionCount; ++completionCount;
if (completionCount === rules.length) { if (completionCount === rules.length) {
@ -34,7 +33,7 @@
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} }
}); });
}); }
}); });
}); });
</script> </script>

View file

@ -13,8 +13,6 @@
"use strict"; "use strict";
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
const rules = new URI().getData("rules").split("|");
$("cancelBtn").focus(); $("cancelBtn").focus();
$("cancelBtn").addEventListener("click", (e) => { $("cancelBtn").addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
@ -26,7 +24,8 @@
e.stopPropagation(); e.stopPropagation();
let completionCount = 0; 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", { fetch("api/v2/rss/removeRule", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
@ -43,7 +42,7 @@
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
} }
}); });
}); }
}); });
}); });
</script> </script>

View file

@ -13,9 +13,10 @@
"use strict"; "use strict";
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
const host = new URI().getData("host"); const searchParams = new URLSearchParams(window.location.search);
const urls = new URI().getData("urls"); 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}"`);
$("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").focus();
$("cancelBtn").addEventListener("click", (e) => { $("cancelBtn").addEventListener("click", (e) => {
@ -29,7 +30,7 @@
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
hash: "*", hash: "*",
urls: urls urls: searchParams.get("urls")
}) })
}) })
.then((response) => { .then((response) => {

View file

@ -163,13 +163,10 @@
<script> <script>
"use strict"; "use strict";
const encodedUrls = new URI().getData("urls"); const encodedUrls = new URLSearchParams(window.location.search).get("urls");
if (encodedUrls) { if (encodedUrls !== null) {
const urls = encodedUrls.split("|").map((url) => { const urls = encodedUrls.split("|").map(decodeURIComponent);
return decodeURIComponent(url); if (urls.length > 0)
});
if (urls.length)
$("urls").value = urls.join("\n"); $("urls").value = urls.join("\n");
} }

View file

@ -46,7 +46,7 @@
} }
}); });
const hashes = new URI().getData("hashes").split("|"); const hashes = new URLSearchParams(window.location.search).get("hashes").split("|");
const setDlLimit = () => { const setDlLimit = () => {
const limit = Number($("dllimitUpdatevalue").value) * 1024; const limit = Number($("dllimitUpdatevalue").value) * 1024;
if (hashes[0] === "global") { if (hashes[0] === "global") {

View file

@ -27,7 +27,8 @@
} }
}); });
const currentUrl = new URI().getData("url"); const searchParams = new URLSearchParams(window.location.search);
const currentUrl = searchParams.get("url");
$("url").value = currentUrl; $("url").value = currentUrl;
$("url").focus(); $("url").focus();
@ -54,7 +55,7 @@
fetch("api/v2/rss/setFeedURL", { fetch("api/v2/rss/setFeedURL", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
path: new URI().getData("path"), path: searchParams.get("path"),
url: newUrl url: newUrl
}) })
}) })

View file

@ -26,8 +26,9 @@
} }
}); });
const currentUrl = new URI().getData("url"); const searchParams = new URLSearchParams(window.location.search);
if (!currentUrl) const currentUrl = searchParams.get("url");
if (currentUrl === null)
return; return;
$("trackerUrl").value = currentUrl; $("trackerUrl").value = currentUrl;
@ -40,7 +41,7 @@
fetch("api/v2/torrents/editTracker", { fetch("api/v2/torrents/editTracker", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
hash: new URI().getData("hash"), hash: searchParams.get("hash"),
origUrl: currentUrl, origUrl: currentUrl,
newUrl: $("trackerUrl").value newUrl: $("trackerUrl").value
}) })

View file

@ -26,7 +26,8 @@
} }
}); });
const origUrl = new URI().getData("url"); const searchParams = new URLSearchParams(window.location.search);
const origUrl = searchParams.get("url");
$("url").value = decodeURIComponent(origUrl); $("url").value = decodeURIComponent(origUrl);
$("url").focus(); $("url").focus();
@ -36,7 +37,7 @@
fetch("api/v2/torrents/editWebSeed", { fetch("api/v2/torrents/editWebSeed", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
hash: new URI().getData("hash"), hash: searchParams.get("hash"),
origUrl: origUrl, origUrl: origUrl,
newUrl: encodeURIComponent($("url").value.trim()) newUrl: encodeURIComponent($("url").value.trim())
}) })

View file

@ -28,10 +28,11 @@
} }
}); });
const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData("action")); const searchParams = new URLSearchParams(window.location.search);
const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData("hashes")); const uriAction = window.qBittorrent.Misc.safeTrim(searchParams.get("action"));
const uriCategoryName = window.qBittorrent.Misc.safeTrim(new URI().getData("categoryName")); const uriHashes = window.qBittorrent.Misc.safeTrim(searchParams.get("hashes"));
const uriSavePath = window.qBittorrent.Misc.safeTrim(new URI().getData("savePath")); const uriCategoryName = window.qBittorrent.Misc.safeTrim(searchParams.get("categoryName"));
const uriSavePath = window.qBittorrent.Misc.safeTrim(searchParams.get("savePath"));
if (uriAction === "edit") { if (uriAction === "edit") {
if (!uriCategoryName) if (!uriCategoryName)

View file

@ -28,7 +28,6 @@
}); });
$("feedURL").focus(); $("feedURL").focus();
const path = new URI().getData("path");
$("submitButton").addEventListener("click", (e) => { $("submitButton").addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
@ -42,11 +41,12 @@
$("submitButton").disabled = true; $("submitButton").disabled = true;
const path = new URLSearchParams(window.location.search).get("path");
fetch("api/v2/rss/addFeed", { fetch("api/v2/rss/addFeed", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
url: feedURL, url: feedURL,
path: path ? (path + "\\" + feedURL) : "" path: (((path !== null) && (path.length > 0)) ? `${path}\\${feedURL}` : "")
}) })
}) })
.then(async (response) => { .then(async (response) => {

View file

@ -29,7 +29,6 @@
}); });
$("folderName").focus(); $("folderName").focus();
const path = new URI().getData("path");
$("submitButton").addEventListener("click", (e) => { $("submitButton").addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
@ -43,10 +42,11 @@
$("submitButton").disabled = true; $("submitButton").disabled = true;
const path = new URLSearchParams(window.location.search).get("path");
fetch("api/v2/rss/addFolder", { fetch("api/v2/rss/addFolder", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
path: path ? (path + "\\" + folderName) : folderName path: (((path !== null) && (path.length > 0)) ? `${path}\\${folderName}` : folderName)
}) })
}) })
.then(async (response) => { .then(async (response) => {

View file

@ -27,8 +27,8 @@
} }
}); });
const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData("action")); const searchParams = new URLSearchParams(window.location.search);
const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData("hashes")); const uriAction = window.qBittorrent.Misc.safeTrim(searchParams.get("action"));
if (uriAction === "create") if (uriAction === "create")
$("legendText").textContent = "QBT_TR(Tag:)QBT_TR[CONTEXT=TagFilterWidget]"; $("legendText").textContent = "QBT_TR(Tag:)QBT_TR[CONTEXT=TagFilterWidget]";
@ -52,8 +52,9 @@
}; };
switch (uriAction) { switch (uriAction) {
case "set": case "set": {
if (uriHashes === "") const uriHashes = window.qBittorrent.Misc.safeTrim(searchParams.get("hashes"));
if ((uriHashes === null) || (uriHashes.length <= 0))
return; return;
fetch("api/v2/torrents/addTags", { fetch("api/v2/torrents/addTags", {
@ -70,6 +71,7 @@
window.parent.qBittorrent.Client.closeFrameWindow(window); window.parent.qBittorrent.Client.closeFrameWindow(window);
}); });
break; break;
}
case "create": case "create":
if (!verifyTagName(tagName)) if (!verifyTagName(tagName))

View file

@ -27,9 +27,10 @@
} }
}); });
const name = new URI().getData("name"); const searchParams = new URLSearchParams(window.location.search);
const name = searchParams.get("name");
// set text field to current value // set text field to current value
if (name) if (name !== null)
$("rename").value = name; $("rename").value = name;
$("rename").focus(); $("rename").focus();
@ -42,8 +43,8 @@
if ((name === null) || (name === "")) if ((name === null) || (name === ""))
return; return;
const hash = new URI().getData("hash"); const hash = searchParams.get("hash");
if (hash) { if (hash !== null) {
fetch("api/v2/torrents/rename", { fetch("api/v2/torrents/rename", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({

View file

@ -27,7 +27,7 @@
} }
}); });
const oldPath = new URI().getData("oldPath"); const oldPath = new URLSearchParams(window.location.search).get("oldPath");
$("rename").value = oldPath; $("rename").value = oldPath;
$("rename").focus(); $("rename").focus();

View file

@ -28,9 +28,10 @@
} }
}); });
const hash = new URI().getData("hash"); const searchParams = new URLSearchParams(window.location.search);
const oldPath = new URI().getData("path"); const hash = searchParams.get("hash");
const isFolder = ((new URI().getData("isFolder")) === "true"); const oldPath = searchParams.get("path");
const isFolder = ((searchParams.get("isFolder")) === "true");
const oldName = window.qBittorrent.Filesystem.fileName(oldPath); const oldName = window.qBittorrent.Filesystem.fileName(oldPath);
$("rename").value = oldName; $("rename").value = oldName;

View file

@ -27,7 +27,7 @@
} }
}); });
const oldName = new URI().getData("rule"); const oldName = new URLSearchParams(window.location.search).get("rule");
$("rename").value = oldName; $("rename").value = oldName;
$("rename").focus(); $("rename").focus();

View file

@ -1656,7 +1656,7 @@ window.addEventListener("DOMContentLoaded", () => {
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Upload local torrent)QBT_TR[CONTEXT=HttpServer]", title: "QBT_TR(Upload local torrent)QBT_TR[CONTEXT=HttpServer]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("upload.html").toString(), contentURL: "upload.html",
addClass: "windowFrame", // fixes iframe scrolling on iOS Safari addClass: "windowFrame", // fixes iframe scrolling on iOS Safari
scrollbars: true, scrollbars: true,
maximizable: false, maximizable: false,
@ -1693,13 +1693,16 @@ window.addEventListener("DOMContentLoaded", () => {
return; return;
const id = "downloadPage"; const id = "downloadPage";
const contentURI = new URI("download.html").setData("urls", urls.map(encodeURIComponent).join("|")); const contentURL = new URL("download.html", window.location);
contentURL.search = new URLSearchParams({
urls: urls.map(encodeURIComponent).join("|")
});
new MochaUI.Window({ new MochaUI.Window({
id: id, id: id,
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Download from URLs)QBT_TR[CONTEXT=downloadFromURL]", title: "QBT_TR(Download from URLs)QBT_TR[CONTEXT=downloadFromURL]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: contentURI.toString(), contentURL: contentURL.toString(),
addClass: "windowFrame", // fixes iframe scrolling on iOS Safari addClass: "windowFrame", // fixes iframe scrolling on iOS Safari
scrollbars: true, scrollbars: true,
maximizable: false, maximizable: false,

View file

@ -179,17 +179,20 @@ const initializeWindows = () => {
showDownloadPage = (urls) => { showDownloadPage = (urls) => {
const id = "downloadPage"; const id = "downloadPage";
const contentUri = new URI("download.html"); const contentURL = new URL("download.html", window.location);
if (urls && (urls.length > 0)) if (urls && (urls.length > 0)) {
contentUri.setData("urls", urls.map(encodeURIComponent).join("|")); contentURL.search = new URLSearchParams({
urls: urls.map(encodeURIComponent).join("|")
});
}
new MochaUI.Window({ new MochaUI.Window({
id: id, id: id,
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Download from URLs)QBT_TR[CONTEXT=downloadFromURL]", title: "QBT_TR(Download from URLs)QBT_TR[CONTEXT=downloadFromURL]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: contentUri.toString(), contentURL: contentURL.toString(),
addClass: "windowFrame", // fixes iframe scrolling on iOS Safari addClass: "windowFrame", // fixes iframe scrolling on iOS Safari
scrollbars: true, scrollbars: true,
maximizable: false, maximizable: false,
@ -216,7 +219,7 @@ const initializeWindows = () => {
title: "QBT_TR(Options)QBT_TR[CONTEXT=OptionsDialog]", title: "QBT_TR(Options)QBT_TR[CONTEXT=OptionsDialog]",
loadMethod: "xhr", loadMethod: "xhr",
toolbar: true, toolbar: true,
contentURL: new URI("views/preferences.html").toString(), contentURL: "views/preferences.html",
require: { require: {
css: ["css/Tabs.css"] css: ["css/Tabs.css"]
}, },
@ -242,7 +245,7 @@ const initializeWindows = () => {
id: id, id: id,
title: "QBT_TR(Manage Cookies)QBT_TR[CONTEXT=CookiesDialog]", title: "QBT_TR(Manage Cookies)QBT_TR[CONTEXT=CookiesDialog]",
loadMethod: "xhr", loadMethod: "xhr",
contentURL: new URI("views/cookies.html").toString(), contentURL: "views/cookies.html",
maximizable: false, maximizable: false,
paddingVertical: 0, paddingVertical: 0,
paddingHorizontal: 0, paddingHorizontal: 0,
@ -264,7 +267,7 @@ const initializeWindows = () => {
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Upload local torrent)QBT_TR[CONTEXT=HttpServer]", title: "QBT_TR(Upload local torrent)QBT_TR[CONTEXT=HttpServer]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("upload.html").toString(), contentURL: "upload.html",
addClass: "windowFrame", // fixes iframe scrolling on iOS Safari addClass: "windowFrame", // fixes iframe scrolling on iOS Safari
scrollbars: true, scrollbars: true,
maximizable: false, maximizable: false,
@ -280,12 +283,16 @@ const initializeWindows = () => {
}); });
globalUploadLimitFN = () => { globalUploadLimitFN = () => {
const contentURL = new URL("uploadlimit.html", window.location);
contentURL.search = new URLSearchParams({
hashes: "global"
});
new MochaUI.Window({ new MochaUI.Window({
id: "uploadLimitPage", id: "uploadLimitPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Global Upload Speed Limit)QBT_TR[CONTEXT=MainWindow]", title: "QBT_TR(Global Upload Speed Limit)QBT_TR[CONTEXT=MainWindow]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("uploadlimit.html").setData("hashes", "global").toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
@ -298,13 +305,19 @@ const initializeWindows = () => {
uploadLimitFN = () => { uploadLimitFN = () => {
const hashes = torrentsTable.selectedRowsIds(); const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) { if (hashes.length <= 0)
return;
const contentURL = new URL("uploadlimit.html", window.location);
contentURL.search = new URLSearchParams({
hashes: hashes.join("|")
});
new MochaUI.Window({ new MochaUI.Window({
id: "uploadLimitPage", id: "uploadLimitPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Torrent Upload Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]", title: "QBT_TR(Torrent Upload Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("uploadlimit.html").setData("hashes", hashes.join("|")).toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
@ -313,12 +326,13 @@ const initializeWindows = () => {
width: 424, width: 424,
height: 100 height: 100
}); });
}
}; };
shareRatioFN = () => { shareRatioFN = () => {
const hashes = torrentsTable.selectedRowsIds(); const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) { if (hashes.length <= 0)
return;
let shareRatio = null; let shareRatio = null;
let torrentsHaveSameShareRatio = true; let torrentsHaveSameShareRatio = true;
@ -339,14 +353,18 @@ const initializeWindows = () => {
} }
} }
const contentURL = new URL("shareratio.html", window.location);
contentURL.search = new URLSearchParams({
hashes: hashes.join("|"),
// if all torrents have same share ratio, display that share ratio. else use the default // if all torrents have same share ratio, display that share ratio. else use the default
const orig = torrentsHaveSameShareRatio ? shareRatio : ""; orig: torrentsHaveSameShareRatio ? shareRatio : ""
});
new MochaUI.Window({ new MochaUI.Window({
id: "shareRatioPage", id: "shareRatioPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDialog]", title: "QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDialog]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("shareratio.html").setData("hashes", hashes.join("|")).setData("orig", orig).toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
maximizable: false, maximizable: false,
paddingVertical: 0, paddingVertical: 0,
@ -354,7 +372,6 @@ const initializeWindows = () => {
width: 424, width: 424,
height: 220 height: 220
}); });
}
}; };
toggleSequentialDownloadFN = () => { toggleSequentialDownloadFN = () => {
@ -412,12 +429,16 @@ const initializeWindows = () => {
}; };
globalDownloadLimitFN = () => { globalDownloadLimitFN = () => {
const contentURL = new URL("downloadlimit.html", window.location);
contentURL.search = new URLSearchParams({
hashes: "global"
});
new MochaUI.Window({ new MochaUI.Window({
id: "downloadLimitPage", id: "downloadLimitPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Global Download Speed Limit)QBT_TR[CONTEXT=MainWindow]", title: "QBT_TR(Global Download Speed Limit)QBT_TR[CONTEXT=MainWindow]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("downloadlimit.html").setData("hashes", "global").toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
@ -435,7 +456,7 @@ const initializeWindows = () => {
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Statistics)QBT_TR[CONTEXT=StatsDialog]", title: "QBT_TR(Statistics)QBT_TR[CONTEXT=StatsDialog]",
loadMethod: "xhr", loadMethod: "xhr",
contentURL: new URI("views/statistics.html").toString(), contentURL: "views/statistics.html",
maximizable: false, maximizable: false,
padding: 10, padding: 10,
width: loadWindowWidth(id, 285), width: loadWindowWidth(id, 285),
@ -448,13 +469,19 @@ const initializeWindows = () => {
downloadLimitFN = () => { downloadLimitFN = () => {
const hashes = torrentsTable.selectedRowsIds(); const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) { if (hashes.length <= 0)
return;
const contentURL = new URL("downloadlimit.html", window.location);
contentURL.search = new URLSearchParams({
hashes: hashes.join("|")
});
new MochaUI.Window({ new MochaUI.Window({
id: "downloadLimitPage", id: "downloadLimitPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Torrent Download Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]", title: "QBT_TR(Torrent Download Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("downloadlimit.html").setData("hashes", hashes.join("|")).toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
@ -463,7 +490,6 @@ const initializeWindows = () => {
width: 424, width: 424,
height: 100 height: 100
}); });
}
}; };
deleteSelectedTorrentsFN = (forceDeleteFiles = false) => { deleteSelectedTorrentsFN = (forceDeleteFiles = false) => {
@ -625,16 +651,20 @@ const initializeWindows = () => {
setLocationFN = () => { setLocationFN = () => {
const hashes = torrentsTable.selectedRowsIds(); const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) { if (hashes.length <= 0)
const hash = hashes[0]; return;
const row = torrentsTable.getRow(hash);
const contentURL = new URL("setlocation.html", window.location);
contentURL.search = new URLSearchParams({
hashes: hashes.join("|"),
path: encodeURIComponent(torrentsTable.getRow(hashes[0]).full_data.save_path)
});
new MochaUI.Window({ new MochaUI.Window({
id: "setLocationPage", id: "setLocationPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Set location)QBT_TR[CONTEXT=TransferListWidget]", title: "QBT_TR(Set location)QBT_TR[CONTEXT=TransferListWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("setlocation.html").setData("hashes", hashes.join("|")).setData("path", encodeURIComponent(row.full_data.save_path)).toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: true, resizable: true,
maximizable: false, maximizable: false,
@ -643,21 +673,28 @@ const initializeWindows = () => {
width: 400, width: 400,
height: 130 height: 130
}); });
}
}; };
renameFN = () => { renameFN = () => {
const hashes = torrentsTable.selectedRowsIds(); const hashes = torrentsTable.selectedRowsIds();
if (hashes.length === 1) { if (hashes.length !== 1)
const hash = hashes[0]; return;
const row = torrentsTable.getRow(hash);
if (row) { const row = torrentsTable.getRow(hashes[0]);
if (!row)
return;
const contentURL = new URL("rename.html", window.location);
contentURL.search = new URLSearchParams({
hash: hashes[0],
name: row.full_data.name
});
new MochaUI.Window({ new MochaUI.Window({
id: "renamePage", id: "renamePage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Rename)QBT_TR[CONTEXT=TransferListWidget]", title: "QBT_TR(Rename)QBT_TR[CONTEXT=TransferListWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("rename.html").setData("hash", hash).setData("name", row.full_data.name).toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: true, resizable: true,
maximizable: false, maximizable: false,
@ -666,8 +703,6 @@ const initializeWindows = () => {
width: 400, width: 400,
height: 100 height: 100
}); });
}
}
}; };
renameFilesFN = () => { renameFilesFN = () => {
@ -784,12 +819,17 @@ const initializeWindows = () => {
if (hashes.length <= 0) if (hashes.length <= 0)
return; return;
const contentURL = new URL("newcategory.html", window.location);
contentURL.search = new URLSearchParams({
action: "set",
hashes: hashes.join("|")
});
new MochaUI.Window({ new MochaUI.Window({
id: "newCategoryPage", id: "newCategoryPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(New Category)QBT_TR[CONTEXT=TransferListWidget]", title: "QBT_TR(New Category)QBT_TR[CONTEXT=TransferListWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("newcategory.html").setData("action", "set").setData("hashes", hashes.join("|")).toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: true, resizable: true,
maximizable: false, maximizable: false,
@ -821,12 +861,16 @@ const initializeWindows = () => {
}; };
createCategoryFN = () => { createCategoryFN = () => {
const contentURL = new URL("newcategory.html", window.location);
contentURL.search = new URLSearchParams({
action: "create"
});
new MochaUI.Window({ new MochaUI.Window({
id: "newCategoryPage", id: "newCategoryPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(New Category)QBT_TR[CONTEXT=CategoryFilterWidget]", title: "QBT_TR(New Category)QBT_TR[CONTEXT=CategoryFilterWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("newcategory.html").setData("action", "create").toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: true, resizable: true,
maximizable: false, maximizable: false,
@ -838,12 +882,17 @@ const initializeWindows = () => {
}; };
createSubcategoryFN = (category) => { createSubcategoryFN = (category) => {
const contentURL = new URL("newcategory.html", window.location);
contentURL.search = new URLSearchParams({
action: "createSubcategory",
categoryName: `${category}/`
});
new MochaUI.Window({ new MochaUI.Window({
id: "newSubcategoryPage", id: "newSubcategoryPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(New Category)QBT_TR[CONTEXT=CategoryFilterWidget]", title: "QBT_TR(New Category)QBT_TR[CONTEXT=CategoryFilterWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("newcategory.html").setData("action", "createSubcategory").setData("categoryName", `${category}/`).toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: true, resizable: true,
maximizable: false, maximizable: false,
@ -855,12 +904,18 @@ const initializeWindows = () => {
}; };
editCategoryFN = (category) => { editCategoryFN = (category) => {
const contentURL = new URL("newcategory.html", window.location);
contentURL.search = new URLSearchParams({
action: "edit",
categoryName: category,
savePath: categoryMap.get(category).savePath
});
new MochaUI.Window({ new MochaUI.Window({
id: "editCategoryPage", id: "editCategoryPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Edit Category)QBT_TR[CONTEXT=TransferListWidget]", title: "QBT_TR(Edit Category)QBT_TR[CONTEXT=TransferListWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("newcategory.html").setData("action", "edit").setData("categoryName", category).setData("savePath", categoryMap.get(category).savePath).toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: true, resizable: true,
maximizable: false, maximizable: false,
@ -913,12 +968,17 @@ const initializeWindows = () => {
if (hashes.length <= 0) if (hashes.length <= 0)
return; return;
const contentURL = new URL("newtag.html", window.location);
contentURL.search = new URLSearchParams({
action: "set",
hashes: hashes.join("|")
});
new MochaUI.Window({ new MochaUI.Window({
id: "newTagPage", id: "newTagPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Add tags)QBT_TR[CONTEXT=TransferListWidget]", title: "QBT_TR(Add tags)QBT_TR[CONTEXT=TransferListWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("newtag.html").setData("action", "set").setData("hashes", hashes.join("|")).toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: true, resizable: true,
maximizable: false, maximizable: false,
@ -956,12 +1016,16 @@ const initializeWindows = () => {
}; };
createTagFN = () => { createTagFN = () => {
const contentURL = new URL("newtag.html", window.location);
contentURL.search = new URLSearchParams({
action: "create"
});
new MochaUI.Window({ new MochaUI.Window({
id: "newTagPage", id: "newTagPage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(New Tag)QBT_TR[CONTEXT=TagFilterWidget]", title: "QBT_TR(New Tag)QBT_TR[CONTEXT=TagFilterWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("newtag.html").setData("action", "create").toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: true, resizable: true,
maximizable: false, maximizable: false,
@ -1002,12 +1066,16 @@ const initializeWindows = () => {
if ((trackerHost === TRACKERS_ALL) || (trackerHost === TRACKERS_TRACKERLESS)) if ((trackerHost === TRACKERS_ALL) || (trackerHost === TRACKERS_TRACKERLESS))
return; return;
const trackerURLs = [...trackerMap.get(trackerHost).keys()].map(encodeURIComponent).join("|"); const contentURL = new URL("confirmtrackerdeletion.html", window.location);
contentURL.search = new URLSearchParams({
host: trackerHost,
urls: [...trackerMap.get(trackerHost).keys()].map(encodeURIComponent).join("|")
});
new MochaUI.Window({ new MochaUI.Window({
id: "confirmDeletionPage", id: "confirmDeletionPage",
title: "QBT_TR(Remove tracker)QBT_TR[CONTEXT=confirmDeletionDlg]", title: "QBT_TR(Remove tracker)QBT_TR[CONTEXT=confirmDeletionDlg]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("confirmtrackerdeletion.html").setData("host", trackerHost).setData("urls", trackerURLs).toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: true, resizable: true,
maximizable: false, maximizable: false,
@ -1099,7 +1167,10 @@ const initializeWindows = () => {
continue; continue;
const name = row.full_data.name; const name = row.full_data.name;
const url = new URI("api/v2/torrents/export").setData("hash", hash).toString(); const url = new URL("api/v2/torrents/export", window.location);
url.search = new URLSearchParams({
hash: hash
});
// download response to file // download response to file
await window.qBittorrent.Misc.downloadFile(url, `${name}.torrent`, "QBT_TR(Unable to export torrent file)QBT_TR[CONTEXT=MainWindow]"); await window.qBittorrent.Misc.downloadFile(url, `${name}.torrent`, "QBT_TR(Unable to export torrent file)QBT_TR[CONTEXT=MainWindow]");
@ -1190,7 +1261,7 @@ const initializeWindows = () => {
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(About qBittorrent)QBT_TR[CONTEXT=AboutDialog]", title: "QBT_TR(About qBittorrent)QBT_TR[CONTEXT=AboutDialog]",
loadMethod: "xhr", loadMethod: "xhr",
contentURL: new URI("views/about.html").toString(), contentURL: "views/about.html",
require: { require: {
css: ["css/Tabs.css"] css: ["css/Tabs.css"]
}, },

View file

@ -56,9 +56,11 @@ window.qBittorrent.PropPeers ??= (() => {
clearTimeout(loadTorrentPeersTimer); clearTimeout(loadTorrentPeersTimer);
return; return;
} }
const url = new URI("api/v2/sync/torrentPeers") const url = new URL("api/v2/sync/torrentPeers", window.location);
.setData("rid", syncTorrentPeersLastResponseId) url.search = new URLSearchParams({
.setData("hash", current_hash); hash: current_hash,
rid: syncTorrentPeersLastResponseId,
});
fetch(url, { fetch(url, {
method: "GET", method: "GET",
cache: "no-store" cache: "no-store"

View file

@ -27,10 +27,11 @@
} }
}); });
const path = new URI().getData("path"); const searchParams = new URLSearchParams(window.location.search);
const path = searchParams.get("path");
// set text field to current value // set text field to current value
if (path) if (path !== null)
$("setLocation").value = decodeURIComponent(path); $("setLocation").value = decodeURIComponent(path);
$("setLocation").focus(); $("setLocation").focus();
@ -48,7 +49,7 @@
fetch("api/v2/torrents/setLocation", { fetch("api/v2/torrents/setLocation", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
hashes: new URI().getData("hashes"), hashes: searchParams.get("hashes"),
location: location location: location
}) })
}) })

View file

@ -30,8 +30,8 @@
} }
}); });
const hashesList = new URI().getData("hashes").split("|"); const searchParams = new URLSearchParams(window.location.search);
const origValues = new URI().getData("orig").split("|"); const origValues = searchParams.get("orig").split("|");
const values = { const values = {
ratioLimit: window.qBittorrent.Misc.friendlyFloat(origValues[0], 2), ratioLimit: window.qBittorrent.Misc.friendlyFloat(origValues[0], 2),
@ -103,7 +103,7 @@
fetch("api/v2/torrents/setShareLimits", { fetch("api/v2/torrents/setShareLimits", {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
hashes: hashesList.join("|"), hashes: searchParams.get("hashes"),
ratioLimit: ratioLimitValue, ratioLimit: ratioLimitValue,
seedingTimeLimit: seedingTimeLimitValue, seedingTimeLimit: seedingTimeLimitValue,
inactiveSeedingTimeLimit: inactiveSeedingTimeLimitValue inactiveSeedingTimeLimit: inactiveSeedingTimeLimitValue

View file

@ -46,7 +46,7 @@
} }
}); });
const hashes = new URI().getData("hashes").split("|"); const hashes = new URLSearchParams(window.location.search).get("hashes").split("|");
const setUpLimit = () => { const setUpLimit = () => {
const limit = Number($("uplimitUpdatevalue").value) * 1024; const limit = Number($("uplimitUpdatevalue").value) * 1024;
if (hashes[0] === "global") { if (hashes[0] === "global") {

View file

@ -340,20 +340,23 @@
curTab = currentSelectedTab; curTab = currentSelectedTab;
let url; let url;
if (curTab === "main") { switch (curTab) {
url = new URI("api/v2/log/main"); case "main":
url.setData({ url = new URL("api/v2/log/main", window.location);
url.search = new URLSearchParams({
normal: selectedLogLevels.includes("1"), normal: selectedLogLevels.includes("1"),
info: selectedLogLevels.includes("2"), info: selectedLogLevels.includes("2"),
warning: selectedLogLevels.includes("4"), warning: selectedLogLevels.includes("4"),
critical: selectedLogLevels.includes("8") critical: selectedLogLevels.includes("8")
}); });
} break;
else {
url = new URI("api/v2/log/peers"); case "peer":
url = new URL("api/v2/log/peers", window.location);
break;
} }
url.setData("last_known_id", tableInfo[curTab].last_id); url.searchParams.set("last_known_id", tableInfo[curTab].last_id);
tableInfo[curTab].progress = true; tableInfo[curTab].progress = true;
fetch(url, { fetch(url, {

View file

@ -743,12 +743,17 @@
}; };
const editUrl = (path, url) => { const editUrl = (path, url) => {
const contentURL = new URL("editfeedurl.html", window.location);
contentURL.search = new URLSearchParams({
path: path,
url: url
});
new MochaUI.Window({ new MochaUI.Window({
id: "editFeedURL", id: "editFeedURL",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Please type a RSS feed URL)QBT_TR[CONTEXT=RSSWidget]", title: "QBT_TR(Please type a RSS feed URL)QBT_TR[CONTEXT=RSSWidget]",
loadMethod: "iframe", loadMethod: "iframe",
contentURL: new URI("editfeedurl.html").setData("path", path).setData("url", url).toString(), contentURL: contentURL.toString(),
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,