diff --git a/src/webui/www/private/addtorrent.html b/src/webui/www/private/addtorrent.html index 551b3c762..ca7af74c0 100644 --- a/src/webui/www/private/addtorrent.html +++ b/src/webui/www/private/addtorrent.html @@ -7,8 +7,10 @@ + + @@ -84,6 +86,13 @@ window.qBittorrent.AddTorrent.loadMetadata(source); }); + + @@ -166,6 +175,17 @@ + + + + + +
+ + +
+ + diff --git a/src/webui/www/private/scripts/addtorrent.js b/src/webui/www/private/scripts/addtorrent.js index 135c2893b..10676cf68 100644 --- a/src/webui/www/private/scripts/addtorrent.js +++ b/src/webui/www/private/scripts/addtorrent.js @@ -37,6 +37,7 @@ window.qBittorrent.AddTorrent ??= (() => { }; let categories = {}; + let tags = []; let defaultSavePath = ""; let windowId = ""; let source; @@ -66,6 +67,38 @@ window.qBittorrent.AddTorrent ??= (() => { }); }; + const getTags = () => { + fetch("api/v2/torrents/tags", { + method: "GET", + cache: "no-store" + }) + .then(async (response) => { + if (!response.ok) + return; + + const data = await response.json(); + + tags = data; + const tagsSelect = document.getElementById("tagsSelect"); + for (const tag of tags) { + const option = document.createElement("option"); + option.value = tag; + option.textContent = tag; + tagsSelect.appendChild(option); + } + + new vanillaSelectBox("#tagsSelect", { + maxHeight: 200, + search: false, + disableSelectAll: true, + translations: { + all: tags.length === 0 ? "" : "QBT_TR(All)QBT_TR[CONTEXT=AddNewTorrentDialog]", + }, + keepInlineStyles: false + }); + }); + }; + const getPreferences = () => { const pref = window.parent.qBittorrent.Cache.preferences.get(); @@ -122,6 +155,11 @@ window.qBittorrent.AddTorrent ??= (() => { } }; + const changeTagsSelect = (element) => { + const tags = [...element.options].filter(opt => opt.selected).map(opt => opt.value); + document.getElementById("tags").value = tags.join(","); + }; + const changeTMM = (item) => { const savepath = document.getElementById("savepath"); const useDownloadPath = document.getElementById("useDownloadPath"); @@ -240,10 +278,12 @@ window.qBittorrent.AddTorrent ??= (() => { getPreferences(); getCategories(); + getTags(); }); window.addEventListener("DOMContentLoaded", () => { document.getElementById("useDownloadPath").addEventListener("change", (e) => changeUseDownloadPath(e.target)); + document.getElementById("tagsSelect").addEventListener("change", (e) => changeTagsSelect(e.target)); }); return exports();