WebUI: use native function to convert to numbers

Also replace `parseInt()` since `Number()` behavior is more intuitive.

PR #21831.
This commit is contained in:
Chocobo1
2024-11-16 15:41:20 +08:00
committed by GitHub
parent ede08f3845
commit f73f31619d
14 changed files with 77 additions and 76 deletions

View File

@@ -184,7 +184,7 @@ window.qBittorrent.DynamicTable ??= (() => {
const onStart = function(el, event) {
if (this.canResize) {
this.currentHeaderAction = "resize";
this.startWidth = parseInt(this.resizeTh.style.width, 10);
this.startWidth = Number(this.resizeTh.style.width);
}
else {
this.currentHeaderAction = "drag";
@@ -3259,7 +3259,7 @@ window.qBittorrent.DynamicTable ??= (() => {
this.columns["type"].updateTd = function(td, row) {
// Type of the message: Log::NORMAL: 1, Log::INFO: 2, Log::WARNING: 4, Log::CRITICAL: 8
let logLevel, addClass;
switch (this.getRowValue(row).toInt()) {
switch (Number(this.getRowValue(row))) {
case 1:
logLevel = "QBT_TR(Normal)QBT_TR[CONTEXT=ExecutionLogWidget]";
addClass = "logNormal";

View File

@@ -1011,7 +1011,7 @@ const initializeWindows = () => {
};
deleteTrackerFN = (trackerHash) => {
const trackerHashInt = Number.parseInt(trackerHash, 10);
const trackerHashInt = Number(trackerHash);
if ((trackerHashInt === TRACKERS_ALL) || (trackerHashInt === TRACKERS_TRACKERLESS))
return;

View File

@@ -127,7 +127,7 @@ window.qBittorrent.ProgressBar ??= (() => {
this.vals.dark.textContent = displayedValue;
this.vals.light.textContent = displayedValue;
const r = parseInt((this.vals.width * (value / 100)), 10);
const r = Number(this.vals.width * (value / 100));
this.vals.dark.style.clipPath = `inset(0 calc(100% - ${r}px) 0 0)`;
this.vals.light.style.clipPath = `inset(0 0 0 ${r}px)`;
}

View File

@@ -197,7 +197,7 @@ window.qBittorrent.PropFiles ??= (() => {
const updatePriorityCombo = (id, selectedPriority) => {
const combobox = $("comboPrio" + id);
if (parseInt(combobox.value, 10) !== selectedPriority)
if (Number(combobox.value) !== selectedPriority)
selectComboboxPriority(combobox, selectedPriority);
};
@@ -205,7 +205,7 @@ window.qBittorrent.PropFiles ??= (() => {
const options = combobox.options;
for (let i = 0; i < options.length; ++i) {
const option = options[i];
if (parseInt(option.value, 10) === priority)
if (Number(option.value) === priority)
option.selected = true;
else
option.selected = false;

View File

@@ -39,7 +39,7 @@ MochaUI.extend({
data: {},
onSuccess: (data) => {
if (data) {
const tmp = data.toInt();
const tmp = Number(data);
if (tmp > 0) {
maximum = tmp / 1024.0;
}
@@ -143,7 +143,7 @@ MochaUI.extend({
data: {},
onSuccess: (data) => {
if (data) {
const tmp = data.toInt();
const tmp = Number(data);
if (tmp > 0) {
maximum = tmp / 1024.0;
}