From 5b814cf1495ea99dcac6dec64e800b9befc62025 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Tue, 1 Jul 2025 07:13:16 -0700 Subject: [PATCH] WebUI: Allow setting default category when adding torrent --- src/webui/www/private/addtorrent.html | 9 ++++++++- src/webui/www/private/scripts/addtorrent.js | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/webui/www/private/addtorrent.html b/src/webui/www/private/addtorrent.html index dd5dc514e..23df8c8fa 100644 --- a/src/webui/www/private/addtorrent.html +++ b/src/webui/www/private/addtorrent.html @@ -195,10 +195,17 @@ - + + + + + + + + diff --git a/src/webui/www/private/scripts/addtorrent.js b/src/webui/www/private/scripts/addtorrent.js index 3addf2750..c2979265e 100644 --- a/src/webui/www/private/scripts/addtorrent.js +++ b/src/webui/www/private/scripts/addtorrent.js @@ -43,13 +43,21 @@ window.qBittorrent.AddTorrent ??= (() => { let windowId = ""; let source = ""; + const LocalPreferences = new window.qBittorrent.LocalPreferences.LocalPreferences(); + const getCategories = () => { + const defaultCategory = LocalPreferences.get("add_torrent_default_category", ""); + const categorySelect = document.getElementById("categorySelect"); for (const name of window.parent.qBittorrent.Client.categoryMap.keys()) { const option = document.createElement("option"); option.value = name; option.textContent = name; - document.getElementById("categorySelect").appendChild(option); + option.selected = name === defaultCategory; + categorySelect.appendChild(option); } + + if (defaultCategory !== "") + changeCategorySelect(categorySelect); }; const getTags = () => { @@ -299,6 +307,13 @@ window.qBittorrent.AddTorrent ??= (() => { document.getElementById("loadingSpinner").style.display = "block"; + if (document.getElementById("setDefaultCategory").checked) { + const category = document.getElementById("category").value.trim(); + if (category.length === 0) + LocalPreferences.remove("add_torrent_default_category"); + else + LocalPreferences.set("add_torrent_default_category", category); + } }; window.addEventListener("load", async (event) => {