WebUI: clean up code

Use proper function for finding match.
Use strict comparison operators.
This commit is contained in:
Chocobo1 2024-04-15 13:46:02 +08:00
parent d7cded54e4
commit 75e2ae2fa0
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
2 changed files with 22 additions and 21 deletions

View file

@ -46,7 +46,7 @@
const verifyTagName = function(name) { const verifyTagName = function(name) {
if ((name === null) || (name === "")) if ((name === null) || (name === ""))
return false; return false;
if (name.indexOf(",") >= 0) { if (name.includes(",")) {
alert("QBT_TR(Invalid tag name)QBT_TR[CONTEXT=TagFilterWidget]"); alert("QBT_TR(Invalid tag name)QBT_TR[CONTEXT=TagFilterWidget]");
return false; return false;
} }

View file

@ -639,7 +639,7 @@ window.qBittorrent.DynamicTable = (function() {
this.deselectAll(); this.deselectAll();
this.selectedRows = rowIds.slice(); this.selectedRows = rowIds.slice();
this.tableBody.getElements('tr').each(function(tr) { this.tableBody.getElements('tr').each(function(tr) {
if (rowIds.indexOf(tr.rowId) > -1) if (rowIds.includes(tr.rowId))
tr.addClass('selected'); tr.addClass('selected');
}); });
}, },
@ -1021,7 +1021,7 @@ window.qBittorrent.DynamicTable = (function() {
if (td.getChildren('img').length > 0) { if (td.getChildren('img').length > 0) {
const img = td.getChildren('img')[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('src', img_path);
img.set('title', state); img.set('title', state);
} }
@ -1335,52 +1335,53 @@ window.qBittorrent.DynamicTable = (function() {
const state = row['full_data'].state; const state = row['full_data'].state;
const name = row['full_data'].name.toLowerCase(); const name = row['full_data'].name.toLowerCase();
let inactive = false; let inactive = false;
let r;
switch (filterName) { switch (filterName) {
case 'downloading': case 'downloading':
if ((state != 'downloading') && (state.indexOf('DL') === -1)) if ((state !== 'downloading') && !state.includes('DL'))
return false; return false;
break; break;
case 'seeding': 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; return false;
break; break;
case 'completed': case 'completed':
if ((state != 'uploading') && (state.indexOf('UP') === -1)) if ((state !== 'uploading') && !state.includes('UP'))
return false; return false;
break; break;
case 'stopped': case 'stopped':
if (state.indexOf('stopped') === -1) if (!state.includes('stopped'))
return false; return false;
break; break;
case 'running': case 'running':
if (state.indexOf('stopped') > -1) if (state.includes('stopped'))
return false; return false;
break; break;
case 'stalled': case 'stalled':
if ((state != 'stalledUP') && (state != 'stalledDL')) if ((state !== 'stalledUP') && (state !== 'stalledDL'))
return false; return false;
break; break;
case 'stalled_uploading': case 'stalled_uploading':
if (state != 'stalledUP') if (state !== 'stalledUP')
return false; return false;
break; break;
case 'stalled_downloading': case 'stalled_downloading':
if (state != 'stalledDL') if (state !== 'stalledDL')
return false; return false;
break; break;
case 'inactive': case 'inactive':
inactive = true; inactive = true;
// fallthrough // fallthrough
case 'active': case 'active': {
if (state == 'stalledDL') let r;
if (state === 'stalledDL')
r = (row['full_data'].upspeed > 0); r = (row['full_data'].upspeed > 0);
else else
r = (state == 'metaDL') || (state == 'forcedMetaDL') || (state == 'downloading') || (state == 'forcedDL') || (state == 'uploading') || (state == 'forcedUP'); r = (state === 'metaDL') || (state === 'forcedMetaDL') || (state === 'downloading') || (state === 'forcedDL') || (state === 'uploading') || (state === 'forcedUP');
if (r == inactive) if (r === inactive)
return false; return false;
break; break;
}
case 'checking': case 'checking':
if ((state !== 'checkingUP') && (state !== 'checkingDL') && (state !== 'checkingResumeData')) if ((state !== 'checkingUP') && (state !== 'checkingDL') && (state !== 'checkingResumeData'))
return false; return false;
@ -1390,7 +1391,7 @@ window.qBittorrent.DynamicTable = (function() {
return false; return false;
break; break;
case 'errored': case 'errored':
if ((state != 'error') && (state != 'unknown') && (state != 'missingFiles')) if ((state !== 'error') && (state !== 'unknown') && (state !== 'missingFiles'))
return false; return false;
break; break;
} }
@ -1533,7 +1534,7 @@ window.qBittorrent.DynamicTable = (function() {
this._this.selectRow(this.rowId); this._this.selectRow(this.rowId);
const row = this._this.rows.get(this.rowId); const row = this._this.rows.get(this.rowId);
const state = row['full_data'].state; const state = row['full_data'].state;
if (state.indexOf('stopped') > -1) if (state.includes('stopped'))
startFN(); startFN();
else else
stopFN(); stopFN();
@ -2095,7 +2096,7 @@ window.qBittorrent.DynamicTable = (function() {
const that = this; const that = this;
this.deselectAll(); this.deselectAll();
this.tableBody.getElements('tr').each(function(tr) { this.tableBody.getElements('tr').each(function(tr) {
if (rowIds.indexOf(tr.rowId) > -1) { if (rowIds.includes(tr.rowId)) {
const node = that.getNode(tr.rowId); const node = that.getNode(tr.rowId);
node.checked = 0; node.checked = 0;
node.full_data.checked = 0; node.full_data.checked = 0;
@ -2704,7 +2705,7 @@ window.qBittorrent.DynamicTable = (function() {
} }
if (td.getChildren('img').length > 0) { if (td.getChildren('img').length > 0) {
const img = td.getChildren('img')[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('src', img_path);
img.set('title', status); img.set('title', status);
} }
@ -3159,7 +3160,7 @@ window.qBittorrent.DynamicTable = (function() {
const logLevels = window.qBittorrent.Log.getSelectedLevels(); const logLevels = window.qBittorrent.Log.getSelectedLevels();
if ((filterTerms.length > 0) || (logLevels.length < 4)) { if ((filterTerms.length > 0) || (logLevels.length < 4)) {
for (let i = 0; i < rows.length; ++i) { 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; continue;
if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(rows[i].full_data.message, filterTerms)) if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(rows[i].full_data.message, filterTerms))