2 #manageCookiesContainer {
39 vertical-align: middle;
46 <div id=
"manageCookiesContainer">
47 <table id=
"manageCookiesTable">
50 <td class=
"domain">QBT_TR(Domain)QBT_TR[CONTEXT=CookiesDialog]
</td>
51 <td class=
"path">QBT_TR(Path)QBT_TR[CONTEXT=CookiesDialog]
</td>
52 <td class=
"name">QBT_TR(Name)QBT_TR[CONTEXT=CookiesDialog]
</td>
53 <td class=
"value">QBT_TR(Value)QBT_TR[CONTEXT=CookiesDialog]
</td>
54 <td class=
"expDate">QBT_TR(Expiration Date)QBT_TR[CONTEXT=CookiesDialog]
</td>
55 <td class=
"actionColumn"></td>
59 <tr class=
"invisible newRow">
60 <td class=
"domain"><input type=
"text" aria-label=
"QBT_TR(Domain)QBT_TR[CONTEXT=CookiesDialog]" autocomplete=
"off" autocorrect=
"off" autocapitalize=
"none"></td>
61 <td class=
"path"><input type=
"text" aria-label=
"QBT_TR(Path)QBT_TR[CONTEXT=CookiesDialog]" autocomplete=
"off" autocorrect=
"off" autocapitalize=
"none"></td>
62 <td class=
"name"><input type=
"text" aria-label=
"QBT_TR(Name)QBT_TR[CONTEXT=CookiesDialog]" autocomplete=
"off" autocorrect=
"off" autocapitalize=
"none"></td>
63 <td class=
"value"><input type=
"text" aria-label=
"QBT_TR(Value)QBT_TR[CONTEXT=CookiesDialog]" autocomplete=
"off" autocorrect=
"off" autocapitalize=
"none"></td>
64 <td class=
"expDate"><input type=
"datetime-local" aria-label=
"QBT_TR(Expiration Date)QBT_TR[CONTEXT=CookiesDialog]"></td>
65 <td><img class=
"removeCookie" src=
"images/list-remove.svg" alt=
"QBT_TR(Remove)QBT_TR[CONTEXT=CookiesDialog]"></td>
75 <td><img class=
"addCookie" src=
"images/list-add.svg" alt=
"QBT_TR(Add Cookie)QBT_TR[CONTEXT=CookiesDialog]"></td>
80 <div class=
"buttonContainer">
81 <button type=
"button" id=
"saveButton">QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]
</button>
88 window
.qBittorrent
??= {};
89 window
.qBittorrent
.ManageCookies
??= (() => {
90 const exports
= () => {
96 const addCookie
= () => {
97 const newRow
= document
.querySelector("#manageCookiesTable tr.newRow").cloneNode(true);
98 newRow
.querySelector(".removeCookie").addEventListener("click", (event
) => {
99 deleteCookie(event
.target
);
101 newRow
.classList
.remove("invisible");
102 document
.querySelector("#manageCookiesTable tbody").append(newRow
);
106 const deleteCookie
= (element
) => {
107 element
.closest("tr").destroy();
111 const rows
= [...document
.querySelectorAll("#manageCookiesTable tbody tr")].filter(e
=> !e
.hasClass("invisible"));
112 const cookies
= rows
.map(row
=> {
113 const expDateValue
= row
.querySelector("td.expDate input").valueAsNumber
;
114 // remove ms from string
115 const expDate
= Number
.isInteger(expDateValue
) ? Number(String(expDateValue
).slice(0, -3)) : 0;
118 domain
: row
.querySelector("td.domain input").value
,
119 path
: row
.querySelector("td.path input").value
,
120 name
: row
.querySelector("td.name input").value
,
121 value
: row
.querySelector("td.value input").value
,
122 expirationDate
: expDate
,
127 url
: "api/v2/app/setCookies",
131 cookies
: JSON
.stringify(cookies
)
133 onFailure
: (response
) => {
134 let error
= "Unable to save cookies";
135 if (response
?.responseText
)
136 error
+= `: ${response.responseText}`;
139 onSuccess
: (response
) => {
140 window
.qBittorrent
.Client
.closeWindow("cookiesPage");
145 const loadCookies
= () => {
147 url
: "api/v2/app/cookies",
149 onFailure
: (response
) => {
150 let error
= "Unable to load cookies";
151 if (response
?.responseText
)
152 error
+= `: ${response.responseText}`;
155 onSuccess
: (response
) => {
156 for (const cookie
of response
) {
157 const row
= addCookie();
158 row
.querySelector("td.domain input").value
= cookie
.domain
;
159 row
.querySelector("td.path input").value
= cookie
.path
;
160 row
.querySelector("td.name input").value
= cookie
.name
;
161 row
.querySelector("td.value input").value
= cookie
.value
;
162 if (cookie
.expirationDate
> 0) {
163 // remove seconds + milliseconds, if any, to ensure seconds aren't displayed in input field
164 const date
= new Date(cookie
.expirationDate
* 1000);
166 date
.setMilliseconds(0);
167 row
.querySelector("td.expDate input").valueAsNumber
= date
.getTime();
174 const setup
= () => {
177 document
.querySelector(".addCookie").addEventListener("click", (event
) => {
181 document
.querySelector("#saveButton").addEventListener("click", (event
) => {
188 Object
.freeze(window
.qBittorrent
.ManageCookies
);
190 window
.qBittorrent
.ManageCookies
.setup();