WebUI: migrate to fetch API
[qBittorrent.git] / src / webui / www / private / addpeers.html
blob3110a32bed36271db8420dcfe477df8739b0347c
1 <!DOCTYPE html>
2 <html lang="${LANG}" class="dark">
4 <head>
5 <meta charset="UTF-8">
6 <title>QBT_TR(Add Peers)QBT_TR[CONTEXT=PeersAdditionDialog]</title>
7 <link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
8 <script src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
9 <script src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
10 <script src="scripts/localpreferences.js?v=${CACHEID}"></script>
11 <script src="scripts/color-scheme.js?v=${CACHEID}"></script>
12 <script>
13 "use strict";
15 window.addEventListener("DOMContentLoaded", () => {
16 window.addEventListener("keydown", (event) => {
17 switch (event.key) {
18 case "Escape":
19 event.preventDefault();
20 window.parent.qBittorrent.Client.closeFrameWindow(window);
21 break;
23 });
25 const hash = new URI().getData("hash");
26 if (!hash)
27 return;
29 $("peers").focus();
31 $("addPeersOk").addEventListener("click", (e) => {
32 e.preventDefault();
33 e.stopPropagation();
35 const peers = $("peers").value.trim().split(/[\r\n]+/);
36 if (peers.length === 0)
37 return;
39 fetch("api/v2/torrents/addPeers", {
40 method: "POST",
41 body: new URLSearchParams({
42 "hashes": hash,
43 "peers": peers.join("|")
46 .then((response) => {
47 if (!response.ok) {
48 alert("QBT_TR(Unable to add peers. Please ensure you are adhering to the IP:port format.)QBT_TR[CONTEXT=HttpServer]");
49 return;
52 window.parent.qBittorrent.Client.closeFrameWindow(window);
53 });
54 });
55 });
56 </script>
57 </head>
59 <body>
60 <div style="padding: 10px 10px 0px 10px;">
61 <label for="peers">QBT_TR(List of peers to add (one IP per line):)QBT_TR[CONTEXT=PeersAdditionDialog]</label>
62 <textarea id="peers" rows="10" style="width: 100%;" placeholder="QBT_TR(Format: IPv4:port / [IPv6]:port)QBT_TR[CONTEXT=PeersAdditionDialog]"></textarea>
63 <div style="margin-top: 10px; text-align: center;">
64 <button type="button" onclick="parent.qBittorrent.Client.closeFrameWindow(window);">QBT_TR(Cancel)QBT_TR[CONTEXT=PeersAdditionDialog]</button>
65 <button type="button" id="addPeersOk">QBT_TR(Ok)QBT_TR[CONTEXT=PeersAdditionDialog]</button>
66 </div>
67 </div>
68 </body>
70 </html>