WebUI: unify curly bracket usage

This commit is contained in:
Chocobo1 2024-06-07 02:22:57 +08:00 committed by sledgehammer999
parent 671943a9a6
commit fa58e58e70
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
32 changed files with 177 additions and 252 deletions

View file

@ -26,6 +26,7 @@ export default [
Stylistic Stylistic
}, },
rules: { rules: {
"curly": ["error", "multi-or-nest", "consistent"],
"eqeqeq": "error", "eqeqeq": "error",
"guard-for-in": "error", "guard-for-in": "error",
"no-undef": "off", "no-undef": "off",

View file

@ -63,9 +63,8 @@
window.parent.qBittorrent.Client.closeWindows(); window.parent.qBittorrent.Client.closeWindows();
}, },
onFailure: (response) => { onFailure: (response) => {
if (response.status === 409) { if (response.status === 409)
alert(response.responseText); alert(response.responseText);
}
$("renameButton").disabled = false; $("renameButton").disabled = false;
} }
}).send(); }).send();

View file

@ -14,9 +14,8 @@
<script> <script>
"use strict"; "use strict";
if (window.parent.qBittorrent !== undefined) { if (window.parent.qBittorrent !== undefined)
window.qBittorrent = window.parent.qBittorrent; window.qBittorrent = window.parent.qBittorrent;
}
window.qBittorrent = window.parent.qBittorrent; window.qBittorrent = window.parent.qBittorrent;
const TriState = window.qBittorrent.FileTree.TriState; const TriState = window.qBittorrent.FileTree.TriState;
@ -51,9 +50,8 @@
const tableHeaders = $$("#bulkRenameFilesTableFixedHeaderDiv .dynamicTableHeader th"); const tableHeaders = $$("#bulkRenameFilesTableFixedHeaderDiv .dynamicTableHeader th");
let checkboxHeader; let checkboxHeader;
if (tableHeaders.length > 0) { if (tableHeaders.length > 0) {
if (checkboxHeader) { if (checkboxHeader)
checkboxHeader.remove(); checkboxHeader.remove();
}
checkboxHeader = new Element("input"); checkboxHeader = new Element("input");
checkboxHeader.set("type", "checkbox"); checkboxHeader.set("type", "checkbox");
checkboxHeader.set("id", "rootMultiRename_cb"); checkboxHeader.set("id", "rootMultiRename_cb");
@ -218,9 +216,12 @@
}); });
$("file_counter").addEvent("input", (e) => { $("file_counter").addEvent("input", (e) => {
let value = e.target.valueAsNumber; let value = e.target.valueAsNumber;
if (!value) { value = 0; } if (!value)
if (value < 0) { value = 0; } value = 0;
if (value > 99999999) { value = 99999999; } if (value < 0)
value = 0;
if (value > 99999999)
value = 99999999;
fileRenamer.fileEnumerationStart = value; fileRenamer.fileEnumerationStart = value;
$("file_counter").set("value", value); $("file_counter").set("value", value);
LocalPreferences.set("multirename_fileEnumerationStart", value); LocalPreferences.set("multirename_fileEnumerationStart", value);
@ -265,9 +266,8 @@
// Recreate table // Recreate table
let selectedRows = bulkRenameFilesTable.getSelectedRows().map(row => row.rowId.toString()); let selectedRows = bulkRenameFilesTable.getSelectedRows().map(row => row.rowId.toString());
for (const renamedRow of rows) { for (const renamedRow of rows)
selectedRows = selectedRows.filter(selectedRow => selectedRow !== renamedRow.rowId.toString()); selectedRows = selectedRows.filter(selectedRow => selectedRow !== renamedRow.rowId.toString());
}
bulkRenameFilesTable.clear(); bulkRenameFilesTable.clear();
// Adjust file enumeration count by 1 when replacing single files to prevent naming conflicts // Adjust file enumeration count by 1 when replacing single files to prevent naming conflicts
@ -278,22 +278,18 @@
setupTable(selectedRows); setupTable(selectedRows);
}; };
fileRenamer.onRenameError = function(err, row) { fileRenamer.onRenameError = function(err, row) {
if (err.xhr.status === 409) { if (err.xhr.status === 409)
$("rename_error").set("text", `QBT_TR(Rename failed: file or folder already exists)QBT_TR[CONTEXT=PropertiesWidget] \`${row.renamed}\``); $("rename_error").set("text", `QBT_TR(Rename failed: file or folder already exists)QBT_TR[CONTEXT=PropertiesWidget] \`${row.renamed}\``);
}
}; };
$("renameOptions").addEvent("change", (e) => { $("renameOptions").addEvent("change", (e) => {
const combobox = e.target; const combobox = e.target;
const replaceOperation = combobox.value; const replaceOperation = combobox.value;
if (replaceOperation === "Replace") { if (replaceOperation === "Replace")
fileRenamer.replaceAll = false; fileRenamer.replaceAll = false;
} else if (replaceOperation === "Replace All")
else if (replaceOperation === "Replace All") {
fileRenamer.replaceAll = true; fileRenamer.replaceAll = true;
} else
else {
fileRenamer.replaceAll = false; fileRenamer.replaceAll = false;
}
LocalPreferences.set("multirename_replaceAll", fileRenamer.replaceAll); LocalPreferences.set("multirename_replaceAll", fileRenamer.replaceAll);
$("renameButton").set("value", replaceOperation); $("renameButton").set("value", replaceOperation);
}); });
@ -336,9 +332,8 @@
pathItems.pop(); // remove last item (i.e. file name) pathItems.pop(); // remove last item (i.e. file name)
let parent = rootNode; let parent = rootNode;
pathItems.forEach((folderName) => { pathItems.forEach((folderName) => {
if (folderName === ".unwanted") { if (folderName === ".unwanted")
return; return;
}
let folderNode = null; let folderNode = null;
if (parent.children !== null) { if (parent.children !== null) {
@ -387,9 +382,9 @@
bulkRenameFilesTable.updateTable(false); bulkRenameFilesTable.updateTable(false);
bulkRenameFilesTable.altRow(); bulkRenameFilesTable.altRow();
if (selectedRows !== undefined) { if (selectedRows !== undefined)
bulkRenameFilesTable.reselectRows(selectedRows); bulkRenameFilesTable.reselectRows(selectedRows);
}
fileRenamer.selectedFiles = bulkRenameFilesTable.getSelectedRows(); fileRenamer.selectedFiles = bulkRenameFilesTable.getSelectedRows();
fileRenamer.update(); fileRenamer.update();
}; };
@ -400,13 +395,11 @@
noCache: true, noCache: true,
method: "get", method: "get",
onSuccess: function(files) { onSuccess: function(files) {
if (files.length === 0) { if (files.length === 0)
bulkRenameFilesTable.clear(); bulkRenameFilesTable.clear();
} else
else {
handleTorrentFiles(files, selectedRows); handleTorrentFiles(files, selectedRows);
} }
}
}).send(); }).send();
}; };
setupTable(data.selectedRows); setupTable(data.selectedRows);

View file

@ -25,9 +25,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.Client = (() => { window.qBittorrent.Client = (() => {
const exports = () => { const exports = () => {
@ -519,10 +518,9 @@ window.addEventListener("DOMContentLoaded", () => {
if (useSubcategories) { if (useSubcategories) {
for (let j = (i + 1); for (let j = (i + 1);
((j < sortedCategories.length) && sortedCategories[j].categoryName.startsWith(categoryName + "/")); ++j) { ((j < sortedCategories.length) && sortedCategories[j].categoryName.startsWith(categoryName + "/")); ++j)
categoryCount += sortedCategories[j].categoryCount; categoryCount += sortedCategories[j].categoryCount;
} }
}
categoryList.appendChild(create_link(categoryHash, categoryName, categoryCount)); categoryList.appendChild(create_link(categoryHash, categoryName, categoryCount));
} }
@ -600,9 +598,8 @@ window.addEventListener("DOMContentLoaded", () => {
// We want the hostname. // We want the hostname.
// If failed to parse the domain, original input should be returned // If failed to parse the domain, original input should be returned
if (!/^(?:https?|udp):/i.test(url)) { if (!/^(?:https?|udp):/i.test(url))
return url; return url;
}
try { try {
// hack: URL can not get hostname from udp protocol // hack: URL can not get hostname from udp protocol
@ -610,9 +607,8 @@ window.addEventListener("DOMContentLoaded", () => {
// host: "example.com:8443" // host: "example.com:8443"
// hostname: "example.com" // hostname: "example.com"
const host = parsedUrl.hostname; const host = parsedUrl.hostname;
if (!host) { if (!host)
return url; return url;
}
return host; return host;
} }
@ -654,10 +650,9 @@ window.addEventListener("DOMContentLoaded", () => {
trackerList.forEach(({ host, trackerTorrentMap }, hash) => { trackerList.forEach(({ host, trackerTorrentMap }, hash) => {
const uniqueTorrents = new Set(); const uniqueTorrents = new Set();
for (const torrents of trackerTorrentMap.values()) { for (const torrents of trackerTorrentMap.values()) {
for (const torrent of torrents) { for (const torrent of torrents)
uniqueTorrents.add(torrent); uniqueTorrents.add(torrent);
} }
}
sortedList.push({ sortedList.push({
trackerHost: host, trackerHost: host,
@ -745,9 +740,8 @@ window.addEventListener("DOMContentLoaded", () => {
category_list.clear(); category_list.clear();
tagList.clear(); tagList.clear();
} }
if (response["rid"]) { if (response["rid"])
syncMainDataLastResponseId = response["rid"]; syncMainDataLastResponseId = response["rid"];
}
if (response["categories"]) { if (response["categories"]) {
for (const key in response["categories"]) { for (const key in response["categories"]) {
if (!Object.hasOwn(response["categories"], key)) if (!Object.hasOwn(response["categories"], key))
@ -816,10 +810,9 @@ window.addEventListener("DOMContentLoaded", () => {
const tracker = response["trackers_removed"][i]; const tracker = response["trackers_removed"][i];
const hash = window.qBittorrent.Client.genHash(getHost(tracker)); const hash = window.qBittorrent.Client.genHash(getHost(tracker));
const trackerListEntry = trackerList.get(hash); const trackerListEntry = trackerList.get(hash);
if (trackerListEntry) { if (trackerListEntry)
trackerListEntry.trackerTorrentMap.delete(tracker); trackerListEntry.trackerTorrentMap.delete(tracker);
} }
}
updateTrackers = true; updateTrackers = true;
} }
if (response["torrents"]) { if (response["torrents"]) {
@ -844,7 +837,7 @@ window.addEventListener("DOMContentLoaded", () => {
if (updateTorrentList) if (updateTorrentList)
setupCopyEventHandler(); setupCopyEventHandler();
} }
if (response["torrents_removed"]) if (response["torrents_removed"]) {
response["torrents_removed"].each((hash) => { response["torrents_removed"].each((hash) => {
torrentsTable.removeRow(hash); torrentsTable.removeRow(hash);
removeTorrentFromCategoryList(hash); removeTorrentFromCategoryList(hash);
@ -852,6 +845,7 @@ window.addEventListener("DOMContentLoaded", () => {
removeTorrentFromTagList(hash); removeTorrentFromTagList(hash);
updateTags = true; // Always to update All tag updateTags = true; // Always to update All tag
}); });
}
torrentsTable.updateTable(full_update); torrentsTable.updateTable(full_update);
torrentsTable.altRow(); torrentsTable.altRow();
if (response["server_state"]) { if (response["server_state"]) {

View file

@ -28,9 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.ContextMenu = (function() { window.qBittorrent.ContextMenu = (function() {
const exports = function() { const exports = function() {
@ -82,12 +81,10 @@ window.qBittorrent.ContextMenu = (function() {
property: "opacity", property: "opacity",
duration: this.options.fadeSpeed, duration: this.options.fadeSpeed,
onComplete: function() { onComplete: function() {
if (this.getStyle("opacity")) { if (this.getStyle("opacity"))
this.setStyle("visibility", "visible"); this.setStyle("visibility", "visible");
} else
else {
this.setStyle("visibility", "hidden"); this.setStyle("visibility", "hidden");
}
}.bind(this.menu) }.bind(this.menu)
}); });
@ -182,9 +179,8 @@ window.qBittorrent.ContextMenu = (function() {
this.touchStartEvent = null; this.touchStartEvent = null;
const isTargetUnchanged = (Math.abs(e.event.pageX - touchStartEvent.event.pageX) <= 10) && (Math.abs(e.event.pageY - touchStartEvent.event.pageY) <= 10); const isTargetUnchanged = (Math.abs(e.event.pageX - touchStartEvent.event.pageX) <= 10) && (Math.abs(e.event.pageY - touchStartEvent.event.pageY) <= 10);
if (((now - touchStartAt) >= this.options.touchTimer) && isTargetUnchanged) { if (((now - touchStartAt) >= this.options.touchTimer) && isTargetUnchanged)
this.triggerMenu(touchStartEvent, elem); this.triggerMenu(touchStartEvent, elem);
}
}); });
}, },
@ -202,9 +198,8 @@ window.qBittorrent.ContextMenu = (function() {
return; return;
//prevent default, if told to //prevent default, if told to
if (this.options.stopEvent) { if (this.options.stopEvent)
e.stop(); e.stop();
}
//record this as the trigger //record this as the trigger
this.options.element = $(el); this.options.element = $(el);
this.adjustMenuPosition(e); this.adjustMenuPosition(e);
@ -294,9 +289,8 @@ window.qBittorrent.ContextMenu = (function() {
//execute an action //execute an action
execute: function(action, element) { execute: function(action, element) {
if (this.options.actions[action]) { if (this.options.actions[action])
this.options.actions[action](element, this, action); this.options.actions[action](element, this, action);
}
return this; return this;
} }
}); });
@ -515,13 +509,11 @@ window.qBittorrent.ContextMenu = (function() {
if ((id !== CATEGORIES_ALL) && (id !== CATEGORIES_UNCATEGORIZED)) { if ((id !== CATEGORIES_ALL) && (id !== CATEGORIES_UNCATEGORIZED)) {
this.showItem("editCategory"); this.showItem("editCategory");
this.showItem("deleteCategory"); this.showItem("deleteCategory");
if (useSubcategories) { if (useSubcategories)
this.showItem("createSubcategory"); this.showItem("createSubcategory");
} else
else {
this.hideItem("createSubcategory"); this.hideItem("createSubcategory");
} }
}
else { else {
this.hideItem("editCategory"); this.hideItem("editCategory");
this.hideItem("deleteCategory"); this.hideItem("deleteCategory");
@ -547,9 +539,10 @@ window.qBittorrent.ContextMenu = (function() {
updateMenuItems: function() { updateMenuItems: function() {
const enabledColumnIndex = function(text) { const enabledColumnIndex = function(text) {
const columns = $("searchPluginsTableFixedHeaderRow").getChildren("th"); const columns = $("searchPluginsTableFixedHeaderRow").getChildren("th");
for (let i = 0; i < columns.length; ++i) for (let i = 0; i < columns.length; ++i) {
if (columns[i].get("html") === "Enabled") if (columns[i].get("html") === "Enabled")
return i; return i;
}
}; };
this.showItem("Enabled"); this.showItem("Enabled");

View file

@ -23,9 +23,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.Download = (function() { window.qBittorrent.Download = (function() {
const exports = function() { const exports = function() {
@ -77,25 +76,19 @@ window.qBittorrent.Download = (function() {
$("autoTMM").selectedIndex = 0; $("autoTMM").selectedIndex = 0;
} }
if (pref.torrent_stop_condition === "MetadataReceived") { if (pref.torrent_stop_condition === "MetadataReceived")
$("stopCondition").selectedIndex = 1; $("stopCondition").selectedIndex = 1;
} else if (pref.torrent_stop_condition === "FilesChecked")
else if (pref.torrent_stop_condition === "FilesChecked") {
$("stopCondition").selectedIndex = 2; $("stopCondition").selectedIndex = 2;
} else
else {
$("stopCondition").selectedIndex = 0; $("stopCondition").selectedIndex = 0;
}
if (pref.torrent_content_layout === "Subfolder") { if (pref.torrent_content_layout === "Subfolder")
$("contentLayout").selectedIndex = 1; $("contentLayout").selectedIndex = 1;
} else if (pref.torrent_content_layout === "NoSubfolder")
else if (pref.torrent_content_layout === "NoSubfolder") {
$("contentLayout").selectedIndex = 2; $("contentLayout").selectedIndex = 2;
} else
else {
$("contentLayout").selectedIndex = 0; $("contentLayout").selectedIndex = 0;
}
}; };
const changeCategorySelect = function(item) { const changeCategorySelect = function(item) {

View file

@ -33,9 +33,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.DynamicTable = (function() { window.qBittorrent.DynamicTable = (function() {
const exports = function() { const exports = function() {
@ -131,9 +130,8 @@ window.qBittorrent.DynamicTable = (function() {
const tableDiv = $(this.dynamicTableDivId); const tableDiv = $(this.dynamicTableDivId);
// dynamicTableDivId is not visible on the UI // dynamicTableDivId is not visible on the UI
if (!tableDiv) { if (!tableDiv)
return; return;
}
const panel = tableDiv.getParent(".panel"); const panel = tableDiv.getParent(".panel");
if (this.lastPanelHeight !== panel.getBoundingClientRect().height) { if (this.lastPanelHeight !== panel.getBoundingClientRect().height) {
@ -361,10 +359,9 @@ window.qBittorrent.DynamicTable = (function() {
// recreate child nodes when reusing (enables the context menu to work correctly) // recreate child nodes when reusing (enables the context menu to work correctly)
if (ul.hasChildNodes()) { if (ul.hasChildNodes()) {
while (ul.firstChild) { while (ul.firstChild)
ul.removeChild(ul.lastChild); ul.removeChild(ul.lastChild);
} }
}
for (let i = 0; i < this.columns.length; ++i) { for (let i = 0; i < this.columns.length; ++i) {
const text = this.columns[i].caption; const text = this.columns[i].caption;
@ -436,9 +433,10 @@ window.qBittorrent.DynamicTable = (function() {
columnsOrder.push(v); columnsOrder.push(v);
}); });
for (let i = 0; i < this.columns.length; ++i) for (let i = 0; i < this.columns.length; ++i) {
if (!columnsOrder.contains(this.columns[i].name)) if (!columnsOrder.contains(this.columns[i].name))
columnsOrder.push(this.columns[i].name); columnsOrder.push(this.columns[i].name);
}
for (let i = 0; i < this.columns.length; ++i) for (let i = 0; i < this.columns.length; ++i)
this.columns[i] = this.columns[columnsOrder[i]]; this.columns[i] = this.columns[columnsOrder[i]];
@ -478,9 +476,10 @@ window.qBittorrent.DynamicTable = (function() {
}, },
getColumnPos: function(columnName) { getColumnPos: function(columnName) {
for (let i = 0; i < this.columns.length; ++i) for (let i = 0; i < this.columns.length; ++i) {
if (this.columns[i].name === columnName) if (this.columns[i].name === columnName)
return i; return i;
}
return -1; return -1;
}, },
@ -507,9 +506,8 @@ window.qBittorrent.DynamicTable = (function() {
for (let j = 0; j < trs.length; ++j) for (let j = 0; j < trs.length; ++j)
trs[j].getElements("td")[pos].addClass("invisible"); trs[j].getElements("td")[pos].addClass("invisible");
} }
if (this.columns[pos].onResize !== null) { if (this.columns[pos].onResize !== null)
this.columns[pos].onResize(columnName); this.columns[pos].onResize(columnName);
}
}, },
getSortedColumn: function() { getSortedColumn: function() {
@ -576,12 +574,10 @@ window.qBittorrent.DynamicTable = (function() {
const trs = this.tableBody.getElements("tr"); const trs = this.tableBody.getElements("tr");
trs.each((el, i) => { trs.each((el, i) => {
if (i % 2) { if (i % 2)
el.addClass("alt"); el.addClass("alt");
} else
else {
el.removeClass("alt"); el.removeClass("alt");
}
}); });
}, },
@ -668,8 +664,9 @@ window.qBittorrent.DynamicTable = (function() {
}; };
this.rows.set(rowId, row); this.rows.set(rowId, row);
} }
else else {
row = this.rows.get(rowId); row = this.rows.get(rowId);
}
row["data"] = data; row["data"] = data;
for (const x in data) { for (const x in data) {
@ -702,27 +699,29 @@ window.qBittorrent.DynamicTable = (function() {
getTrByRowId: function(rowId) { getTrByRowId: function(rowId) {
const trs = this.tableBody.getElements("tr"); const trs = this.tableBody.getElements("tr");
for (let i = 0; i < trs.length; ++i) for (let i = 0; i < trs.length; ++i) {
if (trs[i].rowId === rowId) if (trs[i].rowId === rowId)
return trs[i]; return trs[i];
}
return null; return null;
}, },
updateTable: function(fullUpdate = false) { updateTable: function(fullUpdate = false) {
const rows = this.getFilteredAndSortedRows(); const rows = this.getFilteredAndSortedRows();
for (let i = 0; i < this.selectedRows.length; ++i) for (let i = 0; i < this.selectedRows.length; ++i) {
if (!(this.selectedRows[i] in rows)) { if (!(this.selectedRows[i] in rows)) {
this.selectedRows.splice(i, 1); this.selectedRows.splice(i, 1);
--i; --i;
} }
}
const trs = this.tableBody.getElements("tr"); const trs = this.tableBody.getElements("tr");
for (let rowPos = 0; rowPos < rows.length; ++rowPos) { for (let rowPos = 0; rowPos < rows.length; ++rowPos) {
const rowId = rows[rowPos]["rowId"]; const rowId = rows[rowPos]["rowId"];
let tr_found = false; let tr_found = false;
for (let j = rowPos; j < trs.length; ++j) for (let j = rowPos; j < trs.length; ++j) {
if (trs[j]["rowId"] === rowId) { if (trs[j]["rowId"] === rowId) {
tr_found = true; tr_found = true;
if (rowPos === j) if (rowPos === j)
@ -733,8 +732,10 @@ window.qBittorrent.DynamicTable = (function() {
trs.splice(rowPos, 0, tmpTr); trs.splice(rowPos, 0, tmpTr);
break; break;
} }
if (tr_found) // row already exists in the table }
if (tr_found) { // row already exists in the table
this.updateRow(trs[rowPos], fullUpdate); this.updateRow(trs[rowPos], fullUpdate);
}
else { // else create a new row in the table else { // else create a new row in the table
const tr = new Element("tr"); const tr = new Element("tr");
// set tabindex so element receives keydown events // set tabindex so element receives keydown events
@ -819,9 +820,8 @@ window.qBittorrent.DynamicTable = (function() {
const rowPos = rows.length; const rowPos = rows.length;
while ((rowPos < trs.length) && (trs.length > 0)) { while ((rowPos < trs.length) && (trs.length > 0))
trs.pop().destroy(); trs.pop().destroy();
}
}, },
setupTr: function(tr) {}, setupTr: function(tr) {},
@ -853,9 +853,8 @@ window.qBittorrent.DynamicTable = (function() {
this.deselectAll(); this.deselectAll();
this.rows.empty(); this.rows.empty();
const trs = this.tableBody.getElements("tr"); const trs = this.tableBody.getElements("tr");
while (trs.length > 0) { while (trs.length > 0)
trs.pop().destroy(); trs.pop().destroy();
}
}, },
selectedRowsIds: function() { selectedRowsIds: function() {
@ -1601,13 +1600,14 @@ window.qBittorrent.DynamicTable = (function() {
img.set("alt", country); img.set("alt", country);
img.set("title", country); img.set("title", country);
} }
else else {
td.adopt(new Element("img", { td.adopt(new Element("img", {
"src": img_path, "src": img_path,
"class": "flags", "class": "flags",
"alt": country, "alt": country,
"title": country "title": country
})); }));
}
}; };
// ip // ip
@ -1966,9 +1966,8 @@ window.qBittorrent.DynamicTable = (function() {
checkbox.checked = node.checked === 0; checkbox.checked = node.checked === 0;
checkbox.state = checkbox.checked ? "checked" : "unchecked"; checkbox.state = checkbox.checked ? "checked" : "unchecked";
for (let i = 0; i < node.children.length; ++i) { for (let i = 0; i < node.children.length; ++i)
this.toggleNodeTreeCheckbox(node.children[i].rowId, checkState); this.toggleNodeTreeCheckbox(node.children[i].rowId, checkState);
}
}, },
updateGlobalCheckbox: function() { updateGlobalCheckbox: function() {
@ -2236,9 +2235,8 @@ window.qBittorrent.DynamicTable = (function() {
}.bind(this); }.bind(this);
const rowsString = generateRowsSignature(this.rows); const rowsString = generateRowsSignature(this.rows);
if (!hasRowsChanged(rowsString, this.prevRowsString)) { if (!hasRowsChanged(rowsString, this.prevRowsString))
return this.prevFilteredRows; return this.prevFilteredRows;
}
// sort, then filter // sort, then filter
const column = this.columns[this.sortedColumn]; const column = this.columns[this.sortedColumn];
@ -2586,9 +2584,8 @@ window.qBittorrent.DynamicTable = (function() {
}.bind(this); }.bind(this);
const rowsString = generateRowsSignature(this.rows); const rowsString = generateRowsSignature(this.rows);
if (!hasRowsChanged(rowsString, this.prevRowsString)) { if (!hasRowsChanged(rowsString, this.prevRowsString))
return this.prevFilteredRows; return this.prevFilteredRows;
}
// sort, then filter // sort, then filter
const column = this.columns[this.sortedColumn]; const column = this.columns[this.sortedColumn];
@ -2739,9 +2736,8 @@ window.qBittorrent.DynamicTable = (function() {
column["force_hide"] = false; column["force_hide"] = false;
column["caption"] = caption; column["caption"] = caption;
column["style"] = style; column["style"] = style;
if (defaultWidth !== -1) { if (defaultWidth !== -1)
column["width"] = defaultWidth; column["width"] = defaultWidth;
}
column["dataProperties"] = [name]; column["dataProperties"] = [name];
column["getRowValue"] = function(row, pos) { column["getRowValue"] = function(row, pos) {
@ -2835,9 +2831,8 @@ window.qBittorrent.DynamicTable = (function() {
column["force_hide"] = false; column["force_hide"] = false;
column["caption"] = caption; column["caption"] = caption;
column["style"] = style; column["style"] = style;
if (defaultWidth !== -1) { if (defaultWidth !== -1)
column["width"] = defaultWidth; column["width"] = defaultWidth;
}
column["dataProperties"] = [name]; column["dataProperties"] = [name];
column["getRowValue"] = function(row, pos) { column["getRowValue"] = function(row, pos) {
@ -2921,9 +2916,8 @@ window.qBittorrent.DynamicTable = (function() {
column["force_hide"] = false; column["force_hide"] = false;
column["caption"] = caption; column["caption"] = caption;
column["style"] = style; column["style"] = style;
if (defaultWidth !== -1) { if (defaultWidth !== -1)
column["width"] = defaultWidth; column["width"] = defaultWidth;
}
column["dataProperties"] = [name]; column["dataProperties"] = [name];
column["getRowValue"] = function(row, pos) { column["getRowValue"] = function(row, pos) {
@ -3008,9 +3002,8 @@ window.qBittorrent.DynamicTable = (function() {
column["force_hide"] = false; column["force_hide"] = false;
column["caption"] = caption; column["caption"] = caption;
column["style"] = style; column["style"] = style;
if (defaultWidth !== -1) { if (defaultWidth !== -1)
column["width"] = defaultWidth; column["width"] = defaultWidth;
}
column["dataProperties"] = [name]; column["dataProperties"] = [name];
column["getRowValue"] = function(row, pos) { column["getRowValue"] = function(row, pos) {
@ -3058,9 +3051,8 @@ window.qBittorrent.DynamicTable = (function() {
column["force_hide"] = false; column["force_hide"] = false;
column["caption"] = caption; column["caption"] = caption;
column["style"] = style; column["style"] = style;
if (defaultWidth !== -1) { if (defaultWidth !== -1)
column["width"] = defaultWidth; column["width"] = defaultWidth;
}
column["dataProperties"] = [name]; column["dataProperties"] = [name];
column["getRowValue"] = function(row, pos) { column["getRowValue"] = function(row, pos) {

View file

@ -28,9 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.FileTree = (function() { window.qBittorrent.FileTree = (function() {
const exports = function() { const exports = function() {
@ -77,9 +76,8 @@ window.qBittorrent.FileTree = (function() {
generateNodeMap: function(node) { generateNodeMap: function(node) {
// don't store root node in map // don't store root node in map
if (node.root !== null) { if (node.root !== null)
this.nodeMap[node.rowId] = node; this.nodeMap[node.rowId] = node;
}
node.children.each((child) => { node.children.each((child) => {
this.generateNodeMap(child); this.generateNodeMap(child);

View file

@ -30,9 +30,8 @@
// This file is the JavaScript implementation of base/utils/fs.cpp // This file is the JavaScript implementation of base/utils/fs.cpp
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.Filesystem = (function() { window.qBittorrent.Filesystem = (function() {
const exports = function() { const exports = function() {

View file

@ -28,9 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.LocalPreferences = (function() { window.qBittorrent.LocalPreferences = (function() {
const exports = function() { const exports = function() {

View file

@ -28,9 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.Misc = (function() { window.qBittorrent.Misc = (function() {
const exports = function() { const exports = function() {
@ -86,8 +85,9 @@ window.qBittorrent.Misc = (function() {
} }
let ret; let ret;
if (i === 0) if (i === 0) {
ret = value + " " + units[i]; ret = value + " " + units[i];
}
else { else {
const precision = friendlyUnitPrecision(i); const precision = friendlyUnitPrecision(i);
const offset = Math.pow(10, precision); const offset = Math.pow(10, precision);

View file

@ -110,9 +110,8 @@ const initializeWindows = function() {
function addClickEvent(el, fn) { function addClickEvent(el, fn) {
["Link", "Button"].each((item) => { ["Link", "Button"].each((item) => {
if ($(el + item)) { if ($(el + item))
$(el + item).addEvent("click", fn); $(el + item).addEvent("click", fn);
}
}); });
} }
@ -125,9 +124,8 @@ const initializeWindows = function() {
const id = "downloadPage"; const id = "downloadPage";
const contentUri = new URI("download.html"); const contentUri = new URI("download.html");
if (urls && (urls.length > 0)) { if (urls && (urls.length > 0))
contentUri.setData("urls", urls.map(encodeURIComponent).join("|")); contentUri.setData("urls", urls.map(encodeURIComponent).join("|"));
}
new MochaUI.Window({ new MochaUI.Window({
id: id, id: id,
@ -877,10 +875,9 @@ const initializeWindows = function() {
default: { default: {
const uniqueTorrents = new Set(); const uniqueTorrents = new Set();
for (const torrents of trackerList.get(trackerHashInt).trackerTorrentMap.values()) { for (const torrents of trackerList.get(trackerHashInt).trackerTorrentMap.values()) {
for (const torrent of torrents) { for (const torrent of torrents)
uniqueTorrents.add(torrent); uniqueTorrents.add(torrent);
} }
}
hashes = [...uniqueTorrents]; hashes = [...uniqueTorrents];
break; break;
} }
@ -911,10 +908,9 @@ const initializeWindows = function() {
default: { default: {
const uniqueTorrents = new Set(); const uniqueTorrents = new Set();
for (const torrents of trackerList.get(trackerHashInt).trackerTorrentMap.values()) { for (const torrents of trackerList.get(trackerHashInt).trackerTorrentMap.values()) {
for (const torrent of torrents) { for (const torrent of torrents)
uniqueTorrents.add(torrent); uniqueTorrents.add(torrent);
} }
}
hashes = [...uniqueTorrents]; hashes = [...uniqueTorrents];
break; break;
} }
@ -945,10 +941,9 @@ const initializeWindows = function() {
default: { default: {
const uniqueTorrents = new Set(); const uniqueTorrents = new Set();
for (const torrents of trackerList.get(trackerHashInt).trackerTorrentMap.values()) { for (const torrents of trackerList.get(trackerHashInt).trackerTorrentMap.values()) {
for (const torrent of torrents) { for (const torrent of torrents)
uniqueTorrents.add(torrent); uniqueTorrents.add(torrent);
} }
}
hashes = [...uniqueTorrents]; hashes = [...uniqueTorrents];
break; break;
} }

View file

@ -28,9 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.PiecesBar = (() => { window.qBittorrent.PiecesBar = (() => {
const exports = () => { const exports = () => {
@ -136,14 +135,11 @@ window.qBittorrent.PiecesBar = (() => {
let maxStatus = 0; let maxStatus = 0;
for (const status of pieces) { for (const status of pieces) {
if (status > maxStatus) { if (status > maxStatus)
maxStatus = status; maxStatus = status;
} if (status < minStatus)
if (status < minStatus) {
minStatus = status; minStatus = status;
} }
}
// if no progress then don't do anything // if no progress then don't do anything
if (maxStatus === 0) if (maxStatus === 0)
@ -220,15 +216,13 @@ window.qBittorrent.PiecesBar = (() => {
statusValues[STATUS_DOWNLOADING] = Math.min(statusValues[STATUS_DOWNLOADING], 1); statusValues[STATUS_DOWNLOADING] = Math.min(statusValues[STATUS_DOWNLOADING], 1);
statusValues[STATUS_DOWNLOADED] = Math.min(statusValues[STATUS_DOWNLOADED], 1); statusValues[STATUS_DOWNLOADED] = Math.min(statusValues[STATUS_DOWNLOADED], 1);
if (!lastValue) { if (!lastValue)
lastValue = statusValues; lastValue = statusValues;
}
// group contiguous colors together and draw as a single rectangle // group contiguous colors together and draw as a single rectangle
if ((lastValue[STATUS_DOWNLOADING] === statusValues[STATUS_DOWNLOADING]) if ((lastValue[STATUS_DOWNLOADING] === statusValues[STATUS_DOWNLOADING])
&& (lastValue[STATUS_DOWNLOADED] === statusValues[STATUS_DOWNLOADED])) { && (lastValue[STATUS_DOWNLOADED] === statusValues[STATUS_DOWNLOADED]))
continue; continue;
}
const rectangleWidth = x - rectangleStart; const rectangleWidth = x - rectangleStart;
this._drawStatus(ctx, rectangleStart, rectangleWidth, lastValue); this._drawStatus(ctx, rectangleStart, rectangleWidth, lastValue);

View file

@ -28,9 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.ProgressBar = (function() { window.qBittorrent.ProgressBar = (function() {
const exports = function() { const exports = function() {

View file

@ -28,9 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.PropFiles = (function() { window.qBittorrent.PropFiles = (function() {
const exports = function() { const exports = function() {
@ -496,16 +495,14 @@ window.qBittorrent.PropFiles = (function() {
const expandFolder = function(id) { const expandFolder = function(id) {
const node = torrentFilesTable.getNode(id); const node = torrentFilesTable.getNode(id);
if (node.isFolder) { if (node.isFolder)
expandNode(node); expandNode(node);
}
}; };
const collapseFolder = function(id) { const collapseFolder = function(id) {
const node = torrentFilesTable.getNode(id); const node = torrentFilesTable.getNode(id);
if (node.isFolder) { if (node.isFolder)
collapseNode(node); collapseNode(node);
}
}; };
const filesPriorityMenuClicked = function(priority) { const filesPriorityMenuClicked = function(priority) {
@ -590,12 +587,10 @@ window.qBittorrent.PropFiles = (function() {
if (!hash) if (!hash)
return; return;
if (torrentFilesTable.selectedRowsIds().length > 1) { if (torrentFilesTable.selectedRowsIds().length > 1)
multiFileRename(hash); multiFileRename(hash);
} else
else {
singleFileRename(hash); singleFileRename(hash);
}
}, },
FilePrioIgnore: function(element, ref) { FilePrioIgnore: function(element, ref) {

View file

@ -28,9 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.PropGeneral = (function() { window.qBittorrent.PropGeneral = (function() {
const exports = function() { const exports = function() {
@ -233,12 +232,11 @@ window.qBittorrent.PropGeneral = (function() {
onSuccess: function(data) { onSuccess: function(data) {
$("error_div").set("html", ""); $("error_div").set("html", "");
if (data) { if (data)
piecesBar.setPieces(data); piecesBar.setPieces(data);
} else
else {
clearData(); clearData();
}
clearTimeout(loadTorrentDataTimer); clearTimeout(loadTorrentDataTimer);
loadTorrentDataTimer = loadTorrentData.delay(5000); loadTorrentDataTimer = loadTorrentData.delay(5000);
} }

View file

@ -28,9 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.PropPeers = (function() { window.qBittorrent.PropPeers = (function() {
const exports = function() { const exports = function() {

View file

@ -28,9 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.PropTrackers = (function() { window.qBittorrent.PropTrackers = (function() {
const exports = function() { const exports = function() {

View file

@ -28,9 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.PropWebseeds = (function() { window.qBittorrent.PropWebseeds = (function() {
const exports = function() { const exports = function() {
@ -65,9 +64,8 @@ window.qBittorrent.PropWebseeds = (function() {
updateRow: function(tr, row) { updateRow: function(tr, row) {
const tds = tr.getElements("td"); const tds = tr.getElements("td");
for (let i = 0; i < row.length; ++i) { for (let i = 0; i < row.length; ++i)
tds[i].set("html", row[i]); tds[i].set("html", row[i]);
}
return true; return true;
}, },

View file

@ -1,8 +1,7 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.MultiRename = (function() { window.qBittorrent.MultiRename = (function() {
const exports = function() { const exports = function() {
@ -68,12 +67,10 @@ window.qBittorrent.MultiRename = (function() {
// regex assertions don't modify lastIndex, // regex assertions don't modify lastIndex,
// so we need to explicitly break out to prevent infinite loop // so we need to explicitly break out to prevent infinite loop
if (lastIndex === regex.lastIndex) { if (lastIndex === regex.lastIndex)
break; break;
} else
else {
lastIndex = regex.lastIndex; lastIndex = regex.lastIndex;
}
// Maximum of 250 matches per file // Maximum of 250 matches per file
++count; ++count;
@ -124,14 +121,15 @@ window.qBittorrent.MultiRename = (function() {
this.matchedFiles = []; this.matchedFiles = [];
// Ignore empty searches // Ignore empty searches
if (!this._inner_search) { if (!this._inner_search)
return; return;
}
// Setup regex flags // Setup regex flags
let regexFlags = ""; let regexFlags = "";
if (this.matchAllOccurrences) { regexFlags += "g"; } if (this.matchAllOccurrences)
if (!this.caseSensitive) { regexFlags += "i"; } regexFlags += "g";
if (!this.caseSensitive)
regexFlags += "i";
// Setup regex search // Setup regex search
const regexEscapeExp = new RegExp(/[/\-\\^$*+?.()|[\]{}]/g); const regexEscapeExp = new RegExp(/[/\-\\^$*+?.()|[\]{}]/g);
@ -153,17 +151,17 @@ window.qBittorrent.MultiRename = (function() {
const row = this.selectedFiles[i]; const row = this.selectedFiles[i];
// Ignore files // Ignore files
if (!row.isFolder && !this.includeFiles) { if (!row.isFolder && !this.includeFiles)
continue; continue;
}
// Ignore folders // Ignore folders
else if (row.isFolder && !this.includeFolders) { else if (row.isFolder && !this.includeFolders)
continue; continue;
}
// Get file extension and reappend the "." (only when the file has an extension) // Get file extension and reappend the "." (only when the file has an extension)
let fileExtension = window.qBittorrent.Filesystem.fileExtension(row.original); let fileExtension = window.qBittorrent.Filesystem.fileExtension(row.original);
if (fileExtension) { fileExtension = "." + fileExtension; } if (fileExtension)
fileExtension = "." + fileExtension;
const fileNameWithoutExt = row.original.slice(0, row.original.lastIndexOf(fileExtension)); const fileNameWithoutExt = row.original.slice(0, row.original.lastIndexOf(fileExtension));
@ -183,9 +181,8 @@ window.qBittorrent.MultiRename = (function() {
break; break;
} }
// Ignore rows without a match // Ignore rows without a match
if (!matches || (matches.length === 0)) { if (!matches || (matches.length === 0))
continue; continue;
}
let renamed = row.original; let renamed = row.original;
for (let i = matches.length - 1; i >= 0; --i) { for (let i = matches.length - 1; i >= 0; --i) {
@ -194,7 +191,8 @@ window.qBittorrent.MultiRename = (function() {
// Replace numerical groups // Replace numerical groups
for (let g = 0; g < match.length; ++g) { for (let g = 0; g < match.length; ++g) {
const group = match[g]; const group = match[g];
if (!group) { continue; } if (!group)
continue;
replacement = replaceGroup(replacement, `$${g}`, group, "\\", false); replacement = replaceGroup(replacement, `$${g}`, group, "\\", false);
} }
// Replace named groups // Replace named groups
@ -266,10 +264,9 @@ window.qBittorrent.MultiRename = (function() {
if (this.replaceAll) { if (this.replaceAll) {
// matchedFiles are in DFS order so we rename in reverse // matchedFiles are in DFS order so we rename in reverse
// in order to prevent unwanted folder creation // in order to prevent unwanted folder creation
for (let i = replacements - 1; i >= 0; --i) { for (let i = replacements - 1; i >= 0; --i)
await _inner_rename(i); await _inner_rename(i);
} }
}
else { else {
// single replacements go linearly top-down because the // single replacements go linearly top-down because the
// file tree gets recreated after every rename // file tree gets recreated after every rename

View file

@ -23,9 +23,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.Search = (function() { window.qBittorrent.Search = (function() {
const exports = function() { const exports = function() {
@ -145,9 +144,8 @@ window.qBittorrent.Search = (function() {
// restore search tabs // restore search tabs
const searchJobs = JSON.parse(LocalPreferences.get("search_jobs", "[]")); const searchJobs = JSON.parse(LocalPreferences.get("search_jobs", "[]"));
for (const { id, pattern } of searchJobs) { for (const { id, pattern } of searchJobs)
createSearchTab(id, pattern); createSearchTab(id, pattern);
}
}; };
const numSearchTabs = function() { const numSearchTabs = function() {
@ -226,9 +224,8 @@ window.qBittorrent.Search = (function() {
const currentSearchId = getSelectedSearchId(); const currentSearchId = getSelectedSearchId();
const state = searchState.get(currentSearchId); const state = searchState.get(currentSearchId);
// don't bother sending a stop request if already stopped // don't bother sending a stop request if already stopped
if (state && state.running) { if (state && state.running)
stopSearch(searchId); stopSearch(searchId);
}
tab.destroy(); tab.destroy();
@ -310,9 +307,8 @@ window.qBittorrent.Search = (function() {
// restore table rows // restore table rows
searchResultsTable.clear(); searchResultsTable.clear();
if (state) { if (state) {
for (const row of state.rows) { for (const row of state.rows)
searchResultsTable.updateRowData(row); searchResultsTable.updateRowData(row);
}
rowsToSelect = state.selectedRowIds; rowsToSelect = state.selectedRowIds;
@ -352,9 +348,8 @@ window.qBittorrent.Search = (function() {
searchResultsTable.altRow(); searchResultsTable.altRow();
// must reselect rows after calling updateTable // must reselect rows after calling updateTable
if (rowsToSelect.length > 0) { if (rowsToSelect.length > 0)
searchResultsTable.reselectRows(rowsToSelect); searchResultsTable.reselectRows(rowsToSelect);
}
$("numSearchResultsVisible").set("html", searchResultsTable.getFilteredAndSortedRows().length); $("numSearchResultsVisible").set("html", searchResultsTable.getFilteredAndSortedRows().length);
$("numSearchResultsTotal").set("html", searchResultsTable.getRowIds().length); $("numSearchResultsTotal").set("html", searchResultsTable.getRowIds().length);
@ -494,7 +489,7 @@ window.qBittorrent.Search = (function() {
const manageSearchPlugins = function() { const manageSearchPlugins = function() {
const id = "searchPlugins"; const id = "searchPlugins";
if (!$(id)) if (!$(id)) {
new MochaUI.Window({ new MochaUI.Window({
id: id, id: id,
title: "QBT_TR(Search plugins)QBT_TR[CONTEXT=PluginSelectDlg]", title: "QBT_TR(Search plugins)QBT_TR[CONTEXT=PluginSelectDlg]",
@ -516,6 +511,7 @@ window.qBittorrent.Search = (function() {
clearTimeout(loadSearchPluginsTimer); clearTimeout(loadSearchPluginsTimer);
} }
}); });
}
}; };
const loadSearchPlugins = function() { const loadSearchPlugins = function() {
@ -552,17 +548,19 @@ window.qBittorrent.Search = (function() {
}; };
const reselectCategory = function() { const reselectCategory = function() {
for (let i = 0; i < $("categorySelect").options.length; ++i) for (let i = 0; i < $("categorySelect").options.length; ++i) {
if ($("categorySelect").options[i].get("value") === selectedCategory) if ($("categorySelect").options[i].get("value") === selectedCategory)
$("categorySelect").options[i].selected = true; $("categorySelect").options[i].selected = true;
}
categorySelected(); categorySelected();
}; };
const reselectPlugin = function() { const reselectPlugin = function() {
for (let i = 0; i < $("pluginsSelect").options.length; ++i) for (let i = 0; i < $("pluginsSelect").options.length; ++i) {
if ($("pluginsSelect").options[i].get("value") === selectedPlugin) if ($("pluginsSelect").options[i].get("value") === selectedPlugin)
$("pluginsSelect").options[i].selected = true; $("pluginsSelect").options[i].selected = true;
}
pluginSelected(); pluginSelected();
}; };
@ -606,11 +604,10 @@ window.qBittorrent.Search = (function() {
if ((selectedPlugin === "enabled") && !plugin.enabled) if ((selectedPlugin === "enabled") && !plugin.enabled)
continue; continue;
for (const category of plugin.supportedCategories) { for (const category of plugin.supportedCategories) {
if (uniqueCategories[category.id] === undefined) { if (uniqueCategories[category.id] === undefined)
uniqueCategories[category.id] = category; uniqueCategories[category.id] = category;
} }
} }
}
// we must sort the ids to maintain consistent order. // we must sort the ids to maintain consistent order.
const categories = Object.keys(uniqueCategories).sort().map(id => uniqueCategories[id]); const categories = Object.keys(uniqueCategories).sort().map(id => uniqueCategories[id]);
populateCategorySelect(categories); populateCategorySelect(categories);
@ -644,9 +641,8 @@ window.qBittorrent.Search = (function() {
const searchPluginsEmpty = (searchPlugins.length === 0); const searchPluginsEmpty = (searchPlugins.length === 0);
if (!searchPluginsEmpty) { if (!searchPluginsEmpty) {
$("searchResultsNoPlugins").style.display = "none"; $("searchResultsNoPlugins").style.display = "none";
if (numSearchTabs() === 0) { if (numSearchTabs() === 0)
$("searchResultsNoSearches").style.display = "block"; $("searchResultsNoSearches").style.display = "block";
}
// sort plugins alphabetically // sort plugins alphabetically
const allPlugins = searchPlugins.sort((left, right) => { const allPlugins = searchPlugins.sort((left, right) => {
@ -681,9 +677,10 @@ window.qBittorrent.Search = (function() {
}; };
const getPlugin = function(name) { const getPlugin = function(name) {
for (let i = 0; i < searchPlugins.length; ++i) for (let i = 0; i < searchPlugins.length; ++i) {
if (searchPlugins[i].name === name) if (searchPlugins[i].name === name)
return searchPlugins[i]; return searchPlugins[i];
}
return null; return null;
}; };
@ -743,14 +740,16 @@ window.qBittorrent.Search = (function() {
}; };
const setupSearchTableEvents = function(enable) { const setupSearchTableEvents = function(enable) {
if (enable) if (enable) {
$$(".searchTableRow").each((target) => { $$(".searchTableRow").each((target) => {
target.addEventListener("dblclick", downloadSearchTorrent, false); target.addEventListener("dblclick", downloadSearchTorrent, false);
}); });
else }
else {
$$(".searchTableRow").each((target) => { $$(".searchTableRow").each((target) => {
target.removeEventListener("dblclick", downloadSearchTorrent, false); target.removeEventListener("dblclick", downloadSearchTorrent, false);
}); });
}
}; };
const loadSearchResultsData = function(searchId) { const loadSearchResultsData = function(searchId) {
@ -819,9 +818,8 @@ window.qBittorrent.Search = (function() {
// only update table if this search is currently being displayed // only update table if this search is currently being displayed
if (searchId === getSelectedSearchId()) { if (searchId === getSelectedSearchId()) {
for (const row of newRows) { for (const row of newRows)
searchResultsTable.updateRowData(row); searchResultsTable.updateRowData(row);
}
$("numSearchResultsVisible").set("html", searchResultsTable.getFilteredAndSortedRows().length); $("numSearchResultsVisible").set("html", searchResultsTable.getFilteredAndSortedRows().length);
$("numSearchResultsTotal").set("html", searchResultsTable.getRowIds().length); $("numSearchResultsTotal").set("html", searchResultsTable.getRowIds().length);

View file

@ -92,11 +92,12 @@ MochaUI.extend({
onSuccess: function(data) { onSuccess: function(data) {
if (data) { if (data) {
let up_limit = data[hashes[0]]; let up_limit = data[hashes[0]];
for (const key in data) for (const key in data) {
if (up_limit !== data[key]) { if (up_limit !== data[key]) {
up_limit = 0; up_limit = 0;
break; break;
} }
}
if (up_limit < 0) if (up_limit < 0)
up_limit = 0; up_limit = 0;
new Slider($("uplimitSliderarea"), $("uplimitSliderknob"), { new Slider($("uplimitSliderarea"), $("uplimitSliderknob"), {
@ -195,11 +196,12 @@ MochaUI.extend({
onSuccess: function(data) { onSuccess: function(data) {
if (data) { if (data) {
let dl_limit = data[hashes[0]]; let dl_limit = data[hashes[0]];
for (const key in data) for (const key in data) {
if (dl_limit !== data[key]) { if (dl_limit !== data[key]) {
dl_limit = 0; dl_limit = 0;
break; break;
} }
}
if (dl_limit < 0) if (dl_limit < 0)
dl_limit = 0; dl_limit = 0;
new Slider($("dllimitSliderarea"), $("dllimitSliderknob"), { new Slider($("dllimitSliderarea"), $("dllimitSliderknob"), {

View file

@ -79,9 +79,8 @@
$("save").addEvent("click", (e) => { $("save").addEvent("click", (e) => {
new Event(e).stop(); new Event(e).stop();
if (!isFormValid()) { if (!isFormValid())
return false; return false;
}
const shareLimit = getSelectedRadioValue("shareLimit"); const shareLimit = getSelectedRadioValue("shareLimit");
let ratioLimitValue = 0.00; let ratioLimitValue = 0.00;
@ -124,11 +123,10 @@
for (let i = 0; i < radios.length; ++i) { for (let i = 0; i < radios.length; ++i) {
const radio = radios[i]; const radio = radios[i];
if (radio.checked) { if (radio.checked)
return (radio).get("value"); return (radio).get("value");
} }
} }
}
function setSelectedRadioValue(name, value) { function setSelectedRadioValue(name, value) {
const radios = document.getElementsByName(name); const radios = document.getElementsByName(name);

View file

@ -169,9 +169,8 @@
window.parent.qBittorrent.Client.closeWindows(); window.parent.qBittorrent.Client.closeWindows();
}); });
if ((Browser.platform === "ios") || ((Browser.platform === "mac") && (navigator.maxTouchPoints > 1))) { if ((Browser.platform === "ios") || ((Browser.platform === "mac") && (navigator.maxTouchPoints > 1)))
$("fileselect").accept = ".torrent"; $("fileselect").accept = ".torrent";
}
</script> </script>
</body> </body>

View file

@ -44,9 +44,8 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.Filters = (function() { window.qBittorrent.Filters = (function() {
const exports = function() { const exports = function() {

View file

@ -29,9 +29,8 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.InstallSearchPlugin = (function() { window.qBittorrent.InstallSearchPlugin = (function() {
const exports = function() { const exports = function() {
@ -62,7 +61,7 @@
const newPluginOk = function() { const newPluginOk = function() {
const path = $("newPluginPath").get("value").trim(); const path = $("newPluginPath").get("value").trim();
if (path) if (path) {
new Request({ new Request({
url: "api/v2/search/installPlugin", url: "api/v2/search/installPlugin",
method: "post", method: "post",
@ -73,6 +72,7 @@
window.qBittorrent.SearchPlugins.closeSearchWindow("installSearchPlugin"); window.qBittorrent.SearchPlugins.closeSearchWindow("installSearchPlugin");
} }
}).send(); }).send();
}
}; };
init(); init();

View file

@ -148,9 +148,8 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.Log = (() => { window.qBittorrent.Log = (() => {
const exports = () => { const exports = () => {
@ -190,12 +189,10 @@
const init = () => { const init = () => {
$("logLevelSelect").getElements("option").each((x) => { $("logLevelSelect").getElements("option").each((x) => {
if (selectedLogLevels.indexOf(x.value.toString()) !== -1) { if (selectedLogLevels.indexOf(x.value.toString()) !== -1)
x.selected = true; x.selected = true;
} else
else {
x.selected = false; x.selected = false;
}
}); });
selectBox = new vanillaSelectBox("#logLevelSelect", { selectBox = new vanillaSelectBox("#logLevelSelect", {
@ -330,9 +327,9 @@
logFilterTimer = -1; logFilterTimer = -1;
load(); load();
if (tableInfo[currentSelectedTab].instance.filterText !== getFilterText()) { if (tableInfo[currentSelectedTab].instance.filterText !== getFilterText())
tableInfo[currentSelectedTab].instance.updateTable(); tableInfo[currentSelectedTab].instance.updateTable();
}
updateLabelCount(); updateLabelCount();
}; };

View file

@ -1537,9 +1537,8 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.Preferences = (function() { window.qBittorrent.Preferences = (function() {
const exports = function() { const exports = function() {
@ -1893,12 +1892,10 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
}; };
const registerDynDns = function() { 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"); window.open("http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html", "NO-IP Registration");
} else
else {
window.open("https://www.dyndns.com/account/services/hosts/add.html", "DynDNS Registration"); window.open("https://www.dyndns.com/account/services/hosts/add.html", "DynDNS Registration");
}
}; };
const generateRandomPort = function() { const generateRandomPort = function() {

View file

@ -158,9 +158,8 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
const serverSyncRssDataInterval = 1500; const serverSyncRssDataInterval = 1500;
@ -369,13 +368,14 @@
let visibleArticles = []; let visibleArticles = [];
for (const feedEntry in feedData) { for (const feedEntry in feedData) {
if (childFeeds.has(feedEntry)) if (childFeeds.has(feedEntry)) {
visibleArticles.append(feedData[feedEntry] visibleArticles.append(feedData[feedEntry]
.map((a) => { .map((a) => {
a.feedUid = feedEntry; a.feedUid = feedEntry;
return a; return a;
})); }));
} }
}
//filter read articles if "Unread" feed is selected //filter read articles if "Unread" feed is selected
if (path === "") if (path === "")
visibleArticles = visibleArticles.filter((a) => !a.isRead); visibleArticles = visibleArticles.filter((a) => !a.isRead);
@ -712,9 +712,10 @@
const markItemAsRead = (path) => { const markItemAsRead = (path) => {
// feed data mark as read // feed data mark as read
for (const feedID in feedData) for (const feedID in feedData) {
if (pathByFeedId.get(feedID).slice(0, path.length) === path) if (pathByFeedId.get(feedID).slice(0, path.length) === path)
feedData[feedID].each((el) => el.isRead = true); feedData[feedID].each((el) => el.isRead = true);
}
// mark rows as read // mark rows as read
rssArticleTable.rows.each((el) => el.full_data.isRead = true); rssArticleTable.rows.each((el) => el.full_data.isRead = true);

View file

@ -330,9 +330,8 @@ Supports the formats: S01E01, 1x1, 2017.12.31 and 31.12.2017 (Date formats also
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.RssDownloader = (() => { window.qBittorrent.RssDownloader = (() => {
const exports = () => { const exports = () => {

View file

@ -79,9 +79,8 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.SearchPlugins = (function() { window.qBittorrent.SearchPlugins = (function() {
const exports = function() { const exports = function() {
@ -187,16 +186,18 @@
}; };
const setupSearchPluginTableEvents = function(enable) { const setupSearchPluginTableEvents = function(enable) {
if (enable) if (enable) {
$$(".searchPluginsTableRow").each((target) => { $$(".searchPluginsTableRow").each((target) => {
target.addEventListener("dblclick", enablePlugin, false); target.addEventListener("dblclick", enablePlugin, false);
target.addEventListener("contextmenu", updateSearchPluginsTableContextMenuOffset, true); target.addEventListener("contextmenu", updateSearchPluginsTableContextMenuOffset, true);
}); });
else }
else {
$$(".searchPluginsTableRow").each((target) => { $$(".searchPluginsTableRow").each((target) => {
target.removeEventListener("dblclick", enablePlugin, false); target.removeEventListener("dblclick", enablePlugin, false);
target.removeEventListener("contextmenu", updateSearchPluginsTableContextMenuOffset, true); target.removeEventListener("contextmenu", updateSearchPluginsTableContextMenuOffset, true);
}); });
}
}; };
const updateTable = function() { const updateTable = function() {

View file

@ -18,9 +18,8 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) { if (window.qBittorrent === undefined)
window.qBittorrent = {}; window.qBittorrent = {};
}
window.qBittorrent.TransferList = (function() { window.qBittorrent.TransferList = (function() {
const exports = function() { const exports = function() {