2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2024 Paweł Kotiuk <kotiuk@zohomail.eu>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project"s "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
32 File implementing auto-fill for the path input field in the path dialogs.
35 window
.qBittorrent
??= {};
36 window
.qBittorrent
.pathAutofill
??= (() => {
37 const exports
= () => {
39 attachPathAutofill
: attachPathAutofill
43 function showInputSuggestions(inputElement
, names
) {
44 const datalist
= document
.createElement("datalist");
45 datalist
.id
= inputElement
.id
+ "Suggestions";
46 for (const name
of names
) {
47 const option
= document
.createElement("option");
49 datalist
.appendChild(option
);
52 const oldDatalist
= document
.getElementById(`${inputElement.id}Suggestions`);
53 if (oldDatalist
!== null) {
54 oldDatalist
.replaceWith(datalist
);
57 inputElement
.appendChild(datalist
);
58 inputElement
.setAttribute("list", datalist
.id
);
62 function showPathSuggestions(element
, mode
) {
63 const partialPath
= element
.value
;
64 if (partialPath
=== "")
67 fetch(`api/v2/app/getDirectoryContent?dirPath=${partialPath}&mode=${mode}`)
68 .then(response
=> response
.json())
69 .then(filesList
=> { showInputSuggestions(element
, filesList
); })
73 function attachPathAutofill() {
74 const directoryInputs
= document
.querySelectorAll(".pathDirectory:not(.pathAutoFillInitialized)");
75 for (const input
of directoryInputs
) {
76 input
.addEventListener("input", function() { showPathSuggestions(this, "dirs"); });
77 input
.classList
.add("pathAutoFillInitialized");
80 const fileInputs
= document
.querySelectorAll(".pathFile:not(.pathAutoFillInitialized)");
81 for (const input
of fileInputs
) {
82 input
.addEventListener("input", function() { showPathSuggestions(this, "all"); });
83 input
.classList
.add("pathAutoFillInitialized");
89 Object
.freeze(window
.qBittorrent
.pathAutofill
);