WebUI: enforce strict comparison operators

This commit is contained in:
Chocobo1 2024-04-21 14:11:21 +08:00
parent 75e2ae2fa0
commit 4945ed576a
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
19 changed files with 70 additions and 68 deletions

View File

@ -8,6 +8,7 @@
"html"
],
"rules": {
"eqeqeq": "error",
"no-mixed-operators": [
"error",
{

View File

@ -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',

View File

@ -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 {

View File

@ -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();
}

View File

@ -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

View File

@ -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');

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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');

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 {

View File

@ -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;
}

View File

@ -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
}

View File

@ -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',

View File

@ -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);
}

View File

@ -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();
};