From 75e2ae2fa030add8ae7b20f985343338b1ed094a Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 15 Apr 2024 13:46:02 +0800 Subject: [PATCH 1/3] WebUI: clean up code Use proper function for finding match. Use strict comparison operators. --- src/webui/www/private/newtag.html | 2 +- src/webui/www/private/scripts/dynamicTable.js | 41 ++++++++++--------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/webui/www/private/newtag.html b/src/webui/www/private/newtag.html index 4e67beaf7..6dbe02bfe 100644 --- a/src/webui/www/private/newtag.html +++ b/src/webui/www/private/newtag.html @@ -46,7 +46,7 @@ const verifyTagName = function(name) { if ((name === null) || (name === "")) return false; - if (name.indexOf(",") >= 0) { + if (name.includes(",")) { alert("QBT_TR(Invalid tag name)QBT_TR[CONTEXT=TagFilterWidget]"); return false; } diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index aa584c654..6b75d07de 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -639,7 +639,7 @@ window.qBittorrent.DynamicTable = (function() { this.deselectAll(); this.selectedRows = rowIds.slice(); this.tableBody.getElements('tr').each(function(tr) { - if (rowIds.indexOf(tr.rowId) > -1) + if (rowIds.includes(tr.rowId)) tr.addClass('selected'); }); }, @@ -1021,7 +1021,7 @@ window.qBittorrent.DynamicTable = (function() { if (td.getChildren('img').length > 0) { const img = td.getChildren('img')[0]; - if (img.src.indexOf(img_path) < 0) { + if (!img.src.includes(img_path)) { img.set('src', img_path); img.set('title', state); } @@ -1335,52 +1335,53 @@ window.qBittorrent.DynamicTable = (function() { const state = row['full_data'].state; const name = row['full_data'].name.toLowerCase(); let inactive = false; - let r; switch (filterName) { case 'downloading': - if ((state != 'downloading') && (state.indexOf('DL') === -1)) + if ((state !== 'downloading') && !state.includes('DL')) return false; break; case 'seeding': - if ((state != 'uploading') && (state != 'forcedUP') && (state != 'stalledUP') && (state != 'queuedUP') && (state != 'checkingUP')) + if ((state !== 'uploading') && (state !== 'forcedUP') && (state !== 'stalledUP') && (state !== 'queuedUP') && (state !== 'checkingUP')) return false; break; case 'completed': - if ((state != 'uploading') && (state.indexOf('UP') === -1)) + if ((state !== 'uploading') && !state.includes('UP')) return false; break; case 'stopped': - if (state.indexOf('stopped') === -1) + if (!state.includes('stopped')) return false; break; case 'running': - if (state.indexOf('stopped') > -1) + if (state.includes('stopped')) return false; break; case 'stalled': - if ((state != 'stalledUP') && (state != 'stalledDL')) + if ((state !== 'stalledUP') && (state !== 'stalledDL')) return false; break; case 'stalled_uploading': - if (state != 'stalledUP') + if (state !== 'stalledUP') return false; break; case 'stalled_downloading': - if (state != 'stalledDL') + if (state !== 'stalledDL') return false; break; case 'inactive': inactive = true; // fallthrough - case 'active': - if (state == 'stalledDL') + case 'active': { + let r; + if (state === 'stalledDL') r = (row['full_data'].upspeed > 0); else - r = (state == 'metaDL') || (state == 'forcedMetaDL') || (state == 'downloading') || (state == 'forcedDL') || (state == 'uploading') || (state == 'forcedUP'); - if (r == inactive) + r = (state === 'metaDL') || (state === 'forcedMetaDL') || (state === 'downloading') || (state === 'forcedDL') || (state === 'uploading') || (state === 'forcedUP'); + if (r === inactive) return false; break; + } case 'checking': if ((state !== 'checkingUP') && (state !== 'checkingDL') && (state !== 'checkingResumeData')) return false; @@ -1390,7 +1391,7 @@ window.qBittorrent.DynamicTable = (function() { return false; break; case 'errored': - if ((state != 'error') && (state != 'unknown') && (state != 'missingFiles')) + if ((state !== 'error') && (state !== 'unknown') && (state !== 'missingFiles')) return false; break; } @@ -1533,7 +1534,7 @@ window.qBittorrent.DynamicTable = (function() { this._this.selectRow(this.rowId); const row = this._this.rows.get(this.rowId); const state = row['full_data'].state; - if (state.indexOf('stopped') > -1) + if (state.includes('stopped')) startFN(); else stopFN(); @@ -2095,7 +2096,7 @@ window.qBittorrent.DynamicTable = (function() { const that = this; this.deselectAll(); this.tableBody.getElements('tr').each(function(tr) { - if (rowIds.indexOf(tr.rowId) > -1) { + if (rowIds.includes(tr.rowId)) { const node = that.getNode(tr.rowId); node.checked = 0; node.full_data.checked = 0; @@ -2704,7 +2705,7 @@ window.qBittorrent.DynamicTable = (function() { } if (td.getChildren('img').length > 0) { const img = td.getChildren('img')[0]; - if (img.src.indexOf(img_path) < 0) { + if (!img.src.includes(img_path)) { img.set('src', img_path); img.set('title', status); } @@ -3159,7 +3160,7 @@ window.qBittorrent.DynamicTable = (function() { const logLevels = window.qBittorrent.Log.getSelectedLevels(); if ((filterTerms.length > 0) || (logLevels.length < 4)) { for (let i = 0; i < rows.length; ++i) { - if (logLevels.indexOf(rows[i].full_data.type.toString()) == -1) + if (!logLevels.includes(rows[i].full_data.type.toString())) continue; if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(rows[i].full_data.message, filterTerms)) From 4945ed576a3a66cd50715c81e4ef49e6031c3c14 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 21 Apr 2024 14:11:21 +0800 Subject: [PATCH 2/3] WebUI: enforce strict comparison operators --- src/webui/www/.eslintrc.json | 1 + src/webui/www/private/downloadlimit.html | 2 +- src/webui/www/private/rename_files.html | 6 +-- src/webui/www/private/scripts/client.js | 10 ++-- src/webui/www/private/scripts/contextmenu.js | 12 ++--- src/webui/www/private/scripts/download.js | 10 ++-- src/webui/www/private/scripts/dynamicTable.js | 46 +++++++++---------- src/webui/www/private/scripts/mocha-init.js | 4 +- src/webui/www/private/scripts/progressbar.js | 2 +- src/webui/www/private/scripts/prop-files.js | 2 +- src/webui/www/private/scripts/prop-peers.js | 2 +- .../www/private/scripts/prop-trackers.js | 2 +- .../www/private/scripts/prop-webseeds.js | 2 +- src/webui/www/private/scripts/rename-files.js | 5 +- src/webui/www/private/scripts/speedslider.js | 12 ++--- src/webui/www/private/shareratio.html | 8 ++-- src/webui/www/private/uploadlimit.html | 2 +- src/webui/www/private/views/preferences.html | 8 ++-- src/webui/www/private/views/search.html | 2 +- 19 files changed, 70 insertions(+), 68 deletions(-) diff --git a/src/webui/www/.eslintrc.json b/src/webui/www/.eslintrc.json index 0c222b019..383e7113e 100644 --- a/src/webui/www/.eslintrc.json +++ b/src/webui/www/.eslintrc.json @@ -8,6 +8,7 @@ "html" ], "rules": { + "eqeqeq": "error", "no-mixed-operators": [ "error", { diff --git a/src/webui/www/private/downloadlimit.html b/src/webui/www/private/downloadlimit.html index 30ca841bf..e3398e7e0 100644 --- a/src/webui/www/private/downloadlimit.html +++ b/src/webui/www/private/downloadlimit.html @@ -30,7 +30,7 @@ const hashes = new URI().getData('hashes').split('|'); const setDlLimit = function() { const limit = $("dllimitUpdatevalue").value.toInt() * 1024; - if (hashes[0] == "global") { + if (hashes[0] === "global") { new Request({ url: 'api/v2/transfer/setDownloadLimit', method: 'post', diff --git a/src/webui/www/private/rename_files.html b/src/webui/www/private/rename_files.html index 947aa8ed7..241a41a85 100644 --- a/src/webui/www/private/rename_files.html +++ b/src/webui/www/private/rename_files.html @@ -30,7 +30,7 @@ ToggleSelection: function(element, ref) { const rowId = parseInt(element.get('data-row-id')); const row = bulkRenameFilesTable.getNode(rowId); - const checkState = row.checked == 1 ? 0 : 1; + const checkState = (row.checked === 1) ? 0 : 1; bulkRenameFilesTable.toggleNodeTreeCheckbox(rowId, checkState); bulkRenameFilesTable.updateGlobalCheckbox(); bulkRenameFilesTable.onRowSelectionChange(bulkRenameFilesTable.getSelectedRows()); @@ -285,10 +285,10 @@ $('renameOptions').addEvent('change', function(e) { const combobox = e.target; const replaceOperation = combobox.value; - if (replaceOperation == "Replace") { + if (replaceOperation === "Replace") { fileRenamer.replaceAll = false; } - else if (replaceOperation == "Replace All") { + else if (replaceOperation === "Replace All") { fileRenamer.replaceAll = true; } else { diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index ea84639f4..4d5fab9c9 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -211,7 +211,7 @@ window.addEventListener("DOMContentLoaded", function() { selected_category = hash; LocalPreferences.set('selected_category', selected_category); highlightSelectedCategory(); - if (typeof torrentsTable.tableBody != 'undefined') + if (typeof torrentsTable.tableBody !== 'undefined') updateMainData(); }; @@ -251,7 +251,7 @@ window.addEventListener("DOMContentLoaded", function() { selected_filter = f; LocalPreferences.set('selected_filter', f); // Reload torrents - if (typeof torrentsTable.tableBody != 'undefined') + if (typeof torrentsTable.tableBody !== 'undefined') updateMainData(); }; @@ -927,7 +927,7 @@ window.addEventListener("DOMContentLoaded", function() { break; } - if (queueing_enabled != serverState.queueing) { + if (queueing_enabled !== serverState.queueing) { queueing_enabled = serverState.queueing; torrentsTable.columns['priority'].force_hide = !queueing_enabled; torrentsTable.updateColumn('priority'); @@ -949,12 +949,12 @@ window.addEventListener("DOMContentLoaded", function() { } } - if (alternativeSpeedLimits != serverState.use_alt_speed_limits) { + if (alternativeSpeedLimits !== serverState.use_alt_speed_limits) { alternativeSpeedLimits = serverState.use_alt_speed_limits; updateAltSpeedIcon(alternativeSpeedLimits); } - if (useSubcategories != serverState.use_subcategories) { + if (useSubcategories !== serverState.use_subcategories) { useSubcategories = serverState.use_subcategories; updateCategoryList(); } diff --git a/src/webui/www/private/scripts/contextmenu.js b/src/webui/www/private/scripts/contextmenu.js index 56bda526e..f6ec8e141 100644 --- a/src/webui/www/private/scripts/contextmenu.js +++ b/src/webui/www/private/scripts/contextmenu.js @@ -240,7 +240,7 @@ window.qBittorrent.ContextMenu = (function() { //show menu show: function(trigger) { - if (lastShownContextMenu && (lastShownContextMenu != this)) + if (lastShownContextMenu && (lastShownContextMenu !== this)) lastShownContextMenu.hide(); this.fx.start(1); this.fireEvent('show'); @@ -265,7 +265,7 @@ window.qBittorrent.ContextMenu = (function() { }, getItemChecked: function(item) { - return '0' != this.menu.getElement('a[href$=' + item + ']').firstChild.style.opacity; + return this.menu.getElement('a[href$=' + item + ']').firstChild.style.opacity !== '0'; }, //hide an item @@ -333,12 +333,12 @@ window.qBittorrent.ContextMenu = (function() { else there_are_f_l_piece_prio = true; - if (data['progress'] != 1.0) // not downloaded + if (data['progress'] !== 1.0) // not downloaded all_are_downloaded = false; else if (data['super_seeding'] !== true) all_are_super_seeding = false; - if ((data['state'] != 'stoppedUP') && (data['state'] != 'stoppedDL')) + if ((data['state'] !== 'stoppedUP') && (data['state'] !== 'stoppedDL')) all_are_stopped = false; else there_are_stopped = true; @@ -361,9 +361,9 @@ window.qBittorrent.ContextMenu = (function() { }); // hide renameFiles when more than 1 torrent is selected - if (selectedRows.length == 1) { + if (selectedRows.length === 1) { const data = torrentsTable.rows.get(selectedRows[0]).full_data; - let metadata_downloaded = !((data['state'] == 'metaDL') || (data['state'] == 'forcedMetaDL') || (data['total_size'] == -1)); + let metadata_downloaded = !((data['state'] === 'metaDL') || (data['state'] === 'forcedMetaDL') || (data['total_size'] === -1)); // hide renameFiles when metadata hasn't been downloaded yet metadata_downloaded diff --git a/src/webui/www/private/scripts/download.js b/src/webui/www/private/scripts/download.js index b18ff23a1..5e9b53779 100644 --- a/src/webui/www/private/scripts/download.js +++ b/src/webui/www/private/scripts/download.js @@ -66,7 +66,7 @@ window.qBittorrent.Download = (function() { $('startTorrent').checked = !pref.add_stopped_enabled; $('addToTopOfQueue').checked = pref.add_to_top_of_queue; - if (pref.auto_tmm_enabled == 1) { + if (pref.auto_tmm_enabled === 1) { $('autoTMM').selectedIndex = 1; $('savepath').disabled = true; } @@ -96,12 +96,12 @@ window.qBittorrent.Download = (function() { }; const changeCategorySelect = function(item) { - if (item.value == "\\other") { + if (item.value === "\\other") { item.nextElementSibling.hidden = false; item.nextElementSibling.value = ""; item.nextElementSibling.select(); - if ($('autoTMM').selectedIndex == 1) + if ($('autoTMM').selectedIndex === 1) $('savepath').value = defaultSavePath; } else { @@ -109,7 +109,7 @@ window.qBittorrent.Download = (function() { const text = item.options[item.selectedIndex].textContent; item.nextElementSibling.value = text; - if ($('autoTMM').selectedIndex == 1) { + if ($('autoTMM').selectedIndex === 1) { const categoryName = item.value; const category = categories[categoryName]; let savePath = defaultSavePath; @@ -121,7 +121,7 @@ window.qBittorrent.Download = (function() { }; const changeTMM = function(item) { - if (item.selectedIndex == 1) { + if (item.selectedIndex === 1) { $('savepath').disabled = true; const categorySelect = $('categorySelect'); diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index 6b75d07de..8223954d2 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -112,7 +112,7 @@ window.qBittorrent.DynamicTable = (function() { let n = 2; // is panel vertical scrollbar visible or does panel content not fit? - while (((panel.clientWidth != panel.offsetWidth) || (panel.clientHeight != panel.scrollHeight)) && (n > 0)) { + while (((panel.clientWidth !== panel.offsetWidth) || (panel.clientHeight !== panel.scrollHeight)) && (n > 0)) { --n; h -= 0.5; $(this.dynamicTableDivId).style.height = h + 'px'; @@ -136,7 +136,7 @@ window.qBittorrent.DynamicTable = (function() { } const panel = tableDiv.getParent('.panel'); - if (this.lastPanelHeight != panel.getBoundingClientRect().height) { + if (this.lastPanelHeight !== panel.getBoundingClientRect().height) { this.lastPanelHeight = panel.getBoundingClientRect().height; panel.fireEvent('resize'); } @@ -470,7 +470,7 @@ window.qBittorrent.DynamicTable = (function() { th.setAttribute('style', 'width: ' + this.columns[i].width + 'px;' + this.columns[i].style); th.columnName = this.columns[i].name; th.addClass('column_' + th.columnName); - if ((this.columns[i].visible == '0') || this.columns[i].force_hide) + if ((this.columns[i].visible === '0') || this.columns[i].force_hide) th.addClass('invisible'); else th.removeClass('invisible'); @@ -479,14 +479,14 @@ window.qBittorrent.DynamicTable = (function() { getColumnPos: function(columnName) { for (let i = 0; i < this.columns.length; ++i) - if (this.columns[i].name == columnName) + if (this.columns[i].name === columnName) return i; return -1; }, updateColumn: function(columnName) { const pos = this.getColumnPos(columnName); - const visible = ((this.columns[pos].visible != '0') && !this.columns[pos].force_hide); + const visible = ((this.columns[pos].visible !== '0') && !this.columns[pos].force_hide); const ths = this.hiddenTableHeader.getElements('th'); const fths = this.fixedTableHeader.getElements('th'); const trs = this.tableBody.getElements('tr'); @@ -521,7 +521,7 @@ window.qBittorrent.DynamicTable = (function() { * @param {string|null} reverse defaults to implementation-specific behavior when not specified. Should only be passed when restoring previous state. */ setSortedColumn: function(column, reverse = null) { - if (column != this.sortedColumn) { + if (column !== this.sortedColumn) { const oldColumn = this.sortedColumn; this.sortedColumn = column; this.reverseSort = reverse ?? '0'; @@ -540,7 +540,7 @@ window.qBittorrent.DynamicTable = (function() { setSortedColumnIcon: function(newColumn, oldColumn, isReverse) { const getCol = function(headerDivId, colName) { const colElem = $$("#" + headerDivId + " .column_" + colName); - if (colElem.length == 1) + if (colElem.length === 1) return colElem[0]; return null; }; @@ -623,7 +623,7 @@ window.qBittorrent.DynamicTable = (function() { let select = false; const that = this; this.tableBody.getElements('tr').each(function(tr) { - if ((tr.rowId == rowId1) || (tr.rowId == rowId2)) { + if ((tr.rowId === rowId1) || (tr.rowId === rowId2)) { select = !select; that.selectedRows.push(tr.rowId); } @@ -700,7 +700,7 @@ window.qBittorrent.DynamicTable = (function() { getTrByRowId: function(rowId) { const trs = this.tableBody.getElements('tr'); for (let i = 0; i < trs.length; ++i) - if (trs[i].rowId == rowId) + if (trs[i].rowId === rowId) return trs[i]; return null; }, @@ -720,9 +720,9 @@ window.qBittorrent.DynamicTable = (function() { const rowId = rows[rowPos]['rowId']; let tr_found = false; for (let j = rowPos; j < trs.length; ++j) - if (trs[j]['rowId'] == rowId) { + if (trs[j]['rowId'] === rowId) { tr_found = true; - if (rowPos == j) + if (rowPos === j) break; trs[j].inject(trs[rowPos], 'before'); const tmpTr = trs[j]; @@ -759,7 +759,7 @@ window.qBittorrent.DynamicTable = (function() { else this._this.selectRow(this.rowId); } - else if (e.shift && (this._this.selectedRows.length == 1)) { + else if (e.shift && (this._this.selectedRows.length === 1)) { // Shift key was pressed this._this.selectRows(this._this.getSelectedRowId(), this.rowId); } @@ -791,7 +791,7 @@ window.qBittorrent.DynamicTable = (function() { for (let k = 0; k < this.columns.length; ++k) { const td = new Element('td'); - if ((this.columns[k].visible == '0') || this.columns[k].force_hide) + if ((this.columns[k].visible === '0') || this.columns[k].force_hide) td.addClass('invisible'); td.injectInside(tr); } @@ -1141,7 +1141,7 @@ window.qBittorrent.DynamicTable = (function() { this.columns['progress'].updateTd = function(td, row) { const progress = this.getRowValue(row); let progressFormatted = (progress * 100).round(1); - if ((progressFormatted == 100.0) && (progress != 1.0)) + if ((progressFormatted === 100.0) && (progress !== 1.0)) progressFormatted = 99.9; if (td.getChildren('div').length > 0) { @@ -1150,7 +1150,7 @@ window.qBittorrent.DynamicTable = (function() { td.resized = false; div.setWidth(ProgressColumnWidth - 5); } - if (div.getValue() != progressFormatted) + if (div.getValue() !== progressFormatted) div.setValue(progressFormatted); } else { @@ -1181,7 +1181,7 @@ window.qBittorrent.DynamicTable = (function() { const num_seeds = this.getRowValue(row, 0); const num_complete = this.getRowValue(row, 1); let value = num_seeds; - if (num_complete != -1) + if (num_complete !== -1) value += ' (' + num_complete + ')'; td.set('text', value); td.set('title', value); @@ -1616,7 +1616,7 @@ window.qBittorrent.DynamicTable = (function() { const b = ip2.split("."); for (let i = 0; i < 4; ++i) { - if (a[i] != b[i]) + if (a[i] !== b[i]) return a[i] - b[i]; } @@ -1633,7 +1633,7 @@ window.qBittorrent.DynamicTable = (function() { this.columns['progress'].updateTd = function(td, row) { const progress = this.getRowValue(row); let progressFormatted = (progress * 100).round(1); - if ((progressFormatted == 100.0) && (progress != 1.0)) + if ((progressFormatted === 100.0) && (progress !== 1.0)) progressFormatted = 99.9; progressFormatted += "%"; td.set('text', progressFormatted); @@ -1901,7 +1901,7 @@ window.qBittorrent.DynamicTable = (function() { getSelectedRows: function() { const nodes = this.fileTree.toArray(); - return nodes.filter(x => x.checked == 0); + return nodes.filter(x => x.checked === 0); }, initColumns: function() { @@ -1952,7 +1952,7 @@ window.qBittorrent.DynamicTable = (function() { node.checked = checkState; node.full_data.checked = checkState; const checkbox = $(`cbRename${rowId}`); - checkbox.checked = node.checked == 0; + checkbox.checked = node.checked === 0; checkbox.state = checkbox.checked ? "checked" : "unchecked"; for (let i = 0; i < node.children.length; ++i) { @@ -2021,7 +2021,7 @@ window.qBittorrent.DynamicTable = (function() { that.onRowSelectionChange(node); e.stopPropagation(); }); - checkbox.checked = value == 0; + checkbox.checked = (value === 0); checkbox.state = checkbox.checked ? "checked" : "unchecked"; checkbox.indeterminate = false; td.adopt(treeImg, checkbox); @@ -3176,7 +3176,7 @@ window.qBittorrent.DynamicTable = (function() { filteredRows.sort(function(row1, row2) { const column = this.columns[this.sortedColumn]; const res = column.compareRows(row1, row2); - return (this.reverseSort == '0') ? res : -res; + return (this.reverseSort === '0') ? res : -res; }.bind(this)); return filteredRows; @@ -3239,7 +3239,7 @@ window.qBittorrent.DynamicTable = (function() { filteredRows.sort(function(row1, row2) { const column = this.columns[this.sortedColumn]; const res = column.compareRows(row1, row2); - return (this.reverseSort == '0') ? res : -res; + return (this.reverseSort === '0') ? res : -res; }.bind(this)); return filteredRows; diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js index bc429eff3..e010250e1 100644 --- a/src/webui/www/private/scripts/mocha-init.js +++ b/src/webui/www/private/scripts/mocha-init.js @@ -506,7 +506,7 @@ const initializeWindows = function() { renameFN = function() { const hashes = torrentsTable.selectedRowsIds(); - if (hashes.length == 1) { + if (hashes.length === 1) { const hash = hashes[0]; const row = torrentsTable.rows[hash]; if (row) { @@ -529,7 +529,7 @@ const initializeWindows = function() { renameFilesFN = function() { const hashes = torrentsTable.selectedRowsIds(); - if (hashes.length == 1) { + if (hashes.length === 1) { const hash = hashes[0]; const row = torrentsTable.rows[hash]; if (row) { diff --git a/src/webui/www/private/scripts/progressbar.js b/src/webui/www/private/scripts/progressbar.js index 17c296f5d..e42fef110 100644 --- a/src/webui/www/private/scripts/progressbar.js +++ b/src/webui/www/private/scripts/progressbar.js @@ -52,7 +52,7 @@ window.qBittorrent.ProgressBar = (function() { 'lightbg': 'var(--color-background-default)', 'lightfg': 'var(--color-text-default)' }; - if (parameters && ($type(parameters) == 'object')) + if (parameters && ($type(parameters) === 'object')) $extend(vals, parameters); if (vals.height < 12) vals.height = 12; diff --git a/src/webui/www/private/scripts/prop-files.js b/src/webui/www/private/scripts/prop-files.js index 09bfbfe97..7be42525b 100644 --- a/src/webui/www/private/scripts/prop-files.js +++ b/src/webui/www/private/scripts/prop-files.js @@ -350,7 +350,7 @@ window.qBittorrent.PropFiles = (function() { return; } let loadedNewTorrent = false; - if (new_hash != current_hash) { + if (new_hash !== current_hash) { torrentFilesTable.clear(); current_hash = new_hash; loadedNewTorrent = true; diff --git a/src/webui/www/private/scripts/prop-peers.js b/src/webui/www/private/scripts/prop-peers.js index 5c893d894..f9679783b 100644 --- a/src/webui/www/private/scripts/prop-peers.js +++ b/src/webui/www/private/scripts/prop-peers.js @@ -94,7 +94,7 @@ window.qBittorrent.PropPeers = (function() { torrentPeersTable.altRow(); if (response['show_flags']) { - if (show_flags != response['show_flags']) { + if (show_flags !== response['show_flags']) { show_flags = response['show_flags']; torrentPeersTable.columns['country'].force_hide = !show_flags; torrentPeersTable.updateColumn('country'); diff --git a/src/webui/www/private/scripts/prop-trackers.js b/src/webui/www/private/scripts/prop-trackers.js index 6b6ff5dbf..e27857ffd 100644 --- a/src/webui/www/private/scripts/prop-trackers.js +++ b/src/webui/www/private/scripts/prop-trackers.js @@ -57,7 +57,7 @@ window.qBittorrent.PropTrackers = (function() { loadTrackersDataTimer = loadTrackersData.delay(10000); return; } - if (new_hash != current_hash) { + if (new_hash !== current_hash) { torrentTrackersTable.clear(); current_hash = new_hash; } diff --git a/src/webui/www/private/scripts/prop-webseeds.js b/src/webui/www/private/scripts/prop-webseeds.js index cadd8ab9e..d2bacaef9 100644 --- a/src/webui/www/private/scripts/prop-webseeds.js +++ b/src/webui/www/private/scripts/prop-webseeds.js @@ -106,7 +106,7 @@ window.qBittorrent.PropWebseeds = (function() { loadWebSeedsDataTimer = loadWebSeedsData.delay(10000); return; } - if (new_hash != current_hash) { + if (new_hash !== current_hash) { wsTable.removeAllRows(); current_hash = new_hash; } diff --git a/src/webui/www/private/scripts/rename-files.js b/src/webui/www/private/scripts/rename-files.js index 0269bfefb..a1d5493c2 100644 --- a/src/webui/www/private/scripts/rename-files.js +++ b/src/webui/www/private/scripts/rename-files.js @@ -61,13 +61,14 @@ window.qBittorrent.MultiRename = (function() { let matches = []; do { result = regex.exec(str); + if (result === null) + break; - if (result == null) { break; } matches.push(result); // regex assertions don't modify lastIndex, // so we need to explicitly break out to prevent infinite loop - if (lastIndex == regex.lastIndex) { + if (lastIndex === regex.lastIndex) { break; } else { diff --git a/src/webui/www/private/scripts/speedslider.js b/src/webui/www/private/scripts/speedslider.js index fe14cfc02..d93f3ef24 100644 --- a/src/webui/www/private/scripts/speedslider.js +++ b/src/webui/www/private/scripts/speedslider.js @@ -44,7 +44,7 @@ MochaUI.extend({ maximum = tmp / 1024.0; } else { - if (hashes[0] == "global") + if (hashes[0] === "global") maximum = 10000; else maximum = 1000; @@ -52,7 +52,7 @@ MochaUI.extend({ } // Get torrents upload limit // And create slider - if (hashes[0] == 'global') { + if (hashes[0] === 'global') { let up_limit = maximum; if (up_limit < 0) up_limit = 0; @@ -93,7 +93,7 @@ MochaUI.extend({ if (data) { let up_limit = data[hashes[0]]; for (const key in data) - if (up_limit != data[key]) { + if (up_limit !== data[key]) { up_limit = 0; break; } @@ -147,7 +147,7 @@ MochaUI.extend({ maximum = tmp / 1024.0; } else { - if (hashes[0] == "global") + if (hashes[0] === "global") maximum = 10000; else maximum = 1000; @@ -155,7 +155,7 @@ MochaUI.extend({ } // Get torrents download limit // And create slider - if (hashes[0] == 'global') { + if (hashes[0] === 'global') { let dl_limit = maximum; if (dl_limit < 0) dl_limit = 0; @@ -196,7 +196,7 @@ MochaUI.extend({ if (data) { let dl_limit = data[hashes[0]]; for (const key in data) - if (dl_limit != data[key]) { + if (dl_limit !== data[key]) { dl_limit = 0; break; } diff --git a/src/webui/www/private/shareratio.html b/src/webui/www/private/shareratio.html index c3c2df90d..c42515d1c 100644 --- a/src/webui/www/private/shareratio.html +++ b/src/webui/www/private/shareratio.html @@ -47,13 +47,13 @@ // select default when orig values not passed. using double equals to compare string and int if ((origValues[0] === "") - || ((values.ratioLimit == UseGlobalLimit) - && (values.seedingTimeLimit == UseGlobalLimit) - && (values.inactiveSeedingTimeLimit == UseGlobalLimit))) { + || ((values.ratioLimit === UseGlobalLimit) + && (values.seedingTimeLimit === UseGlobalLimit) + && (values.inactiveSeedingTimeLimit === UseGlobalLimit))) { // use default option setSelectedRadioValue('shareLimit', 'default'); } - else if ((values.maxRatio == NoLimit) && (values.maxSeedingTime == NoLimit) && (values.maxInactiveSeedingTime == NoLimit)) { + else if ((values.maxRatio === NoLimit) && (values.maxSeedingTime === NoLimit) && (values.maxInactiveSeedingTime === NoLimit)) { setSelectedRadioValue('shareLimit', 'none'); // TODO set input boxes to *global* max ratio and seeding time } diff --git a/src/webui/www/private/uploadlimit.html b/src/webui/www/private/uploadlimit.html index df9d3772d..87d0db7b6 100644 --- a/src/webui/www/private/uploadlimit.html +++ b/src/webui/www/private/uploadlimit.html @@ -30,7 +30,7 @@ const hashes = new URI().getData('hashes').split('|'); const setUpLimit = function() { const limit = $("uplimitUpdatevalue").value.toInt() * 1024; - if (hashes[0] == "global") { + if (hashes[0] === "global") { new Request({ url: 'api/v2/transfer/setUploadLimit', method: 'post', diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index aaee0d682..f4a8ce761 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1893,7 +1893,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD }; const registerDynDns = function() { - if ($('dyndns_select').getProperty('value').toInt() == 1) { + if ($('dyndns_select').getProperty('value').toInt() === 1) { window.open("http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html", "NO-IP Registration"); } else { @@ -1910,7 +1910,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD const time_padding = function(val) { let ret = val.toString(); - if (ret.length == 1) + if (ret.length === 1) ret = '0' + ret; return ret; }; @@ -2041,7 +2041,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD $('temppath_checkbox').setProperty('checked', pref.temp_path_enabled); $('temppath_text').setProperty('value', pref.temp_path); updateTempDirEnabled(); - if (pref.export_dir != '') { + if (pref.export_dir !== '') { $('exportdir_checkbox').setProperty('checked', true); $('exportdir_text').setProperty('value', pref.export_dir); } @@ -2050,7 +2050,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD $('exportdir_text').setProperty('value', ''); } updateExportDirEnabled(); - if (pref.export_dir_fin != '') { + if (pref.export_dir_fin !== '') { $('exportdirfin_checkbox').setProperty('checked', true); $('exportdirfin_text').setProperty('value', pref.export_dir_fin); } diff --git a/src/webui/www/private/views/search.html b/src/webui/www/private/views/search.html index df399f1cb..8f9df7734 100644 --- a/src/webui/www/private/views/search.html +++ b/src/webui/www/private/views/search.html @@ -913,7 +913,7 @@ }; const searchSizeFilterPrefixChanged = function() { - if (($('searchMinSizeFilter').get('value') != 0) || ($('searchMaxSizeFilter').get('value') != 0)) + if ((Number($('searchMinSizeFilter').get('value')) !== 0) || (Number($('searchMaxSizeFilter').get('value')) !== 0)) searchSizeFilterChanged(); }; From 1c7ecb7371c2d6f4423b537add0c9e97cf5aa183 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 21 Apr 2024 15:32:36 +0800 Subject: [PATCH 3/3] WebUI: migrate away from MooTools deprecated functions https://mootools.net/core/docs/1.6.0/Core/Core#Deprecated-Functions --- src/webui/www/private/scripts/client.js | 11 +++-------- src/webui/www/private/scripts/piecesbar.js | 6 +++--- src/webui/www/private/scripts/progressbar.js | 8 ++++---- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index 4d5fab9c9..5b612aeea 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -130,8 +130,8 @@ let toggleFilterDisplay = function() {}; window.addEventListener("DOMContentLoaded", function() { const saveColumnSizes = function() { const filters_width = $('Filters').getSize().x; - const properties_height_rel = $('propertiesPanel').getSize().y / Window.getSize().y; LocalPreferences.set('filters_width', filters_width); + const properties_height_rel = $('propertiesPanel').getSize().y / Window.getSize().y; LocalPreferences.set('properties_height_rel', properties_height_rel); }; @@ -149,11 +149,7 @@ window.addEventListener("DOMContentLoaded", function() { MochaUI.Desktop.initialize(); const buildTransfersTab = function() { - let filt_w = LocalPreferences.get('filters_width'); - if ($defined(filt_w)) - filt_w = filt_w.toInt(); - else - filt_w = 120; + const filt_w = Number(LocalPreferences.get('filters_width', 120)); new MochaUI.Column({ id: 'filtersColumn', placement: 'left', @@ -161,7 +157,6 @@ window.addEventListener("DOMContentLoaded", function() { width: filt_w, resizeLimit: [1, 300] }); - new MochaUI.Column({ id: 'mainColumn', placement: 'main' @@ -1350,7 +1345,7 @@ window.addEventListener("DOMContentLoaded", function() { height: null }); let prop_h = LocalPreferences.get('properties_height_rel'); - if ($defined(prop_h)) + if (prop_h !== null) prop_h = prop_h.toFloat() * Window.getSize().y; else prop_h = Window.getSize().y / 2.0; diff --git a/src/webui/www/private/scripts/piecesbar.js b/src/webui/www/private/scripts/piecesbar.js index ae98dda00..d5835217c 100644 --- a/src/webui/www/private/scripts/piecesbar.js +++ b/src/webui/www/private/scripts/piecesbar.js @@ -60,8 +60,8 @@ window.qBittorrent.PiecesBar = (() => { 'borderColor': 'var(--color-border-default)' }; - if (parameters && ($type(parameters) === 'object')) - $extend(vals, parameters); + if (parameters && (typeOf(parameters) === 'object')) + Object.append(vals, parameters); vals.height = Math.max(vals.height, 12); const obj = new Element('div', { @@ -73,7 +73,7 @@ window.qBittorrent.PiecesBar = (() => { } }); obj.vals = vals; - obj.vals.pieces = $pick(pieces, []); + obj.vals.pieces = [pieces, []].pick(); obj.vals.canvas = new Element('canvas', { 'id': vals.id + '_canvas', diff --git a/src/webui/www/private/scripts/progressbar.js b/src/webui/www/private/scripts/progressbar.js index e42fef110..676ba435a 100644 --- a/src/webui/www/private/scripts/progressbar.js +++ b/src/webui/www/private/scripts/progressbar.js @@ -44,7 +44,7 @@ window.qBittorrent.ProgressBar = (function() { initialize: function(value, parameters) { const vals = { 'id': 'progressbar_' + (ProgressBars++), - 'value': $pick(value, 0), + 'value': [value, 0].pick(), 'width': 0, 'height': 0, 'darkbg': 'var(--color-background-blue)', @@ -52,8 +52,8 @@ window.qBittorrent.ProgressBar = (function() { 'lightbg': 'var(--color-background-default)', 'lightfg': 'var(--color-text-default)' }; - if (parameters && ($type(parameters) === 'object')) - $extend(vals, parameters); + if (parameters && (typeOf(parameters) === 'object')) + Object.append(vals, parameters); if (vals.height < 12) vals.height = 12; const obj = new Element('div', { @@ -68,7 +68,7 @@ window.qBittorrent.ProgressBar = (function() { } }); obj.vals = vals; - obj.vals.value = $pick(value, 0); // Fix by Chris + obj.vals.value = [value, 0].pick(); obj.vals.dark = new Element('div', { 'id': vals.id + '_dark', 'class': 'progressbar_dark',