2022-10-18 22:39:32 -04:00
<!DOCTYPE html>
< html lang = "${LANG}" >
< head >
2024-10-03 08:37:11 -04:00
< meta charset = "UTF-8" >
2022-11-30 13:49:48 -05:00
< title > Torrent Upload/Download Ratio Limiting< / title >
2024-10-03 08:37:11 -04:00
< link rel = "stylesheet" href = "css/style.css?v=${CACHEID}" type = "text/css" >
2022-10-18 22:39:32 -04:00
< script src = "scripts/lib/MooTools-Core-1.6.0-compat-compressed.js" > < / script >
< script src = "scripts/lib/MooTools-More-1.6.0-compat-compressed.js" > < / script >
< script src = "scripts/misc.js?locale=${LANG}&v=${CACHEID}" > < / script >
< script >
2024-10-03 08:37:11 -04:00
"use strict";
2022-10-18 22:39:32 -04:00
const UseGlobalLimit = -2;
const NoLimit = -1;
new Keyboard({
2024-10-03 08:37:11 -04:00
defaultEventType: "keydown",
2022-10-18 22:39:32 -04:00
events: {
2024-10-03 08:37:11 -04:00
"Enter": function(event) {
$("save").click();
2022-10-18 22:39:32 -04:00
event.preventDefault();
},
2024-10-03 08:37:11 -04:00
"Escape": function(event) {
window.parent.qBittorrent.Client.closeWindows();
2022-10-18 22:39:32 -04:00
event.preventDefault();
},
2024-10-03 08:37:11 -04:00
"Esc": function(event) {
window.parent.qBittorrent.Client.closeWindows();
2022-10-18 22:39:32 -04:00
event.preventDefault();
}
}
}).activate();
2024-10-03 08:37:11 -04:00
window.addEventListener("DOMContentLoaded", () => {
const hashesList = new URI().getData("hashes").split("|");
const origValues = new URI().getData("orig").split("|");
2022-10-18 22:39:32 -04:00
const values = {
ratioLimit: window.qBittorrent.Misc.friendlyFloat(origValues[0], 2),
2024-10-03 08:37:11 -04:00
seedingTimeLimit: parseInt(origValues[1], 10),
inactiveSeedingTimeLimit: parseInt(origValues[2], 10),
2024-01-07 17:04:03 -05:00
maxRatio: window.qBittorrent.Misc.friendlyFloat(origValues[3], 2),
2024-10-03 08:37:11 -04:00
maxSeedingTime: parseInt(origValues[4], 10),
maxInactiveSeedingTime: parseInt(origValues[5], 10)
2022-10-18 22:39:32 -04:00
};
// select default when orig values not passed. using double equals to compare string and int
2024-10-03 08:37:11 -04:00
if ((origValues[0] === "")
|| ((values.ratioLimit === UseGlobalLimit)
& & (values.seedingTimeLimit === UseGlobalLimit)
& & (values.inactiveSeedingTimeLimit === UseGlobalLimit))) {
2022-10-18 22:39:32 -04:00
// use default option
2024-10-03 08:37:11 -04:00
setSelectedRadioValue("shareLimit", "default");
2022-10-18 22:39:32 -04:00
}
2024-10-03 08:37:11 -04:00
else if ((values.maxRatio === NoLimit) & & (values.maxSeedingTime === NoLimit) & & (values.maxInactiveSeedingTime === NoLimit)) {
setSelectedRadioValue("shareLimit", "none");
2022-10-18 22:39:32 -04:00
// TODO set input boxes to *global* max ratio and seeding time
}
else {
2024-10-03 08:37:11 -04:00
setSelectedRadioValue("shareLimit", "custom");
2022-10-18 22:39:32 -04:00
if (values.ratioLimit >= 0) {
2024-10-03 08:37:11 -04:00
$("setRatio").checked = true;
$("ratio").value = values.ratioLimit;
2022-10-18 22:39:32 -04:00
}
if (values.seedingTimeLimit >= 0) {
2024-10-03 08:37:11 -04:00
$("setTotalMinutes").checked = true;
$("totalMinutes").value = values.seedingTimeLimit;
2024-01-07 17:04:03 -05:00
}
if (values.inactiveSeedingTimeLimit >= 0) {
2024-10-03 08:37:11 -04:00
$("setInactiveMinutes").checked = true;
$("inactiveMinutes").value = values.inactiveSeedingTimeLimit;
2022-10-18 22:39:32 -04:00
}
}
shareLimitChanged();
2024-10-03 08:37:11 -04:00
$("default").focus();
$("save").addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
2022-10-18 22:39:32 -04:00
2024-10-03 08:37:11 -04:00
if (!isFormValid())
return;
2022-10-18 22:39:32 -04:00
2024-10-03 08:37:11 -04:00
const shareLimit = getSelectedRadioValue("shareLimit");
2022-10-18 22:39:32 -04:00
let ratioLimitValue = 0.00;
let seedingTimeLimitValue = 0;
2024-01-07 17:04:03 -05:00
let inactiveSeedingTimeLimitValue = 0;
2022-10-18 22:39:32 -04:00
2024-10-03 08:37:11 -04:00
if (shareLimit === "default") {
2024-01-07 17:04:03 -05:00
ratioLimitValue = seedingTimeLimitValue = inactiveSeedingTimeLimitValue = UseGlobalLimit;
2022-10-18 22:39:32 -04:00
}
2024-10-03 08:37:11 -04:00
else if (shareLimit === "none") {
2024-01-07 17:04:03 -05:00
ratioLimitValue = seedingTimeLimitValue = inactiveSeedingTimeLimitValue = NoLimit;
2022-10-18 22:39:32 -04:00
}
2024-10-03 08:37:11 -04:00
else if (shareLimit === "custom") {
ratioLimitValue = $("setRatio").checked ? $("ratio").value : -1;
seedingTimeLimitValue = $("setTotalMinutes").checked ? $("totalMinutes").value : -1;
inactiveSeedingTimeLimitValue = $("setInactiveMinutes").checked ? $("inactiveMinutes").value : -1;
2022-10-18 22:39:32 -04:00
}
else {
2024-10-03 08:37:11 -04:00
return;
2022-10-18 22:39:32 -04:00
}
new Request({
2024-10-03 08:37:11 -04:00
url: "api/v2/torrents/setShareLimits",
method: "post",
2022-10-18 22:39:32 -04:00
data: {
2024-10-03 08:37:11 -04:00
hashes: hashesList.join("|"),
2022-10-18 22:39:32 -04:00
ratioLimit: ratioLimitValue,
2024-01-07 17:04:03 -05:00
seedingTimeLimit: seedingTimeLimitValue,
inactiveSeedingTimeLimit: inactiveSeedingTimeLimitValue
2022-10-18 22:39:32 -04:00
},
onComplete: function() {
2024-10-03 08:37:11 -04:00
window.parent.qBittorrent.Client.closeWindows();
2022-10-18 22:39:32 -04:00
}
}).send();
});
});
function getSelectedRadioValue(name) {
const radios = document.getElementsByName(name);
for (let i = 0; i < radios.length ; + + i ) {
const radio = radios[i];
2024-10-03 08:37:11 -04:00
if (radio.checked)
return radio.value;
2022-10-18 22:39:32 -04:00
}
}
function setSelectedRadioValue(name, value) {
const radios = document.getElementsByName(name);
for (let i = 0; i < radios.length ; + + i ) {
const radio = radios[i];
if (radio.value === value)
radio.checked = true;
}
}
function shareLimitChanged() {
2024-10-03 08:37:11 -04:00
const customShareLimit = getSelectedRadioValue("shareLimit") === "custom";
$("setRatio").disabled = !customShareLimit;
$("setTotalMinutes").disabled = !customShareLimit;
$("setInactiveMinutes").disabled = !customShareLimit;
2022-10-18 22:39:32 -04:00
enableInputBoxes();
2024-10-03 08:37:11 -04:00
$("save").disabled = !isFormValid();
2022-10-18 22:39:32 -04:00
}
function enableInputBoxes() {
2024-10-03 08:37:11 -04:00
$("ratio").disabled = $("setRatio").disabled || !$("setRatio").checked;
$("totalMinutes").disabled = $("setTotalMinutes").disabled || !$("setTotalMinutes").checked;
$("inactiveMinutes").disabled = $("setInactiveMinutes").disabled || !$("setInactiveMinutes").checked;
2022-10-18 22:39:32 -04:00
2024-10-03 08:37:11 -04:00
$("save").disabled = !isFormValid();
2022-10-18 22:39:32 -04:00
}
function isFormValid() {
2024-10-03 08:37:11 -04:00
return !((getSelectedRadioValue("shareLimit") === "custom") & & !$("setRatio").checked
& & !$("setTotalMinutes").checked & & !$("setInactiveMinutes").checked);
2022-10-18 22:39:32 -04:00
}
< / script >
< / head >
< body >
< div style = "padding: 10px 10px 0px 10px;" >
2024-10-03 08:37:11 -04:00
< input type = "radio" name = "shareLimit" id = "default" value = "default" onchange = "shareLimitChanged()" checked style = "margin-bottom: 5px;" > < label for = "default" > Use global share limit< / label > < br >
< input type = "radio" name = "shareLimit" id = "shareLimitNone" value = "none" onchange = "shareLimitChanged()" style = "margin-bottom: 5px;" > < label for = "shareLimitNone" > Set no share limit< / label > < br >
< input type = "radio" name = "shareLimit" id = "shareLimitCustom" value = "custom" onchange = "shareLimitChanged()" style = "margin-bottom: 5px;" > < label for = "shareLimitCustom" > Set share limit to< / label > < br >
2022-10-18 22:39:32 -04:00
< div style = "margin-left: 40px; margin-bottom: 5px;" >
2024-10-03 08:37:11 -04:00
< input type = "checkbox" id = "setRatio" class = "shareLimitInput" onclick = "enableInputBoxes()" >
< label id = "ratioLabel" for = "setRatio" > ratio< / label >
< input type = "number" id = "ratio" value = "0.00" step = ".01" min = "0" max = "9999" class = "shareLimitInput" aria-labelledby = "ratioLabel" >
2022-10-18 22:39:32 -04:00
< / div >
< div style = "margin-left: 40px; margin-bottom: 5px;" >
2024-10-03 08:37:11 -04:00
< input type = "checkbox" id = "setTotalMinutes" class = "shareLimitInput" onclick = "enableInputBoxes()" >
< label id = "totalMinutesLabel" for = "setTotalMinutes" > total minutes< / label >
< input type = "number" id = "totalMinutes" value = "0" step = "1" min = "0" max = "525600" class = "shareLimitInput" aria-labelledby = "totalMinutesLabel" >
2024-01-07 17:04:03 -05:00
< / div >
< div style = "margin-left: 40px; margin-bottom: 5px;" >
2024-10-03 08:37:11 -04:00
< input type = "checkbox" id = "setInactiveMinutes" class = "shareLimitInput" onclick = "enableInputBoxes()" >
< label id = "inactiveMinutesLabel" for = "setInactiveMinutes" > inactive minutes< / label >
< input type = "number" id = "inactiveMinutes" value = "0" step = "1" min = "0" max = "525600" class = "shareLimitInput" aria-labelledby = "inactiveMinutesLabel" >
2022-10-18 22:39:32 -04:00
< / div >
< div style = "text-align: center; padding-top: 10px;" >
2024-10-03 08:37:11 -04:00
< input type = "button" value = "Save" id = "save" >
2022-10-18 22:39:32 -04:00
< / div >
< / div >
< / body >
< / html >