@@ -38,6 +38,7 @@ window.qBittorrent.AddTorrent ??= (() => {
38
38
} ;
39
39
40
40
let categories = { } ;
41
+ let tags = [ ] ;
41
42
let defaultSavePath = "" ;
42
43
let defaultTempPath = "" ;
43
44
let windowId = "" ;
@@ -68,6 +69,38 @@ window.qBittorrent.AddTorrent ??= (() => {
68
69
} ) ;
69
70
} ;
70
71
72
+ const getTags = ( ) => {
73
+ fetch ( "api/v2/torrents/tags" , {
74
+ method : "GET" ,
75
+ cache : "no-store"
76
+ } )
77
+ . then ( async ( response ) => {
78
+ if ( ! response . ok )
79
+ return ;
80
+
81
+ const data = await response . json ( ) ;
82
+
83
+ tags = data ;
84
+ const tagsSelect = document . getElementById ( "tagsSelect" ) ;
85
+ for ( const tag of tags ) {
86
+ const option = document . createElement ( "option" ) ;
87
+ option . value = tag ;
88
+ option . textContent = tag ;
89
+ tagsSelect . appendChild ( option ) ;
90
+ }
91
+
92
+ new vanillaSelectBox ( "#tagsSelect" , {
93
+ maxHeight : 200 ,
94
+ search : false ,
95
+ disableSelectAll : true ,
96
+ translations : {
97
+ all : tags . length === 0 ? "" : "QBT_TR(All)QBT_TR[CONTEXT=AddNewTorrentDialog]" ,
98
+ } ,
99
+ keepInlineStyles : false
100
+ } ) ;
101
+ } ) ;
102
+ } ;
103
+
71
104
const getPreferences = ( ) => {
72
105
const pref = window . parent . qBittorrent . Cache . preferences . get ( ) ;
73
106
@@ -132,6 +165,11 @@ window.qBittorrent.AddTorrent ??= (() => {
132
165
}
133
166
} ;
134
167
168
+ const changeTagsSelect = ( element ) => {
169
+ const tags = [ ...element . options ] . filter ( opt => opt . selected ) . map ( opt => opt . value ) ;
170
+ document . getElementById ( "tags" ) . value = tags . join ( "," ) ;
171
+ } ;
172
+
135
173
const changeTMM = ( item ) => {
136
174
const savepath = document . getElementById ( "savepath" ) ;
137
175
const useDownloadPath = document . getElementById ( "useDownloadPath" ) ;
@@ -266,10 +304,12 @@ window.qBittorrent.AddTorrent ??= (() => {
266
304
267
305
getPreferences ( ) ;
268
306
getCategories ( ) ;
307
+ getTags ( ) ;
269
308
} ) ;
270
309
271
310
window . addEventListener ( "DOMContentLoaded" , ( event ) => {
272
311
document . getElementById ( "useDownloadPath" ) . addEventListener ( "change" , ( e ) => changeUseDownloadPath ( e . target . checked ) ) ;
312
+ document . getElementById ( "tagsSelect" ) . addEventListener ( "change" , ( e ) => changeTagsSelect ( e . target ) ) ;
273
313
} ) ;
274
314
275
315
return exports ( ) ;
0 commit comments