2 <html lang=
"${LANG}" class=
"dark">
6 <title>QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDialog]
</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 src=
"scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
16 const UseGlobalLimit
= -2;
19 window
.addEventListener("DOMContentLoaded", () => {
20 window
.addEventListener("keydown", (event
) => {
23 event
.preventDefault();
27 event
.preventDefault();
28 window
.parent
.qBittorrent
.Client
.closeFrameWindow(window
);
33 const hashesList
= new URI().getData("hashes").split("|");
34 const origValues
= new URI().getData("orig").split("|");
37 ratioLimit
: window
.qBittorrent
.Misc
.friendlyFloat(origValues
[0], 2),
38 seedingTimeLimit
: Number(origValues
[1]),
39 inactiveSeedingTimeLimit
: Number(origValues
[2]),
40 maxRatio
: window
.qBittorrent
.Misc
.friendlyFloat(origValues
[3], 2),
41 maxSeedingTime
: Number(origValues
[4]),
42 maxInactiveSeedingTime
: Number(origValues
[5])
45 // select default when orig values not passed. using double equals to compare string and int
46 if ((origValues
[0] === "")
47 || ((values
.ratioLimit
=== UseGlobalLimit
)
48 && (values
.seedingTimeLimit
=== UseGlobalLimit
)
49 && (values
.inactiveSeedingTimeLimit
=== UseGlobalLimit
))) {
51 setSelectedRadioValue("shareLimit", "default");
53 else if ((values
.maxRatio
=== NoLimit
) && (values
.maxSeedingTime
=== NoLimit
) && (values
.maxInactiveSeedingTime
=== NoLimit
)) {
54 setSelectedRadioValue("shareLimit", "none");
55 // TODO set input boxes to *global* max ratio and seeding time
58 setSelectedRadioValue("shareLimit", "custom");
59 if (values
.ratioLimit
>= 0) {
60 $("setRatio").checked
= true;
61 $("ratio").value
= values
.ratioLimit
;
63 if (values
.seedingTimeLimit
>= 0) {
64 $("setTotalMinutes").checked
= true;
65 $("totalMinutes").value
= values
.seedingTimeLimit
;
67 if (values
.inactiveSeedingTimeLimit
>= 0) {
68 $("setInactiveMinutes").checked
= true;
69 $("inactiveMinutes").value
= values
.inactiveSeedingTimeLimit
;
76 $("save").addEventListener("click", (e
) => {
83 const shareLimit
= getSelectedRadioValue("shareLimit");
84 let ratioLimitValue
= 0.00;
85 let seedingTimeLimitValue
= 0;
86 let inactiveSeedingTimeLimitValue
= 0;
88 if (shareLimit
=== "default") {
89 ratioLimitValue
= seedingTimeLimitValue
= inactiveSeedingTimeLimitValue
= UseGlobalLimit
;
91 else if (shareLimit
=== "none") {
92 ratioLimitValue
= seedingTimeLimitValue
= inactiveSeedingTimeLimitValue
= NoLimit
;
94 else if (shareLimit
=== "custom") {
95 ratioLimitValue
= $("setRatio").checked
? $("ratio").value
: -1;
96 seedingTimeLimitValue
= $("setTotalMinutes").checked
? $("totalMinutes").value
: -1;
97 inactiveSeedingTimeLimitValue
= $("setInactiveMinutes").checked
? $("inactiveMinutes").value
: -1;
103 fetch("api/v2/torrents/setShareLimits", {
105 body
: new URLSearchParams({
106 hashes
: hashesList
.join("|"),
107 ratioLimit
: ratioLimitValue
,
108 seedingTimeLimit
: seedingTimeLimitValue
,
109 inactiveSeedingTimeLimit
: inactiveSeedingTimeLimitValue
112 .then(async (response
) => {
116 window
.parent
.qBittorrent
.Client
.closeFrameWindow(window
);
121 const getSelectedRadioValue
= (name
) => {
122 const radios
= document
.getElementsByName(name
);
124 for (let i
= 0; i
< radios
.length
; ++i
) {
125 const radio
= radios
[i
];
131 const setSelectedRadioValue
= (name
, value
) => {
132 const radios
= document
.getElementsByName(name
);
134 for (let i
= 0; i
< radios
.length
; ++i
) {
135 const radio
= radios
[i
];
136 if (radio
.value
=== value
)
137 radio
.checked
= true;
141 const shareLimitChanged
= () => {
142 const customShareLimit
= getSelectedRadioValue("shareLimit") === "custom";
143 $("setRatio").disabled
= !customShareLimit
;
144 $("setTotalMinutes").disabled
= !customShareLimit
;
145 $("setInactiveMinutes").disabled
= !customShareLimit
;
149 $("save").disabled
= !isFormValid();
152 const enableInputBoxes
= () => {
153 $("ratio").disabled
= $("setRatio").disabled
|| !$("setRatio").checked
;
154 $("totalMinutes").disabled
= $("setTotalMinutes").disabled
|| !$("setTotalMinutes").checked
;
155 $("inactiveMinutes").disabled
= $("setInactiveMinutes").disabled
|| !$("setInactiveMinutes").checked
;
157 $("save").disabled
= !isFormValid();
160 const isFormValid
= () => {
161 return !((getSelectedRadioValue("shareLimit") === "custom") && !$("setRatio").checked
162 && !$("setTotalMinutes").checked
&& !$("setInactiveMinutes").checked
);
168 <div style=
"padding: 10px 10px 0px 10px;">
169 <input type=
"radio" name=
"shareLimit" id=
"default" value=
"default" onchange=
"shareLimitChanged()" checked
style=
"margin-bottom: 5px;"><label for=
"default">QBT_TR(Use global share limit)QBT_TR[CONTEXT=UpDownRatioDialog]
</label><br>
170 <input type=
"radio" name=
"shareLimit" id=
"shareLimitNone" value=
"none" onchange=
"shareLimitChanged()" style=
"margin-bottom: 5px;"><label for=
"shareLimitNone">QBT_TR(Set no share limit)QBT_TR[CONTEXT=UpDownRatioDialog]
</label><br>
171 <input type=
"radio" name=
"shareLimit" id=
"shareLimitCustom" value=
"custom" onchange=
"shareLimitChanged()" style=
"margin-bottom: 5px;"><label for=
"shareLimitCustom">QBT_TR(Set share limit to)QBT_TR[CONTEXT=UpDownRatioDialog]
</label><br>
173 <div style=
"margin-left: 40px; margin-bottom: 5px;">
174 <input type=
"checkbox" id=
"setRatio" class=
"shareLimitInput" onclick=
"enableInputBoxes()">
175 <label id=
"ratioLabel" for=
"setRatio">QBT_TR(ratio)QBT_TR[CONTEXT=UpDownRatioDialog]
</label>
176 <input type=
"number" id=
"ratio" value=
"0.00" step=
".01" min=
"0" max=
"9999" class=
"shareLimitInput" aria-labelledby=
"ratioLabel">
178 <div style=
"margin-left: 40px; margin-bottom: 5px;">
179 <input type=
"checkbox" id=
"setTotalMinutes" class=
"shareLimitInput" onclick=
"enableInputBoxes()">
180 <label id=
"totalMinutesLabel" for=
"setTotalMinutes">QBT_TR(total minutes)QBT_TR[CONTEXT=UpDownRatioDialog]
</label>
181 <input type=
"number" id=
"totalMinutes" value=
"0" step=
"1" min=
"0" max=
"525600" class=
"shareLimitInput" aria-labelledby=
"totalMinutesLabel">
183 <div style=
"margin-left: 40px; margin-bottom: 5px;">
184 <input type=
"checkbox" id=
"setInactiveMinutes" class=
"shareLimitInput" onclick=
"enableInputBoxes()">
185 <label id=
"inactiveMinutesLabel" for=
"setInactiveMinutes">QBT_TR(inactive minutes)QBT_TR[CONTEXT=UpDownRatioDialog]
</label>
186 <input type=
"number" id=
"inactiveMinutes" value=
"0" step=
"1" min=
"0" max=
"525600" class=
"shareLimitInput" aria-labelledby=
"inactiveMinutesLabel">
188 <div style=
"text-align: center; padding-top: 10px;">
189 <input type=
"button" value=
"QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id=
"save">