merge upload and download limit html

This commit is contained in:
tehcneko 2025-05-25 17:11:56 +08:00
commit 0fd929174a
6 changed files with 187 additions and 265 deletions

View file

@ -1,35 +0,0 @@
<!DOCTYPE html>
<html lang="${LANG}" class="dark">
<head>
<meta charset="UTF-8">
<title>QBT_TR(Torrent Download Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]</title>
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
<script src="scripts/localpreferences.js?v=${CACHEID}"></script>
<script src="scripts/color-scheme.js?v=${CACHEID}"></script>
<script src="scripts/speedslider.js?v=${CACHEID}"></script>
</head>
<body>
<div style="padding-top: 10px; width: 100%; text-align: center; margin: 0 auto; overflow: hidden">
<div id="limitSlider" class="slider">
<div id="limitUpdate" class="update">
<label for="limitUpdatevalue">QBT_TR(Download limit:)QBT_TR[CONTEXT=PropertiesWidget]</label>
<input type="text" id="limitUpdatevalue" size="6" placeholder="∞" style="text-align: center;">
<span id="limitUnit">QBT_TR(KiB/s)QBT_TR[CONTEXT=SpeedLimitDialog]</span>
</div>
<input type="range" id="limitSliderInput" value="0" style="width: 100%;" aria-label="QBT_TR(Download limit)QBT_TR[CONTEXT=PropertiesWidget]">
</div>
<input type="button" id="applyButton" value="QBT_TR(Apply)QBT_TR[CONTEXT=HttpServer]" onclick="window.qBittorrent.SpeedSlider.setLimit('download')">
</div>
<script>
"use strict";
window.qBittorrent.SpeedSlider.setup("download");
document.getElementById("limitUpdatevalue").focus();
</script>
</body>
</html>

View file

@ -309,9 +309,10 @@ const initializeWindows = () => {
}); });
globalUploadLimitFN = () => { globalUploadLimitFN = () => {
const contentURL = new URL("uploadlimit.html", window.location); const contentURL = new URL("speedlimit.html", window.location);
contentURL.search = new URLSearchParams({ contentURL.search = new URLSearchParams({
hashes: "global" hashes: "global",
type: "upload",
}); });
new MochaUI.Window({ new MochaUI.Window({
id: "uploadLimitPage", id: "uploadLimitPage",
@ -334,9 +335,10 @@ const initializeWindows = () => {
if (hashes.length <= 0) if (hashes.length <= 0)
return; return;
const contentURL = new URL("uploadlimit.html", window.location); const contentURL = new URL("speedlimit.html", window.location);
contentURL.search = new URLSearchParams({ contentURL.search = new URLSearchParams({
hashes: hashes.join("|") hashes: hashes.join("|"),
type: "upload",
}); });
new MochaUI.Window({ new MochaUI.Window({
id: "uploadLimitPage", id: "uploadLimitPage",
@ -455,9 +457,10 @@ const initializeWindows = () => {
}; };
globalDownloadLimitFN = () => { globalDownloadLimitFN = () => {
const contentURL = new URL("downloadlimit.html", window.location); const contentURL = new URL("speedlimit.html", window.location);
contentURL.search = new URLSearchParams({ contentURL.search = new URLSearchParams({
hashes: "global" hashes: "global",
type: "download",
}); });
new MochaUI.Window({ new MochaUI.Window({
id: "downloadLimitPage", id: "downloadLimitPage",
@ -498,9 +501,10 @@ const initializeWindows = () => {
if (hashes.length <= 0) if (hashes.length <= 0)
return; return;
const contentURL = new URL("downloadlimit.html", window.location); const contentURL = new URL("speedlimit.html", window.location);
contentURL.search = new URLSearchParams({ contentURL.search = new URLSearchParams({
hashes: hashes.join("|") hashes: hashes.join("|"),
type: "download",
}); });
new MochaUI.Window({ new MochaUI.Window({
id: "downloadLimitPage", id: "downloadLimitPage",

View file

@ -1,184 +0,0 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2019 Thomas Piccirello <thomas.piccirello@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
"use strict";
window.qBittorrent ??= {};
window.qBittorrent.SpeedSlider ??= (() => {
const exports = () => {
return {
setup: setup,
setLimit: setLimit,
};
};
const hashes = new URLSearchParams(window.location.search).get("hashes").split("|");
const setup = (type) => {
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Enter":
event.preventDefault();
document.getElementById("applyButton").click();
break;
case "Escape":
event.preventDefault();
window.parent.qBittorrent.Client.closeFrameWindow(window);
break;
}
});
const method = type === "upload" ? "uploadLimit" : "downloadLimit";
// Get global upload limit
fetch(`api/v2/transfer/${method}`, {
method: "GET",
cache: "no-store"
})
.then(async (response) => {
if (!response.ok)
return;
const data = await response.text();
let maximum = 500;
const tmp = Number(data);
if (tmp > 0) {
maximum = tmp / 1024.0;
}
else {
if (hashes[0] === "global")
maximum = 10000;
else
maximum = 1000;
}
// Get torrents download limit
// And create slider
if (hashes[0] === "global") {
let limit = maximum;
if (limit < 0)
limit = 0;
maximum = 10000;
setupSlider(Math.round(limit), maximum);
}
else {
fetch(`api/v2/torrents/${method}`, {
method: "POST",
body: new URLSearchParams({
hashes: hashes.join("|")
})
})
.then(async (response) => {
if (!response.ok)
return;
const data = await response.json();
let limit = data[hashes[0]];
for (const key in data) {
if (limit !== data[key]) {
limit = 0;
break;
}
}
if (limit < 0)
limit = 0;
setupSlider(Math.round(limit / 1024), maximum);
});
}
});
};
const setupSlider = (limit, maximum) => {
const input = document.getElementById("limitSliderInput");
input.setAttribute("max", maximum);
input.setAttribute("min", 0);
input.value = limit;
input.addEventListener("input", (event) => {
const pos = Number(event.target.value);
if (pos > 0) {
document.getElementById("limitUpdatevalue").value = pos;
document.getElementById("limitUnit").style.visibility = "visible";
}
else {
document.getElementById("limitUpdatevalue").value = "∞";
document.getElementById("limitUnit").style.visibility = "hidden";
}
});
// Set default value
if (limit === 0) {
document.getElementById("limitUpdatevalue").value = "∞";
document.getElementById("limitUnit").style.visibility = "hidden";
}
else {
document.getElementById("limitUpdatevalue").value = limit;
document.getElementById("limitUnit").style.visibility = "visible";
}
};
const setLimit = (type) => {
const limit = Number(document.getElementById("limitUpdatevalue").value) * 1024;
const method = type === "upload" ? "setUploadLimit" : "setDownloadLimit";
if (hashes[0] === "global") {
fetch(`api/v2/transfer/${method}`, {
method: "POST",
body: new URLSearchParams({
limit: limit
})
})
.then((response) => {
if (!response.ok)
return;
window.parent.updateMainData();
window.parent.qBittorrent.Client.closeFrameWindow(window);
});
}
else {
fetch(`api/v2/torrents/${method}`, {
method: "POST",
body: new URLSearchParams({
hashes: hashes.join("|"),
limit: limit
})
})
.then((response) => {
if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window);
});
}
};
return exports();
})();
Object.freeze(window.qBittorrent.SpeedSlider);

View file

@ -0,0 +1,174 @@
<!DOCTYPE html>
<html lang="${LANG}" class="dark">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
<script src="scripts/localpreferences.js?v=${CACHEID}"></script>
<script src="scripts/color-scheme.js?v=${CACHEID}"></script>
</head>
<body>
<div style="padding-top: 10px; width: 100%; text-align: center; margin: 0 auto; overflow: hidden">
<div id="limitSlider" class="slider">
<div id="limitUpdate" class="update">
<label id="limitUpdateLabel" for="limitUpdatevalue"></label>
<input type="text" id="limitUpdatevalue" size="6" placeholder="∞" style="text-align: center;">
<span id="limitUnit">QBT_TR(KiB/s)QBT_TR[CONTEXT=SpeedLimitDialog]</span>
</div>
<input type="range" id="limitSliderInput" value="0" style="width: 100%;" aria-label="QBT_TR(Download limit)QBT_TR[CONTEXT=PropertiesWidget]">
</div>
<input type="button" id="applyButton" value="QBT_TR(Apply)QBT_TR[CONTEXT=HttpServer]" onclick="setLimit()">
</div>
<script>
"use strict";
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Enter":
event.preventDefault();
document.getElementById("applyButton").click();
break;
case "Escape":
event.preventDefault();
window.parent.qBittorrent.Client.closeFrameWindow(window);
break;
}
});
const params = new URLSearchParams(window.location.search);
const type = params.get("type");
const hashes = params.get("hashes").split("|");
document.getElementById("limitUpdateLabel").textContent =
type === "upload"
? `QBT_TR(Upload limit:)QBT_TR[CONTEXT=PropertiesWidget]`
: `QBT_TR(Download limit:)QBT_TR[CONTEXT=PropertiesWidget]`;
const setupSlider = (limit, maximum) => {
const input = document.getElementById("limitSliderInput");
input.setAttribute("max", maximum);
input.setAttribute("min", 0);
input.value = limit;
input.addEventListener("input", (event) => {
const pos = Number(event.target.value);
if (pos > 0) {
document.getElementById("limitUpdatevalue").value = pos;
document.getElementById("limitUnit").style.visibility = "visible";
}
else {
document.getElementById("limitUpdatevalue").value = "∞";
document.getElementById("limitUnit").style.visibility = "hidden";
}
});
// Set default value
if (limit === 0) {
document.getElementById("limitUpdatevalue").value = "∞";
document.getElementById("limitUnit").style.visibility = "hidden";
}
else {
document.getElementById("limitUpdatevalue").value = limit;
document.getElementById("limitUnit").style.visibility = "visible";
}
};
const setLimit = () => {
const limit = Number(document.getElementById("limitUpdatevalue").value) * 1024;
if (hashes[0] === "global") {
fetch(`api/v2/transfer/${type === "upload" ? "setUploadLimit" : "setDownloadLimit"}`, {
method: "POST",
body: new URLSearchParams({
limit: limit
})
})
.then((response) => {
if (!response.ok)
return;
window.parent.updateMainData();
window.parent.qBittorrent.Client.closeFrameWindow(window);
});
}
else {
fetch(`api/v2/torrents/${type === "upload" ? "setUploadLimit" : "setDownloadLimit"}`, {
method: "POST",
body: new URLSearchParams({
hashes: hashes.join("|"),
limit: limit
})
})
.then((response) => {
if (!response.ok)
return;
window.parent.qBittorrent.Client.closeFrameWindow(window);
});
}
};
fetch(`api/v2/transfer/${type === "upload" ? "uploadLimit" : "downloadLimit"}`, {
method: "GET",
cache: "no-store"
})
.then(async (response) => {
if (!response.ok)
return;
const data = await response.text();
let maximum = 500;
const tmp = Number(data);
if (tmp > 0) {
maximum = tmp / 1024.0;
}
else {
if (hashes[0] === "global")
maximum = 10000;
else
maximum = 1000;
}
// Get torrents download limit
// And create slider
if (hashes[0] === "global") {
let limit = maximum;
if (limit < 0)
limit = 0;
maximum = 10000;
setupSlider(Math.round(limit), maximum);
}
else {
fetch(`api/v2/torrents/${type === "upload" ? "uploadLimit" : "downloadLimit"}`, {
method: "POST",
body: new URLSearchParams({
hashes: hashes.join("|")
})
})
.then(async (response) => {
if (!response.ok)
return;
const data = await response.json();
let limit = data[hashes[0]];
for (const key in data) {
if (limit !== data[key]) {
limit = 0;
break;
}
}
if (limit < 0)
limit = 0;
setupSlider(Math.round(limit / 1024), maximum);
});
}
});
document.getElementById("limitUpdatevalue").focus();
</script>
</body>
</html>

View file

@ -1,35 +0,0 @@
<!DOCTYPE html>
<html lang="${LANG}" class="dark">
<head>
<meta charset="UTF-8">
<title>QBT_TR(Torrent Upload Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]</title>
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
<script src="scripts/localpreferences.js?v=${CACHEID}"></script>
<script src="scripts/color-scheme.js?v=${CACHEID}"></script>
<script src="scripts/speedslider.js?v=${CACHEID}"></script>
</head>
<body>
<div style="padding-top: 10px; width: 100%; text-align: center; margin: 0 auto; overflow: hidden">
<div id="limitSlider" class="slider">
<div id="limitUpdate" class="update">
<label for="limitUpdatevalue">QBT_TR(Upload limit:)QBT_TR[CONTEXT=PropertiesWidget]</label>
<input type="text" id="limitUpdatevalue" size="6" placeholder="∞" style="text-align: center;">
<span id="limitUnit">QBT_TR(KiB/s)QBT_TR[CONTEXT=SpeedLimitDialog]</span>
</div>
<input type="range" id="limitSliderInput" value="0" style="width: 100%;" aria-label="QBT_TR(Upload limit)QBT_TR[CONTEXT=PropertiesWidget]">
</div>
<input type="button" id="applyButton" value="QBT_TR(Apply)QBT_TR[CONTEXT=HttpServer]" onclick="window.qBittorrent.SpeedSlider.setLimit('upload')">
</div>
<script>
"use strict";
window.qBittorrent.SpeedSlider.setup("upload");
document.getElementById("limitUpdatevalue").focus();
</script>
</body>
</html>

View file

@ -16,7 +16,6 @@
<file>private/css/vanillaSelectBox.css</file> <file>private/css/vanillaSelectBox.css</file>
<file>private/css/Window.css</file> <file>private/css/Window.css</file>
<file>private/download.html</file> <file>private/download.html</file>
<file>private/downloadlimit.html</file>
<file>private/editfeedurl.html</file> <file>private/editfeedurl.html</file>
<file>private/edittracker.html</file> <file>private/edittracker.html</file>
<file>private/editwebseed.html</file> <file>private/editwebseed.html</file>
@ -416,11 +415,10 @@
<file>private/scripts/prop-webseeds.js</file> <file>private/scripts/prop-webseeds.js</file>
<file>private/scripts/rename-files.js</file> <file>private/scripts/rename-files.js</file>
<file>private/scripts/search.js</file> <file>private/scripts/search.js</file>
<file>private/scripts/speedslider.js</file>
<file>private/setlocation.html</file> <file>private/setlocation.html</file>
<file>private/shareratio.html</file> <file>private/shareratio.html</file>
<file>private/speedlimit.html</file>
<file>private/upload.html</file> <file>private/upload.html</file>
<file>private/uploadlimit.html</file>
<file>private/views/about.html</file> <file>private/views/about.html</file>
<file>private/views/aboutToolbar.html</file> <file>private/views/aboutToolbar.html</file>
<file>private/views/confirmAutoTMM.html</file> <file>private/views/confirmAutoTMM.html</file>