Merge pull request #20928 from Chocobo1/webui_curly

WebUI: unify coding style
This commit is contained in:
Chocobo1 2024-06-17 13:09:18 +08:00 committed by GitHub
commit 2000be12ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 206 additions and 280 deletions

View File

@ -26,6 +26,7 @@ export default [
Stylistic
},
rules: {
"curly": ["error", "multi-or-nest", "consistent"],
"eqeqeq": "error",
"guard-for-in": "error",
"no-undef": "off",
@ -52,7 +53,8 @@ export default [
"allowTemplateLiterals": true
}
],
"Stylistic/semi": "error"
"Stylistic/semi": "error",
"Stylistic/spaced-comment": ["error", "always", { "exceptions": ["*"] }]
}
}
];

View File

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

View File

@ -14,9 +14,8 @@
<script>
"use strict";
if (window.parent.qBittorrent !== undefined) {
if (window.parent.qBittorrent !== undefined)
window.qBittorrent = window.parent.qBittorrent;
}
window.qBittorrent = window.parent.qBittorrent;
const TriState = window.qBittorrent.FileTree.TriState;
@ -51,9 +50,8 @@
const tableHeaders = $$("#bulkRenameFilesTableFixedHeaderDiv .dynamicTableHeader th");
let checkboxHeader;
if (tableHeaders.length > 0) {
if (checkboxHeader) {
if (checkboxHeader)
checkboxHeader.remove();
}
checkboxHeader = new Element("input");
checkboxHeader.set("type", "checkbox");
checkboxHeader.set("id", "rootMultiRename_cb");
@ -218,9 +216,12 @@
});
$("file_counter").addEvent("input", (e) => {
let value = e.target.valueAsNumber;
if (!value) { value = 0; }
if (value < 0) { value = 0; }
if (value > 99999999) { value = 99999999; }
if (!value)
value = 0;
if (value < 0)
value = 0;
if (value > 99999999)
value = 99999999;
fileRenamer.fileEnumerationStart = value;
$("file_counter").set("value", value);
LocalPreferences.set("multirename_fileEnumerationStart", value);
@ -265,9 +266,8 @@
// Recreate table
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());
}
bulkRenameFilesTable.clear();
// Adjust file enumeration count by 1 when replacing single files to prevent naming conflicts
@ -278,22 +278,18 @@
setupTable(selectedRows);
};
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}\``);
}
};
$("renameOptions").addEvent("change", (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 {
else
fileRenamer.replaceAll = false;
}
LocalPreferences.set("multirename_replaceAll", fileRenamer.replaceAll);
$("renameButton").set("value", replaceOperation);
});
@ -336,9 +332,8 @@
pathItems.pop(); // remove last item (i.e. file name)
let parent = rootNode;
pathItems.forEach((folderName) => {
if (folderName === ".unwanted") {
if (folderName === ".unwanted")
return;
}
let folderNode = null;
if (parent.children !== null) {
@ -387,9 +382,9 @@
bulkRenameFilesTable.updateTable(false);
bulkRenameFilesTable.altRow();
if (selectedRows !== undefined) {
if (selectedRows !== undefined)
bulkRenameFilesTable.reselectRows(selectedRows);
}
fileRenamer.selectedFiles = bulkRenameFilesTable.getSelectedRows();
fileRenamer.update();
};
@ -400,12 +395,10 @@
noCache: true,
method: "get",
onSuccess: function(files) {
if (files.length === 0) {
if (files.length === 0)
bulkRenameFilesTable.clear();
}
else {
else
handleTorrentFiles(files, selectedRows);
}
}
}).send();
};

View File

@ -25,9 +25,8 @@
"use strict";
if (window.qBittorrent === undefined) {
if (window.qBittorrent === undefined)
window.qBittorrent = {};
}
window.qBittorrent.Client = (() => {
const exports = () => {
@ -173,7 +172,7 @@ window.addEventListener("DOMContentLoaded", () => {
saveColumnSizes.delay(200); // Resizing might takes some time.
});
/*MochaUI.Desktop = new MochaUI.Desktop();
/* MochaUI.Desktop = new MochaUI.Desktop();
MochaUI.Desktop.desktop.setStyles({
'background': '#fff',
'visibility': 'visible'
@ -519,9 +518,8 @@ window.addEventListener("DOMContentLoaded", () => {
if (useSubcategories) {
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;
}
}
categoryList.appendChild(create_link(categoryHash, categoryName, categoryCount));
@ -600,9 +598,8 @@ window.addEventListener("DOMContentLoaded", () => {
// We want the hostname.
// 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;
}
try {
// hack: URL can not get hostname from udp protocol
@ -610,9 +607,8 @@ window.addEventListener("DOMContentLoaded", () => {
// host: "example.com:8443"
// hostname: "example.com"
const host = parsedUrl.hostname;
if (!host) {
if (!host)
return url;
}
return host;
}
@ -654,9 +650,8 @@ window.addEventListener("DOMContentLoaded", () => {
trackerList.forEach(({ host, trackerTorrentMap }, hash) => {
const uniqueTorrents = new Set();
for (const torrents of trackerTorrentMap.values()) {
for (const torrent of torrents) {
for (const torrent of torrents)
uniqueTorrents.add(torrent);
}
}
sortedList.push({
@ -745,9 +740,8 @@ window.addEventListener("DOMContentLoaded", () => {
category_list.clear();
tagList.clear();
}
if (response["rid"]) {
if (response["rid"])
syncMainDataLastResponseId = response["rid"];
}
if (response["categories"]) {
for (const key in response["categories"]) {
if (!Object.hasOwn(response["categories"], key))
@ -816,9 +810,8 @@ window.addEventListener("DOMContentLoaded", () => {
const tracker = response["trackers_removed"][i];
const hash = window.qBittorrent.Client.genHash(getHost(tracker));
const trackerListEntry = trackerList.get(hash);
if (trackerListEntry) {
if (trackerListEntry)
trackerListEntry.trackerTorrentMap.delete(tracker);
}
}
updateTrackers = true;
}
@ -844,7 +837,7 @@ window.addEventListener("DOMContentLoaded", () => {
if (updateTorrentList)
setupCopyEventHandler();
}
if (response["torrents_removed"])
if (response["torrents_removed"]) {
response["torrents_removed"].each((hash) => {
torrentsTable.removeRow(hash);
removeTorrentFromCategoryList(hash);
@ -852,6 +845,7 @@ window.addEventListener("DOMContentLoaded", () => {
removeTorrentFromTagList(hash);
updateTags = true; // Always to update All tag
});
}
torrentsTable.updateTable(full_update);
torrentsTable.altRow();
if (response["server_state"]) {

View File

@ -28,9 +28,8 @@
"use strict";
if (window.qBittorrent === undefined) {
if (window.qBittorrent === undefined)
window.qBittorrent = {};
}
window.qBittorrent.ContextMenu = (function() {
const exports = function() {
@ -48,10 +47,10 @@ window.qBittorrent.ContextMenu = (function() {
let lastShownContextMenu = null;
const ContextMenu = new Class({
//implements
// implements
Implements: [Options, Events],
//options
// options
options: {
actions: {},
menu: "menu_id",
@ -68,33 +67,31 @@ window.qBittorrent.ContextMenu = (function() {
touchTimer: 600
},
//initialization
// initialization
initialize: function(options) {
//set options
// set options
this.setOptions(options);
//option diffs menu
// option diffs menu
this.menu = $(this.options.menu);
this.targets = $$(this.options.targets);
//fx
// fx
this.fx = new Fx.Tween(this.menu, {
property: "opacity",
duration: this.options.fadeSpeed,
onComplete: function() {
if (this.getStyle("opacity")) {
if (this.getStyle("opacity"))
this.setStyle("visibility", "visible");
}
else {
else
this.setStyle("visibility", "hidden");
}
}.bind(this.menu)
});
//hide and begin the listener
// hide and begin the listener
this.hide().startListener();
//hide the menu
// hide the menu
this.menu.setStyles({
"position": "absolute",
"top": "-900000px",
@ -182,9 +179,8 @@ window.qBittorrent.ContextMenu = (function() {
this.touchStartEvent = null;
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);
}
});
},
@ -201,18 +197,17 @@ window.qBittorrent.ContextMenu = (function() {
if (this.options.disabled)
return;
//prevent default, if told to
if (this.options.stopEvent) {
// prevent default, if told to
if (this.options.stopEvent)
e.stop();
}
//record this as the trigger
// record this as the trigger
this.options.element = $(el);
this.adjustMenuPosition(e);
//show the menu
// show the menu
this.show();
},
//get things started
// get things started
startListener: function() {
/* all elements */
this.targets.each((el) => {
@ -230,7 +225,7 @@ window.qBittorrent.ContextMenu = (function() {
});
}, this);
//hide on body click
// hide on body click
$(document.body).addEvent("click", () => {
this.hide();
});
@ -238,7 +233,7 @@ window.qBittorrent.ContextMenu = (function() {
updateMenuItems: function() {},
//show menu
// show menu
show: function(trigger) {
if (lastShownContextMenu && (lastShownContextMenu !== this))
lastShownContextMenu.hide();
@ -248,11 +243,11 @@ window.qBittorrent.ContextMenu = (function() {
return this;
},
//hide the menu
// hide the menu
hide: function(trigger) {
if (lastShownContextMenu && (lastShownContextMenu.menu.style.visibility !== "hidden")) {
this.fx.start(0);
//this.menu.fade('out');
// this.menu.fade('out');
this.fireEvent("hide");
}
return this;
@ -268,35 +263,34 @@ window.qBittorrent.ContextMenu = (function() {
return this.menu.getElement("a[href$=" + item + "]").firstChild.style.opacity !== "0";
},
//hide an item
// hide an item
hideItem: function(item) {
this.menu.getElement("a[href$=" + item + "]").parentNode.addClass("invisible");
return this;
},
//show an item
// show an item
showItem: function(item) {
this.menu.getElement("a[href$=" + item + "]").parentNode.removeClass("invisible");
return this;
},
//disable the entire menu
// disable the entire menu
disable: function() {
this.options.disabled = true;
return this;
},
//enable the entire menu
// enable the entire menu
enable: function() {
this.options.disabled = false;
return this;
},
//execute an action
// execute an action
execute: function(action, element) {
if (this.options.actions[action]) {
if (this.options.actions[action])
this.options.actions[action](element, this, action);
}
return this;
}
});
@ -515,12 +509,10 @@ window.qBittorrent.ContextMenu = (function() {
if ((id !== CATEGORIES_ALL) && (id !== CATEGORIES_UNCATEGORIZED)) {
this.showItem("editCategory");
this.showItem("deleteCategory");
if (useSubcategories) {
if (useSubcategories)
this.showItem("createSubcategory");
}
else {
else
this.hideItem("createSubcategory");
}
}
else {
this.hideItem("editCategory");
@ -547,9 +539,10 @@ window.qBittorrent.ContextMenu = (function() {
updateMenuItems: function() {
const enabledColumnIndex = function(text) {
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")
return i;
}
};
this.showItem("Enabled");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,9 +28,8 @@
"use strict";
if (window.qBittorrent === undefined) {
if (window.qBittorrent === undefined)
window.qBittorrent = {};
}
window.qBittorrent.PropWebseeds = (function() {
const exports = function() {
@ -65,9 +64,8 @@ window.qBittorrent.PropWebseeds = (function() {
updateRow: function(tr, row) {
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]);
}
return true;
},
@ -78,7 +76,7 @@ window.qBittorrent.PropWebseeds = (function() {
this.updateRow(tableRow, row);
return;
}
//this.removeRow(id);
// this.removeRow(id);
const tr = new Element("tr");
this.rows.set(url, tr);
for (let i = 0; i < row.length; ++i) {

View File

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

View File

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

View File

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

View File

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

View File

@ -169,9 +169,8 @@
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";
}
</script>
</body>

View File

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

View File

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

View File

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

View File

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

View File

@ -158,9 +158,8 @@
<script>
"use strict";
if (window.qBittorrent === undefined) {
if (window.qBittorrent === undefined)
window.qBittorrent = {};
}
const serverSyncRssDataInterval = 1500;
@ -369,14 +368,15 @@
let visibleArticles = [];
for (const feedEntry in feedData) {
if (childFeeds.has(feedEntry))
if (childFeeds.has(feedEntry)) {
visibleArticles.append(feedData[feedEntry]
.map((a) => {
a.feedUid = feedEntry;
return a;
}));
}
}
//filter read articles if "Unread" feed is selected
// filter read articles if "Unread" feed is selected
if (path === "")
visibleArticles = visibleArticles.filter((a) => !a.isRead);
@ -427,7 +427,7 @@
$("rssDetailsView").append(torrentDescription);
document.getElementById("rssDescription").srcdoc = '<html><head><link rel="stylesheet" type="text/css" href="css/style.css" /></head><body>' + article.description + "</body></html>";
//calculate height to fill screen
// calculate height to fill screen
document.getElementById("rssDescription").style.height =
"calc(100% - " + document.getElementById("rssTorrentDetailsName").offsetHeight + "px - "
+ document.getElementById("rssTorrentDetailsDate").offsetHeight + "px - 5px)";
@ -712,9 +712,10 @@
const markItemAsRead = (path) => {
// feed data mark as read
for (const feedID in feedData)
for (const feedID in feedData) {
if (pathByFeedId.get(feedID).slice(0, path.length) === path)
feedData[feedID].each((el) => el.isRead = true);
}
// mark rows as read
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>
"use strict";
if (window.qBittorrent === undefined) {
if (window.qBittorrent === undefined)
window.qBittorrent = {};
}
window.qBittorrent.RssDownloader = (() => {
const exports = () => {

View File

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

View File

@ -18,9 +18,8 @@
<script>
"use strict";
if (window.qBittorrent === undefined) {
if (window.qBittorrent === undefined)
window.qBittorrent = {};
}
window.qBittorrent.TransferList = (function() {
const exports = function() {
@ -29,7 +28,7 @@
};
};
//create a context menu
// create a context menu
const contextMenu = new window.qBittorrent.ContextMenu.TorrentsTableContextMenu({
targets: ".torrentsTableContextMenuTarget",
menu: "torrentsTableMenu",