From 72cbc83569bb48fa61b55851c83bedeb1e9c6f01 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 1 Nov 2024 04:17:41 +0800 Subject: [PATCH] WebUI: prefer arrow functions whenever applicable Compared to plain function, arrow function is simpler to understand (without bindings to `this`, `arguments`, `super`) and to read. Now, plain function will only be used when this object is required. PR #21691. --- src/webui/www/eslint.config.mjs | 3 + src/webui/www/package.json | 1 + src/webui/www/private/addpeers.html | 4 +- src/webui/www/private/addtrackers.html | 2 +- src/webui/www/private/addwebseeds.html | 2 +- .../www/private/confirmtrackerdeletion.html | 2 +- src/webui/www/private/downloadlimit.html | 6 +- src/webui/www/private/edittracker.html | 2 +- src/webui/www/private/editwebseed.html | 2 +- src/webui/www/private/newcategory.html | 18 +- src/webui/www/private/newtag.html | 6 +- src/webui/www/private/rename.html | 2 +- src/webui/www/private/rename_file.html | 4 +- src/webui/www/private/rename_files.html | 20 +- src/webui/www/private/scripts/client.js | 144 +++++------ src/webui/www/private/scripts/contextmenu.js | 2 +- src/webui/www/private/scripts/download.js | 10 +- src/webui/www/private/scripts/dynamicTable.js | 74 +++--- src/webui/www/private/scripts/file-tree.js | 2 +- src/webui/www/private/scripts/filesystem.js | 6 +- .../www/private/scripts/localpreferences.js | 6 +- src/webui/www/private/scripts/misc.js | 26 +- src/webui/www/private/scripts/mocha-init.js | 224 +++++++++--------- src/webui/www/private/scripts/pathAutofill.js | 8 +- src/webui/www/private/scripts/piecesbar.js | 6 +- src/webui/www/private/scripts/progressbar.js | 10 +- src/webui/www/private/scripts/prop-files.js | 98 ++++---- src/webui/www/private/scripts/prop-general.js | 16 +- src/webui/www/private/scripts/prop-peers.js | 16 +- .../www/private/scripts/prop-trackers.js | 30 +-- .../www/private/scripts/prop-webseeds.js | 30 +-- src/webui/www/private/scripts/rename-files.js | 8 +- src/webui/www/private/scripts/search.js | 80 +++---- src/webui/www/private/scripts/speedslider.js | 28 +-- src/webui/www/private/setlocation.html | 4 +- src/webui/www/private/shareratio.html | 22 +- src/webui/www/private/uploadlimit.html | 6 +- src/webui/www/private/views/aboutToolbar.html | 2 +- .../www/private/views/confirmRecheck.html | 4 +- .../www/private/views/confirmdeletion.html | 6 +- src/webui/www/private/views/cookies.html | 10 +- src/webui/www/private/views/filters.html | 18 +- .../private/views/installsearchplugin.html | 6 +- src/webui/www/private/views/log.html | 6 +- src/webui/www/private/views/preferences.html | 94 ++++---- .../www/private/views/preferencesToolbar.html | 2 +- .../www/private/views/searchplugins.html | 20 +- src/webui/www/private/views/transferlist.html | 42 ++-- src/webui/www/public/scripts/login.js | 4 +- 49 files changed, 574 insertions(+), 570 deletions(-) diff --git a/src/webui/www/eslint.config.mjs b/src/webui/www/eslint.config.mjs index e77e7d422..293288b03 100644 --- a/src/webui/www/eslint.config.mjs +++ b/src/webui/www/eslint.config.mjs @@ -1,6 +1,7 @@ import Globals from "globals"; import Html from "eslint-plugin-html"; import Js from "@eslint/js"; +import PreferArrowFunctions from "eslint-plugin-prefer-arrow-functions"; import Stylistic from "@stylistic/eslint-plugin"; import * as RegexpPlugin from "eslint-plugin-regexp"; @@ -22,6 +23,7 @@ export default [ }, plugins: { Html, + PreferArrowFunctions, RegexpPlugin, Stylistic }, @@ -36,6 +38,7 @@ export default [ "prefer-arrow-callback": "error", "prefer-const": "error", "radix": "error", + "PreferArrowFunctions/prefer-arrow-functions": "error", "Stylistic/no-mixed-operators": [ "error", { diff --git a/src/webui/www/package.json b/src/webui/www/package.json index bad08c881..818d48738 100644 --- a/src/webui/www/package.json +++ b/src/webui/www/package.json @@ -13,6 +13,7 @@ "@stylistic/eslint-plugin": "*", "eslint": "*", "eslint-plugin-html": "*", + "eslint-plugin-prefer-arrow-functions": "*", "eslint-plugin-regexp": "*", "html-validate": "*", "js-beautify": "*", diff --git a/src/webui/www/private/addpeers.html b/src/webui/www/private/addpeers.html index 6bc225449..89a89849d 100644 --- a/src/webui/www/private/addpeers.html +++ b/src/webui/www/private/addpeers.html @@ -46,10 +46,10 @@ hashes: hash, peers: peers.join("|") }, - onFailure: function() { + onFailure: () => { alert("QBT_TR(Unable to add peers. Please ensure you are adhering to the IP:port format.)QBT_TR[CONTEXT=HttpServer]"); }, - onSuccess: function() { + onSuccess: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); diff --git a/src/webui/www/private/addtrackers.html b/src/webui/www/private/addtrackers.html index f083cbb83..a9ade7115 100644 --- a/src/webui/www/private/addtrackers.html +++ b/src/webui/www/private/addtrackers.html @@ -38,7 +38,7 @@ hash: hash, urls: $("trackersUrls").value }, - onComplete: function() { + onComplete: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); diff --git a/src/webui/www/private/addwebseeds.html b/src/webui/www/private/addwebseeds.html index 08b28bda6..f266ecaba 100644 --- a/src/webui/www/private/addwebseeds.html +++ b/src/webui/www/private/addwebseeds.html @@ -36,7 +36,7 @@ hash: hash, urls: $("urls").value.split("\n").map(w => encodeURIComponent(w.trim())).filter(w => (w.length > 0)).join("|") }, - onComplete: function() { + onComplete: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); diff --git a/src/webui/www/private/confirmtrackerdeletion.html b/src/webui/www/private/confirmtrackerdeletion.html index cd8c467a3..610eacee6 100644 --- a/src/webui/www/private/confirmtrackerdeletion.html +++ b/src/webui/www/private/confirmtrackerdeletion.html @@ -30,7 +30,7 @@ hash: "*", urls: urls, }, - onComplete: function() { + onComplete: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); diff --git a/src/webui/www/private/downloadlimit.html b/src/webui/www/private/downloadlimit.html index 28753d259..931604099 100644 --- a/src/webui/www/private/downloadlimit.html +++ b/src/webui/www/private/downloadlimit.html @@ -32,7 +32,7 @@ "use strict"; const hashes = new URI().getData("hashes").split("|"); - const setDlLimit = function() { + const setDlLimit = () => { const limit = $("dllimitUpdatevalue").value.toInt() * 1024; if (hashes[0] === "global") { new Request({ @@ -41,7 +41,7 @@ data: { "limit": limit }, - onComplete: function() { + onComplete: () => { window.parent.updateMainData(); window.parent.qBittorrent.Client.closeWindows(); } @@ -55,7 +55,7 @@ "hashes": hashes.join("|"), "limit": limit }, - onComplete: function() { + onComplete: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); diff --git a/src/webui/www/private/edittracker.html b/src/webui/www/private/edittracker.html index 4e476fcf7..a30585284 100644 --- a/src/webui/www/private/edittracker.html +++ b/src/webui/www/private/edittracker.html @@ -49,7 +49,7 @@ origUrl: currentUrl, newUrl: $("trackerUrl").value }, - onComplete: function() { + onComplete: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); diff --git a/src/webui/www/private/editwebseed.html b/src/webui/www/private/editwebseed.html index 78b410d56..acbf49fc7 100644 --- a/src/webui/www/private/editwebseed.html +++ b/src/webui/www/private/editwebseed.html @@ -44,7 +44,7 @@ origUrl: origUrl, newUrl: encodeURIComponent($("url").value.trim()), }, - onComplete: function() { + onComplete: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); diff --git a/src/webui/www/private/newcategory.html b/src/webui/www/private/newcategory.html index 224afa3ac..b8cbf767c 100644 --- a/src/webui/www/private/newcategory.html +++ b/src/webui/www/private/newcategory.html @@ -60,7 +60,7 @@ const savePath = $("savePath").value.trim(); const categoryName = $("categoryName").value.trim(); - const verifyCategoryName = function(name) { + const verifyCategoryName = (name) => { if ((name === null) || (name === "")) return false; if (name.match("^([^\\\\\\/]|[^\\\\\\/]([^\\\\\\/]|\\/(?=[^\\/]))*[^\\\\\\/])$") === null) { @@ -82,7 +82,7 @@ category: categoryName, savePath: savePath }, - onSuccess: function() { + onSuccess: () => { new Request({ url: "api/v2/torrents/setCategory", method: "post", @@ -90,16 +90,16 @@ hashes: uriHashes, category: categoryName }, - onSuccess: function() { + onSuccess: () => { window.parent.updateMainData(); window.parent.qBittorrent.Client.closeWindows(); }, - onFailure: function() { + onFailure: () => { alert("QBT_TR(Unable to set category)QBT_TR[CONTEXT=Category]"); } }).send(); }, - onFailure: function() { + onFailure: () => { alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=Category] " + window.qBittorrent.Misc.escapeHtml(categoryName)); } }).send(); @@ -116,11 +116,11 @@ category: categoryName, savePath: savePath }, - onSuccess: function() { + onSuccess: () => { window.parent.updateMainData(); window.parent.qBittorrent.Client.closeWindows(); }, - onFailure: function() { + onFailure: () => { alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=Category]"); } }).send(); @@ -133,11 +133,11 @@ category: uriCategoryName, // category name can't be changed savePath: savePath }, - onSuccess: function() { + onSuccess: () => { window.parent.updateMainData(); window.parent.qBittorrent.Client.closeWindows(); }, - onFailure: function() { + onFailure: () => { alert("QBT_TR(Unable to edit category)QBT_TR[CONTEXT=Category]"); } }).send(); diff --git a/src/webui/www/private/newtag.html b/src/webui/www/private/newtag.html index c661e98bb..fd11bb582 100644 --- a/src/webui/www/private/newtag.html +++ b/src/webui/www/private/newtag.html @@ -44,7 +44,7 @@ const tagName = $("tagName").value.trim(); - const verifyTagName = function(name) { + const verifyTagName = (name) => { if ((name === null) || (name === "")) return false; if (name.includes(",")) { @@ -66,7 +66,7 @@ hashes: uriHashes, tags: tagName, }, - onComplete: function() { + onComplete: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); @@ -82,7 +82,7 @@ data: { tags: tagName, }, - onComplete: function() { + onComplete: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); diff --git a/src/webui/www/private/rename.html b/src/webui/www/private/rename.html index a59b7379c..301cbb691 100644 --- a/src/webui/www/private/rename.html +++ b/src/webui/www/private/rename.html @@ -54,7 +54,7 @@ hash: hash, name: name }, - onComplete: function() { + onComplete: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); diff --git a/src/webui/www/private/rename_file.html b/src/webui/www/private/rename_file.html index bdb10aae3..d847023d3 100644 --- a/src/webui/www/private/rename_file.html +++ b/src/webui/www/private/rename_file.html @@ -71,10 +71,10 @@ oldPath: oldPath, newPath: newPath }, - onSuccess: function() { + onSuccess: () => { window.parent.qBittorrent.Client.closeWindows(); }, - onFailure: function() { + onFailure: () => { alert("QBT_TR(Failed to update name)QBT_TR[CONTEXT=HttpServer]"); $("renameButton").disabled = false; } diff --git a/src/webui/www/private/rename_files.html b/src/webui/www/private/rename_files.html index 59f68b2e9..77abd6520 100644 --- a/src/webui/www/private/rename_files.html +++ b/src/webui/www/private/rename_files.html @@ -24,7 +24,7 @@ targets: "#bulkRenameFilesTableDiv tr", menu: "multiRenameFilesMenu", actions: { - ToggleSelection: function(element, ref) { + ToggleSelection: (element, ref) => { const rowId = parseInt(element.getAttribute("data-row-id"), 10); const row = bulkRenameFilesTable.getNode(rowId); const checkState = (row.checked === 1) ? 0 : 1; @@ -128,7 +128,7 @@ } // Fires every time a row's selection changes - bulkRenameFilesTable.onRowSelectionChange = function(row) { + bulkRenameFilesTable.onRowSelectionChange = (row) => { fileRenamer.selectedFiles = bulkRenameFilesTable.getSelectedRows(); fileRenamer.update(); }; @@ -162,7 +162,7 @@ /** * Fires every time the filerenamer gets changed, it will update all the rows in the table */ - fileRenamer.onChanged = function(matchedRows) { + fileRenamer.onChanged = (matchedRows) => { // Clear renamed column document .querySelectorAll("span[id^='filesTablefileRenamed']") @@ -176,7 +176,7 @@ $("filesTablefileRenamed" + row.rowId).textContent = row.renamed; } }; - fileRenamer.onInvalidRegex = function(err) { + fileRenamer.onInvalidRegex = (err) => { $("multiRenameSearch").style["border-color"] = "#CC0033"; }; @@ -239,7 +239,7 @@ $("rename_error").textContent = ""; fileRenamer.rename(); }); - fileRenamer.onRenamed = function(rows) { + fileRenamer.onRenamed = (rows) => { // Disable Search Options $("multiRenameSearch").disabled = false; $("use_regex_search").disabled = false; @@ -268,7 +268,7 @@ } setupTable(selectedRows); }; - fileRenamer.onRenameError = function(err, row) { + fileRenamer.onRenameError = (err, row) => { if (err.xhr.status === 409) $("rename_error").textContent = `QBT_TR(Rename failed: file or folder already exists)QBT_TR[CONTEXT=PropertiesWidget] \`${row.renamed}\``; }; @@ -294,7 +294,7 @@ $("bulkRenameFilesTableFixedHeaderDiv").scrollLeft = length; }; - const handleTorrentFiles = function(files, selectedRows) { + const handleTorrentFiles = (files, selectedRows) => { const rows = files.map((file, index) => { const row = { @@ -312,7 +312,7 @@ addRowsToTable(rows, selectedRows); }; - const addRowsToTable = function(rows, selectedRows) { + const addRowsToTable = (rows, selectedRows) => { let rowId = 0; const rootNode = new window.qBittorrent.FileTree.FolderNode(); rootNode.autoCheckFolders = false; @@ -379,12 +379,12 @@ fileRenamer.update(); }; - const setupTable = function(selectedRows) { + const setupTable = (selectedRows) => { new Request.JSON({ url: new URI("api/v2/torrents/files?hash=" + data.hash), noCache: true, method: "get", - onSuccess: function(files) { + onSuccess: (files) => { if (files.length === 0) bulkRenameFilesTable.clear(); else diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index e2c3771d3..21c6a9604 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -44,18 +44,18 @@ window.qBittorrent.Client ??= (() => { }; }; - const closeWindow = function(windowID) { + const closeWindow = (windowID) => { const window = document.getElementById(windowID); if (!window) return; MochaUI.closeWindow(window); }; - const closeWindows = function() { + const closeWindows = () => { MochaUI.closeAll(); }; - const getSyncMainDataInterval = function() { + const getSyncMainDataInterval = () => { return customSyncMainDataInterval ? customSyncMainDataInterval : serverSyncMainDataInterval; }; @@ -81,22 +81,22 @@ window.qBittorrent.Client ??= (() => { let showingRssReader = false; let showingLogViewer = false; - const showSearchEngine = function(bool) { + const showSearchEngine = (bool) => { showingSearchEngine = bool; }; - const showRssReader = function(bool) { + const showRssReader = (bool) => { showingRssReader = bool; }; - const showLogViewer = function(bool) { + const showLogViewer = (bool) => { showingLogViewer = bool; }; - const isShowSearchEngine = function() { + const isShowSearchEngine = () => { return showingSearchEngine; }; - const isShowRssReader = function() { + const isShowRssReader = () => { return showingRssReader; }; - const isShowLogViewer = function() { + const isShowLogViewer = () => { return showingLogViewer; }; @@ -108,9 +108,9 @@ Object.freeze(window.qBittorrent.Client); this.torrentsTable = new window.qBittorrent.DynamicTable.TorrentsTable(); -let updatePropertiesPanel = function() {}; +let updatePropertiesPanel = () => {}; -this.updateMainData = function() {}; +this.updateMainData = () => {}; let alternativeSpeedLimits = false; let queueing_enabled = true; let serverSyncMainDataInterval = 1500; @@ -126,7 +126,7 @@ const CATEGORIES_UNCATEGORIZED = 2; const category_list = new Map(); let selectedCategory = Number(LocalPreferences.get("selected_category", CATEGORIES_ALL)); -let setCategoryFilter = function() {}; +let setCategoryFilter = () => {}; /* Tags filter */ const TAGS_ALL = 1; @@ -135,7 +135,7 @@ const TAGS_UNTAGGED = 2; const tagList = new Map(); let selectedTag = Number(LocalPreferences.get("selected_tag", TAGS_ALL)); -let setTagFilter = function() {}; +let setTagFilter = () => {}; /* Trackers filter */ const TRACKERS_ALL = 1; @@ -145,19 +145,19 @@ const TRACKERS_TRACKERLESS = 2; const trackerList = new Map(); let selectedTracker = Number(LocalPreferences.get("selected_tracker", TRACKERS_ALL)); -let setTrackerFilter = function() {}; +let setTrackerFilter = () => {}; /* All filters */ let selectedStatus = LocalPreferences.get("selected_filter", "all"); -let setStatusFilter = function() {}; -let toggleFilterDisplay = function() {}; +let setStatusFilter = () => {}; +let toggleFilterDisplay = () => {}; window.addEventListener("DOMContentLoaded", () => { let isSearchPanelLoaded = false; let isLogPanelLoaded = false; let isRssPanelLoaded = false; - const saveColumnSizes = function() { + const saveColumnSizes = () => { const filters_width = $("Filters").getSize().x; LocalPreferences.set("filters_width", filters_width); const properties_height_rel = $("propertiesPanel").getSize().y / Window.getSize().y; @@ -175,7 +175,7 @@ window.addEventListener("DOMContentLoaded", () => { MochaUI.Desktop.desktop.style.visibility = "visible"; */ MochaUI.Desktop.initialize(); - const buildTransfersTab = function() { + const buildTransfersTab = () => { new MochaUI.Column({ id: "filtersColumn", placement: "left", @@ -191,7 +191,7 @@ window.addEventListener("DOMContentLoaded", () => { }); }; - const buildSearchTab = function() { + const buildSearchTab = () => { new MochaUI.Column({ id: "searchTabColumn", placement: "main", @@ -202,7 +202,7 @@ window.addEventListener("DOMContentLoaded", () => { $("searchTabColumn").addClass("invisible"); }; - const buildRssTab = function() { + const buildRssTab = () => { new MochaUI.Column({ id: "rssTabColumn", placement: "main", @@ -213,7 +213,7 @@ window.addEventListener("DOMContentLoaded", () => { $("rssTabColumn").addClass("invisible"); }; - const buildLogTab = function() { + const buildLogTab = () => { new MochaUI.Column({ id: "logTabColumn", placement: "main", @@ -230,7 +230,7 @@ window.addEventListener("DOMContentLoaded", () => { buildLogTab(); MochaUI.initializeTabs("mainWindowTabsList"); - const handleFilterSelectionChange = function(prevSelectedTorrent, currSelectedTorrent) { + const handleFilterSelectionChange = (prevSelectedTorrent, currSelectedTorrent) => { // clear properties panels when filter changes (e.g. selected torrent is no longer visible) if (prevSelectedTorrent !== currSelectedTorrent) { window.qBittorrent.PropGeneral.clear(); @@ -241,7 +241,7 @@ window.addEventListener("DOMContentLoaded", () => { } }; - setStatusFilter = function(name) { + setStatusFilter = (name) => { const currentHash = torrentsTable.getCurrentTorrentID(); LocalPreferences.set("selected_filter", name); @@ -253,7 +253,7 @@ window.addEventListener("DOMContentLoaded", () => { handleFilterSelectionChange(currentHash, newHash); }; - setCategoryFilter = function(hash) { + setCategoryFilter = (hash) => { const currentHash = torrentsTable.getCurrentTorrentID(); LocalPreferences.set("selected_category", hash); @@ -265,7 +265,7 @@ window.addEventListener("DOMContentLoaded", () => { handleFilterSelectionChange(currentHash, newHash); }; - setTagFilter = function(hash) { + setTagFilter = (hash) => { const currentHash = torrentsTable.getCurrentTorrentID(); LocalPreferences.set("selected_tag", hash); @@ -277,7 +277,7 @@ window.addEventListener("DOMContentLoaded", () => { handleFilterSelectionChange(currentHash, newHash); }; - setTrackerFilter = function(hash) { + setTrackerFilter = (hash) => { const currentHash = torrentsTable.getCurrentTorrentID(); LocalPreferences.set("selected_tracker", hash); @@ -289,7 +289,7 @@ window.addEventListener("DOMContentLoaded", () => { handleFilterSelectionChange(currentHash, newHash); }; - toggleFilterDisplay = function(filterListID) { + toggleFilterDisplay = (filterListID) => { const filterList = document.getElementById(filterListID); const filterTitle = filterList.previousElementSibling; const toggleIcon = filterTitle.firstElementChild; @@ -309,7 +309,7 @@ window.addEventListener("DOMContentLoaded", () => { }, loadMethod: "xhr", contentURL: "views/filters.html", - onContentLoaded: function() { + onContentLoaded: () => { highlightSelectedStatus(); }, column: "filtersColumn", @@ -354,7 +354,7 @@ window.addEventListener("DOMContentLoaded", () => { let syncMainDataLastResponseId = 0; const serverState = {}; - const removeTorrentFromCategoryList = function(hash) { + const removeTorrentFromCategoryList = (hash) => { if (!hash) return false; @@ -367,7 +367,7 @@ window.addEventListener("DOMContentLoaded", () => { return removed; }; - const addTorrentToCategoryList = function(torrent) { + const addTorrentToCategoryList = (torrent) => { const category = torrent["category"]; if (typeof category === "undefined") return false; @@ -395,7 +395,7 @@ window.addEventListener("DOMContentLoaded", () => { return false; }; - const removeTorrentFromTagList = function(hash) { + const removeTorrentFromTagList = (hash) => { if (!hash) return false; @@ -408,7 +408,7 @@ window.addEventListener("DOMContentLoaded", () => { return removed; }; - const addTorrentToTagList = function(torrent) { + const addTorrentToTagList = (torrent) => { if (torrent["tags"] === undefined) // Tags haven't changed return false; @@ -438,7 +438,7 @@ window.addEventListener("DOMContentLoaded", () => { return added; }; - const updateFilter = function(filter, filterTitle) { + const updateFilter = (filter, filterTitle) => { const filterEl = document.getElementById(`${filter}_filter`); const filterTorrentCount = torrentsTable.getFilteredTorrentsNumber(filter, CATEGORIES_ALL, TAGS_ALL, TRACKERS_ALL); if (useAutoHideZeroStatusFilters) { @@ -449,7 +449,7 @@ window.addEventListener("DOMContentLoaded", () => { filterEl.firstElementChild.lastChild.nodeValue = filterTitle.replace("%1", filterTorrentCount); }; - const updateFiltersList = function() { + const updateFiltersList = () => { updateFilter("all", "QBT_TR(All (%1))QBT_TR[CONTEXT=StatusFilterWidget]"); updateFilter("downloading", "QBT_TR(Downloading (%1))QBT_TR[CONTEXT=StatusFilterWidget]"); updateFilter("seeding", "QBT_TR(Seeding (%1))QBT_TR[CONTEXT=StatusFilterWidget]"); @@ -466,14 +466,14 @@ window.addEventListener("DOMContentLoaded", () => { updateFilter("errored", "QBT_TR(Errored (%1))QBT_TR[CONTEXT=StatusFilterWidget]"); }; - const highlightSelectedStatus = function() { + const highlightSelectedStatus = () => { const statusFilter = document.getElementById("statusFilterList"); const filterID = `${selectedStatus}_filter`; for (const status of statusFilter.children) status.classList.toggle("selectedFilter", (status.id === filterID)); }; - const updateCategoryList = function() { + const updateCategoryList = () => { const categoryList = document.getElementById("categoryFilterList"); if (!categoryList) return; @@ -583,7 +583,7 @@ window.addEventListener("DOMContentLoaded", () => { window.qBittorrent.Filters.categoriesFilterContextMenu.searchAndAddTargets(); }; - const highlightSelectedCategory = function() { + const highlightSelectedCategory = () => { const categoryList = document.getElementById("categoryFilterList"); if (!categoryList) return; @@ -592,7 +592,7 @@ window.addEventListener("DOMContentLoaded", () => { category.classList.toggle("selectedFilter", (Number(category.id) === selectedCategory)); }; - const updateTagList = function() { + const updateTagList = () => { const tagFilterList = $("tagFilterList"); if (tagFilterList === null) return; @@ -601,7 +601,7 @@ window.addEventListener("DOMContentLoaded", () => { const tagItemTemplate = document.getElementById("tagFilterItem"); - const createLink = function(hash, text, count) { + const createLink = (hash, text, count) => { const tagFilterItem = tagItemTemplate.content.cloneNode(true).firstElementChild; tagFilterItem.id = hash; tagFilterItem.classList.toggle("selectedFilter", hash === selectedTag); @@ -635,7 +635,7 @@ window.addEventListener("DOMContentLoaded", () => { window.qBittorrent.Filters.tagsFilterContextMenu.searchAndAddTargets(); }; - const highlightSelectedTag = function() { + const highlightSelectedTag = () => { const tagFilterList = document.getElementById("tagFilterList"); if (!tagFilterList) return; @@ -644,7 +644,7 @@ window.addEventListener("DOMContentLoaded", () => { tag.classList.toggle("selectedFilter", (Number(tag.id) === selectedTag)); }; - const updateTrackerList = function() { + const updateTrackerList = () => { const trackerFilterList = $("trackerFilterList"); if (trackerFilterList === null) return; @@ -653,7 +653,7 @@ window.addEventListener("DOMContentLoaded", () => { const trackerItemTemplate = document.getElementById("trackerFilterItem"); - const createLink = function(hash, text, count) { + const createLink = (hash, text, count) => { const trackerFilterItem = trackerItemTemplate.content.cloneNode(true).firstElementChild; trackerFilterItem.id = hash; trackerFilterItem.classList.toggle("selectedFilter", hash === selectedTracker); @@ -695,7 +695,7 @@ window.addEventListener("DOMContentLoaded", () => { window.qBittorrent.Filters.trackersFilterContextMenu.searchAndAddTargets(); }; - const highlightSelectedTracker = function() { + const highlightSelectedTracker = () => { const trackerFilterList = document.getElementById("trackerFilterList"); if (!trackerFilterList) return; @@ -728,21 +728,21 @@ window.addEventListener("DOMContentLoaded", () => { let syncMainDataTimeoutID = -1; let syncRequestInProgress = false; - const syncMainData = function() { + const syncMainData = () => { const url = new URI("api/v2/sync/maindata"); url.setData("rid", syncMainDataLastResponseId); const request = new Request.JSON({ url: url, noCache: true, method: "get", - onFailure: function() { + onFailure: () => { const errorDiv = $("error_div"); if (errorDiv) errorDiv.textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]"; syncRequestInProgress = false; syncData(2000); }, - onSuccess: function(response) { + onSuccess: (response) => { $("error_div").textContent = ""; if (response) { clearTimeout(torrentsFilterInputTimer); @@ -909,12 +909,12 @@ window.addEventListener("DOMContentLoaded", () => { request.send(); }; - updateMainData = function() { + updateMainData = () => { torrentsTable.updateTable(); syncData(100); }; - const syncData = function(delay) { + const syncData = (delay) => { if (syncRequestInProgress) return; @@ -927,7 +927,7 @@ window.addEventListener("DOMContentLoaded", () => { syncMainDataTimeoutID = syncMainData.delay(delay); }; - const processServerState = function() { + const processServerState = () => { let transfer_info = window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_speed, true); if (serverState.dl_rate_limit > 0) transfer_info += " [" + window.qBittorrent.Misc.friendlyUnit(serverState.dl_rate_limit, true) + "]"; @@ -1028,7 +1028,7 @@ window.addEventListener("DOMContentLoaded", () => { serverSyncMainDataInterval = Math.max(serverState.refresh_interval, 500); }; - const updateAltSpeedIcon = function(enabled) { + const updateAltSpeedIcon = (enabled) => { if (enabled) { $("alternativeSpeedLimits").src = "images/slow.svg"; $("alternativeSpeedLimits").alt = "QBT_TR(Alternative speed limits: On)QBT_TR[CONTEXT=MainWindow]"; @@ -1048,11 +1048,11 @@ window.addEventListener("DOMContentLoaded", () => { new Request({ url: "api/v2/transfer/toggleSpeedLimitsMode", method: "post", - onComplete: function() { + onComplete: () => { alternativeSpeedLimits = !alternativeSpeedLimits; updateMainData(); }, - onFailure: function() { + onFailure: () => { // Restore icon in case of failure updateAltSpeedIcon(alternativeSpeedLimits); } @@ -1090,7 +1090,7 @@ window.addEventListener("DOMContentLoaded", () => { MochaUI.Desktop.setDesktopSize(); }); - const registerMagnetHandler = function() { + const registerMagnetHandler = () => { if (typeof navigator.registerProtocolHandler !== "function") { if (window.location.protocol !== "https:") alert("QBT_TR(To use this feature, the WebUI needs to be accessed over HTTPS)QBT_TR[CONTEXT=MainWindow]"); @@ -1158,7 +1158,7 @@ window.addEventListener("DOMContentLoaded", () => { updateTabDisplay(); }); - const updateTabDisplay = function() { + const updateTabDisplay = () => { if (window.qBittorrent.Client.isShowRssReader()) { $("showRssReaderLink").firstChild.style.opacity = "1"; $("mainWindowTabs").removeClass("invisible"); @@ -1210,7 +1210,7 @@ window.addEventListener("DOMContentLoaded", () => { // main window tabs - const showTransfersTab = function() { + const showTransfersTab = () => { const showFiltersSidebar = LocalPreferences.get("show_filters_sidebar", "true") === "true"; if (showFiltersSidebar) { $("filtersColumn").removeClass("invisible"); @@ -1229,7 +1229,7 @@ window.addEventListener("DOMContentLoaded", () => { LocalPreferences.set("selected_window_tab", "transfers"); }; - const hideTransfersTab = function() { + const hideTransfersTab = () => { $("filtersColumn").addClass("invisible"); $("filtersColumn_handle").addClass("invisible"); $("mainColumn").addClass("invisible"); @@ -1237,7 +1237,7 @@ window.addEventListener("DOMContentLoaded", () => { MochaUI.Desktop.resizePanels(); }; - const showSearchTab = (function() { + const showSearchTab = (() => { let searchTabInitialized = false; return () => { @@ -1266,12 +1266,12 @@ window.addEventListener("DOMContentLoaded", () => { }; })(); - const hideSearchTab = function() { + const hideSearchTab = () => { $("searchTabColumn").addClass("invisible"); MochaUI.Desktop.resizePanels(); }; - const showRssTab = (function() { + const showRssTab = (() => { let rssTabInitialized = false; return () => { @@ -1303,13 +1303,13 @@ window.addEventListener("DOMContentLoaded", () => { }; })(); - const hideRssTab = function() { + const hideRssTab = () => { $("rssTabColumn").addClass("invisible"); window.qBittorrent.Rss && window.qBittorrent.Rss.unload(); MochaUI.Desktop.resizePanels(); }; - const showLogTab = (function() { + const showLogTab = (() => { let logTabInitialized = false; return () => { @@ -1341,13 +1341,13 @@ window.addEventListener("DOMContentLoaded", () => { }; })(); - const hideLogTab = function() { + const hideLogTab = () => { $("logTabColumn").addClass("invisible"); MochaUI.Desktop.resizePanels(); window.qBittorrent.Log && window.qBittorrent.Log.unload(); }; - const addSearchPanel = function() { + const addSearchPanel = () => { new MochaUI.Panel({ id: "SearchPanel", title: "Search", @@ -1372,7 +1372,7 @@ window.addEventListener("DOMContentLoaded", () => { }); }; - const addRssPanel = function() { + const addRssPanel = () => { new MochaUI.Panel({ id: "RssPanel", title: "Rss", @@ -1394,7 +1394,7 @@ window.addEventListener("DOMContentLoaded", () => { }); }; - const addLogPanel = function() { + const addLogPanel = () => { new MochaUI.Panel({ id: "LogPanel", title: "Log", @@ -1415,7 +1415,7 @@ window.addEventListener("DOMContentLoaded", () => { }, }, tabsURL: "views/logTabs.html", - tabsOnload: function() { + tabsOnload: () => { MochaUI.initializeTabs("panelTabs"); $("logMessageLink").addEventListener("click", (e) => { @@ -1433,7 +1433,7 @@ window.addEventListener("DOMContentLoaded", () => { }); }; - const handleDownloadParam = function() { + const handleDownloadParam = () => { // Extract torrent URL from download param in WebUI URL hash const downloadHash = "#download="; if (location.hash.indexOf(downloadHash) !== 0) @@ -1457,7 +1457,7 @@ window.addEventListener("DOMContentLoaded", () => { }, loadMethod: "xhr", contentURL: "views/transferlist.html", - onContentLoaded: function() { + onContentLoaded: () => { handleDownloadParam(); updateMainData(); }, @@ -1484,8 +1484,8 @@ window.addEventListener("DOMContentLoaded", () => { contentURL: "views/properties.html", require: { js: ["scripts/prop-general.js", "scripts/prop-trackers.js", "scripts/prop-peers.js", "scripts/prop-webseeds.js", "scripts/prop-files.js"], - onload: function() { - updatePropertiesPanel = function() { + onload: () => { + updatePropertiesPanel = () => { switch (LocalPreferences.get("selected_properties_tab")) { case "propGeneralLink": window.qBittorrent.PropGeneral.updateData(); @@ -1507,7 +1507,7 @@ window.addEventListener("DOMContentLoaded", () => { } }, tabsURL: "views/propertiesToolbar.html", - tabsOnload: function() {}, // must be included, otherwise panel won't load properly + tabsOnload: () => {}, // must be included, otherwise panel won't load properly onContentLoaded: function() { this.panelHeaderCollapseBoxEl.classList.add("invisible"); @@ -1703,7 +1703,7 @@ window.addEventListener("DOMContentLoaded", () => { }).activate(); new ClipboardJS(".copyToClipboard", { - text: function(trigger) { + text: (trigger) => { switch (trigger.id) { case "copyName": return copyNameFN(); diff --git a/src/webui/www/private/scripts/contextmenu.js b/src/webui/www/private/scripts/contextmenu.js index ecc187f59..758783411 100644 --- a/src/webui/www/private/scripts/contextmenu.js +++ b/src/webui/www/private/scripts/contextmenu.js @@ -642,7 +642,7 @@ window.qBittorrent.ContextMenu ??= (() => { class SearchPluginsTableContextMenu extends ContextMenu { updateMenuItems() { - const enabledColumnIndex = function(text) { + const enabledColumnIndex = (text) => { const columns = $("searchPluginsTableFixedHeaderRow").getChildren("th"); for (let i = 0; i < columns.length; ++i) { if (columns[i].textContent === "Enabled") diff --git a/src/webui/www/private/scripts/download.js b/src/webui/www/private/scripts/download.js index 012f6466d..491b627a6 100644 --- a/src/webui/www/private/scripts/download.js +++ b/src/webui/www/private/scripts/download.js @@ -35,12 +35,12 @@ window.qBittorrent.Download ??= (() => { let categories = {}; let defaultSavePath = ""; - const getCategories = function() { + const getCategories = () => { new Request.JSON({ url: "api/v2/torrents/categories", method: "get", noCache: true, - onSuccess: function(data) { + onSuccess: (data) => { if (data) { categories = data; for (const i in data) { @@ -58,7 +58,7 @@ window.qBittorrent.Download ??= (() => { }).send(); }; - const getPreferences = function() { + const getPreferences = () => { const pref = window.parent.qBittorrent.Cache.preferences.get(); defaultSavePath = pref.save_path; @@ -89,7 +89,7 @@ window.qBittorrent.Download ??= (() => { $("contentLayout").selectedIndex = 0; }; - const changeCategorySelect = function(item) { + const changeCategorySelect = (item) => { if (item.value === "\\other") { item.nextElementSibling.hidden = false; item.nextElementSibling.value = ""; @@ -114,7 +114,7 @@ window.qBittorrent.Download ??= (() => { } }; - const changeTMM = function(item) { + const changeTMM = (item) => { if (item.selectedIndex === 1) { $("savepath").disabled = true; diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index 9d3869890..d2558f0f6 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -68,7 +68,7 @@ window.qBittorrent.DynamicTable ??= (() => { const DynamicTable = new Class({ - initialize: function() {}, + initialize: () => {}, setup: function(dynamicTableDivId, dynamicTableFixedHeaderDivId, contextMenu) { this.dynamicTableDivId = dynamicTableDivId; @@ -133,7 +133,7 @@ window.qBittorrent.DynamicTable ??= (() => { this.currentHeaderAction = ""; this.canResize = false; - const resetElementBorderStyle = function(el, side) { + const resetElementBorderStyle = (el, side) => { if ((side === "left") || (side !== "right")) el.style.borderLeft = ""; if ((side === "right") || (side !== "left")) @@ -197,9 +197,9 @@ window.qBittorrent.DynamicTable ??= (() => { this.lastClientX = e.clientX; }.bind(this); - const mouseOutFn = function(e) { + const mouseOutFn = (e) => { resetElementBorderStyle(e.target); - }.bind(this); + }; const onBeforeStart = function(el) { this.clickedTh = el; @@ -392,7 +392,7 @@ window.qBittorrent.DynamicTable ??= (() => { class: "contextMenu scrollableMenu" }); - const createLi = function(columnName, text) { + const createLi = (columnName, text) => { const anchor = document.createElement("a"); anchor.href = `#${columnName}`; anchor.textContent = text; @@ -436,7 +436,7 @@ window.qBittorrent.DynamicTable ??= (() => { actions[this.columns[i].name] = onMenuItemClicked; } - const createResizeElement = function(text, href) { + const createResizeElement = (text, href) => { const anchor = document.createElement("a"); anchor.href = href; anchor.textContent = text; @@ -471,7 +471,7 @@ window.qBittorrent.DynamicTable ??= (() => { this.headerContextMenu.dynamicTable = this; }, - initColumns: function() {}, + initColumns: () => {}, newColumn: function(name, style, caption, defaultWidth, defaultVisible) { const column = {}; @@ -623,7 +623,7 @@ window.qBittorrent.DynamicTable ??= (() => { }, setSortedColumnIcon: function(newColumn, oldColumn, isReverse) { - const getCol = function(headerDivId, colName) { + const getCol = (headerDivId, colName) => { const colElem = $$("#" + headerDivId + " .column_" + colName); if (colElem.length === 1) return colElem[0]; @@ -730,7 +730,7 @@ window.qBittorrent.DynamicTable ??= (() => { }); }, - onSelectedRowChanged: function() {}, + onSelectedRowChanged: () => {}, updateRowData: function(data) { // ensure rowId is a string @@ -908,7 +908,7 @@ window.qBittorrent.DynamicTable ??= (() => { trs.pop().destroy(); }, - setupTr: function(tr) {}, + setupTr: (tr) => {}, updateRow: function(tr, fullUpdate) { const row = this.rows.get(tr.rowId); @@ -1200,7 +1200,7 @@ window.qBittorrent.DynamicTable ??= (() => { td.title = status; }; - this.columns["status"].compareRows = function(row1, row2) { + this.columns["status"].compareRows = (row1, row2) => { return compareNumbers(row1.full_data._statusOrder, row2.full_data._statusOrder); }; @@ -1470,7 +1470,7 @@ window.qBittorrent.DynamicTable ??= (() => { }; }, - applyFilter: function(row, filterName, categoryHash, tagHash, trackerHash, filterTerms) { + applyFilter: (row, filterName, categoryHash, tagHash, trackerHash, filterTerms) => { const state = row["full_data"].state; let inactive = false; @@ -1716,7 +1716,7 @@ window.qBittorrent.DynamicTable ??= (() => { return this.getSelectedRowId(); }, - onSelectedRowChanged: function() { + onSelectedRowChanged: () => { updatePropertiesPanel(); } }); @@ -1875,7 +1875,7 @@ window.qBittorrent.DynamicTable ??= (() => { }, getFilteredAndSortedRows: function() { - const getSizeFilters = function() { + const getSizeFilters = () => { let minSize = (window.qBittorrent.Search.searchSizeFilter.min > 0.00) ? (window.qBittorrent.Search.searchSizeFilter.min * Math.pow(1024, window.qBittorrent.Search.searchSizeFilter.minUnit)) : 0.00; let maxSize = (window.qBittorrent.Search.searchSizeFilter.max > 0.00) ? (window.qBittorrent.Search.searchSizeFilter.max * Math.pow(1024, window.qBittorrent.Search.searchSizeFilter.maxUnit)) : 0.00; @@ -1891,7 +1891,7 @@ window.qBittorrent.DynamicTable ??= (() => { }; }; - const getSeedsFilters = function() { + const getSeedsFilters = () => { let minSeeds = (window.qBittorrent.Search.searchSeedsFilter.min > 0) ? window.qBittorrent.Search.searchSeedsFilter.min : 0; let maxSeeds = (window.qBittorrent.Search.searchSeedsFilter.max > 0) ? window.qBittorrent.Search.searchSeedsFilter.max : 0; @@ -1949,7 +1949,7 @@ window.qBittorrent.DynamicTable ??= (() => { return filteredRows; }, - setupTr: function(tr) { + setupTr: (tr) => { tr.addClass("searchTableRow"); } }); @@ -1984,7 +1984,7 @@ window.qBittorrent.DynamicTable ??= (() => { }; }, - setupTr: function(tr) { + setupTr: (tr) => { tr.addClass("searchPluginsTableRow"); } }); @@ -2174,17 +2174,17 @@ window.qBittorrent.DynamicTable ??= (() => { this.toggleNodeTreeCheckbox(node.children[i].rowId, checkState); }, - updateGlobalCheckbox: function() { + updateGlobalCheckbox: () => { const checkbox = $("rootMultiRename_cb"); const checkboxes = $$("input.RenamingCB"); - const isAllChecked = function() { + const isAllChecked = () => { for (let i = 0; i < checkboxes.length; ++i) { if (!checkboxes[i].checked) return false; } return true; }; - const isAllUnchecked = function() { + const isAllUnchecked = () => { for (let i = 0; i < checkboxes.length; ++i) { if (checkboxes[i].checked) return false; @@ -2300,9 +2300,9 @@ window.qBittorrent.DynamicTable ??= (() => { }; }, - onRowSelectionChange: function(row) {}, + onRowSelectionChange: (row) => {}, - selectRow: function() { + selectRow: () => { return; }, @@ -2618,7 +2618,7 @@ window.qBittorrent.DynamicTable ??= (() => { td.replaceChildren(span); } }; - this.columns["name"].calculateBuffer = function(rowId) { + this.columns["name"].calculateBuffer = (rowId) => { const node = that.getNode(rowId); // folders add 20px for folder icon and 15px for collapse icon const folderBuffer = node.isFolder ? 35 : 0; @@ -2814,8 +2814,8 @@ window.qBittorrent.DynamicTable ??= (() => { td.title = value; }; }, - setupHeaderMenu: function() {}, - setupHeaderEvents: function() {}, + setupHeaderMenu: () => {}, + setupHeaderEvents: () => {}, getFilteredAndSortedRows: function() { return [...this.getRowValues()]; }, @@ -2944,8 +2944,8 @@ window.qBittorrent.DynamicTable ??= (() => { initColumns: function() { this.newColumn("name", "", "QBT_TR(Torrents: (double-click to download))QBT_TR[CONTEXT=RSSWidget]", -1, true); }, - setupHeaderMenu: function() {}, - setupHeaderEvents: function() {}, + setupHeaderMenu: () => {}, + setupHeaderEvents: () => {}, getFilteredAndSortedRows: function() { return [...this.getRowValues()]; }, @@ -3056,8 +3056,8 @@ window.qBittorrent.DynamicTable ??= (() => { }; this.columns["checked"].staticWidth = 50; }, - setupHeaderMenu: function() {}, - setupHeaderEvents: function() {}, + setupHeaderMenu: () => {}, + setupHeaderEvents: () => {}, getFilteredAndSortedRows: function() { return [...this.getRowValues()]; }, @@ -3148,8 +3148,8 @@ window.qBittorrent.DynamicTable ??= (() => { }; this.columns["checked"].staticWidth = 50; }, - setupHeaderMenu: function() {}, - setupHeaderEvents: function() {}, + setupHeaderMenu: () => {}, + setupHeaderEvents: () => {}, getFilteredAndSortedRows: function() { return [...this.getRowValues()]; }, @@ -3189,7 +3189,7 @@ window.qBittorrent.DynamicTable ??= (() => { this.hiddenTableHeader.appendChild(new Element("th")); this.fixedTableHeader.appendChild(new Element("th")); }, - selectRow: function() {} + selectRow: () => {} }); const RssDownloaderArticlesTable = new Class({ @@ -3197,8 +3197,8 @@ window.qBittorrent.DynamicTable ??= (() => { initColumns: function() { this.newColumn("name", "", "", -1, true); }, - setupHeaderMenu: function() {}, - setupHeaderEvents: function() {}, + setupHeaderMenu: () => {}, + setupHeaderEvents: () => {}, getFilteredAndSortedRows: function() { return [...this.getRowValues()]; }, @@ -3238,7 +3238,7 @@ window.qBittorrent.DynamicTable ??= (() => { this.hiddenTableHeader.appendChild(new Element("th")); this.fixedTableHeader.appendChild(new Element("th")); }, - selectRow: function() {}, + selectRow: () => {}, updateRow: function(tr, fullUpdate) { const row = this.rows.get(tr.rowId); const data = row[fullUpdate ? "full_data" : "data"]; @@ -3343,9 +3343,9 @@ window.qBittorrent.DynamicTable ??= (() => { return filteredRows; }, - setupCommonEvents: function() {}, + setupCommonEvents: () => {}, - setupTr: function(tr) { + setupTr: (tr) => { tr.addClass("logTableRow"); } }); diff --git a/src/webui/www/private/scripts/file-tree.js b/src/webui/www/private/scripts/file-tree.js index 7ccc46513..3ad304084 100644 --- a/src/webui/www/private/scripts/file-tree.js +++ b/src/webui/www/private/scripts/file-tree.js @@ -88,7 +88,7 @@ window.qBittorrent.FileTree ??= (() => { : this.nodeMap[rowId]; }, - getRowId: function(node) { + getRowId: (node) => { return node.rowId; }, diff --git a/src/webui/www/private/scripts/filesystem.js b/src/webui/www/private/scripts/filesystem.js index 7dd202f74..311ad906d 100644 --- a/src/webui/www/private/scripts/filesystem.js +++ b/src/webui/www/private/scripts/filesystem.js @@ -46,21 +46,21 @@ window.qBittorrent.Filesystem ??= (() => { /** * Returns the file extension part of a file name. */ - const fileExtension = function(filename) { + const fileExtension = (filename) => { const pointIndex = filename.lastIndexOf("."); if (pointIndex === -1) return ""; return filename.substring(pointIndex + 1); }; - const fileName = function(filepath) { + const fileName = (filepath) => { const slashIndex = filepath.lastIndexOf(PathSeparator); if (slashIndex === -1) return filepath; return filepath.substring(slashIndex + 1); }; - const folderName = function(filepath) { + const folderName = (filepath) => { const slashIndex = filepath.lastIndexOf(PathSeparator); if (slashIndex === -1) return ""; diff --git a/src/webui/www/private/scripts/localpreferences.js b/src/webui/www/private/scripts/localpreferences.js index 8eba65557..31fd5f0c8 100644 --- a/src/webui/www/private/scripts/localpreferences.js +++ b/src/webui/www/private/scripts/localpreferences.js @@ -37,14 +37,14 @@ window.qBittorrent.LocalPreferences ??= (() => { }; const LocalPreferencesClass = new Class({ - get: function(key, defaultValue) { + get: (key, defaultValue) => { const value = localStorage.getItem(key); return ((value === null) && (defaultValue !== undefined)) ? defaultValue : value; }, - set: function(key, value) { + set: (key, value) => { try { localStorage.setItem(key, value); } @@ -53,7 +53,7 @@ window.qBittorrent.LocalPreferences ??= (() => { } }, - remove: function(key) { + remove: (key) => { try { localStorage.removeItem(key); } diff --git a/src/webui/www/private/scripts/misc.js b/src/webui/www/private/scripts/misc.js index 4fff5d4fe..3010c8f42 100644 --- a/src/webui/www/private/scripts/misc.js +++ b/src/webui/www/private/scripts/misc.js @@ -53,7 +53,7 @@ window.qBittorrent.Misc ??= (() => { }; }; - const genHash = function(string) { + const genHash = (string) => { // origins: // https://stackoverflow.com/a/8831937 // https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0 @@ -64,7 +64,7 @@ window.qBittorrent.Misc ??= (() => { }; // getHost emulate the GUI version `QString getHost(const QString &url)` - const getHost = function(url) { + const getHost = (url) => { // We want the hostname. // If failed to parse the domain, original input should be returned @@ -102,7 +102,7 @@ window.qBittorrent.Misc ??= (() => { /* * JS counterpart of the function in src/misc.cpp */ - const friendlyUnit = function(value, isSpeed) { + const friendlyUnit = (value, isSpeed) => { const units = [ "QBT_TR(B)QBT_TR[CONTEXT=misc]", "QBT_TR(KiB)QBT_TR[CONTEXT=misc]", @@ -122,14 +122,14 @@ window.qBittorrent.Misc ??= (() => { ++i; } - function friendlyUnitPrecision(sizeUnit) { + const friendlyUnitPrecision = (sizeUnit) => { if (sizeUnit <= 2) // KiB, MiB return 1; else if (sizeUnit === 3) // GiB return 2; else // TiB, PiB, EiB return 3; - } + }; let ret; if (i === 0) { @@ -150,7 +150,7 @@ window.qBittorrent.Misc ??= (() => { /* * JS counterpart of the function in src/misc.cpp */ - const friendlyDuration = function(seconds, maxCap = -1) { + const friendlyDuration = (seconds, maxCap = -1) => { if ((seconds < 0) || ((seconds >= maxCap) && (maxCap >= 0))) return "∞"; if (seconds === 0) @@ -173,7 +173,7 @@ window.qBittorrent.Misc ??= (() => { return "QBT_TR(%1y %2d)QBT_TR[CONTEXT=misc]".replace("%1", Math.floor(years)).replace("%2", Math.floor(days)); }; - const friendlyPercentage = function(value) { + const friendlyPercentage = (value) => { let percentage = (value * 100).round(1); if (isNaN(percentage) || (percentage < 0)) percentage = 0; @@ -182,19 +182,19 @@ window.qBittorrent.Misc ??= (() => { return percentage.toFixed(1) + "%"; }; - const friendlyFloat = function(value, precision) { + const friendlyFloat = (value, precision) => { return parseFloat(value).toFixed(precision); }; /* * JS counterpart of the function in src/misc.cpp */ - const parseHtmlLinks = function(text) { + const parseHtmlLinks = (text) => { const exp = /(\b(https?|ftp|file):\/\/[-\w+&@#/%?=~|!:,.;]*[-\w+&@#/%=~|])/gi; return text.replace(exp, "$1"); }; - const parseVersion = function(versionString) { + const parseVersion = (versionString) => { const failure = { valid: false }; @@ -228,7 +228,7 @@ window.qBittorrent.Misc ??= (() => { // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#parameters const naturalSortCollator = new Intl.Collator(undefined, { numeric: true, usage: "sort" }); - const safeTrim = function(value) { + const safeTrim = (value) => { try { return value.trim(); } @@ -239,7 +239,7 @@ window.qBittorrent.Misc ??= (() => { } }; - const toFixedPointString = function(number, digits) { + const toFixedPointString = (number, digits) => { // Do not round up number const power = Math.pow(10, digits); return (Math.floor(power * number) / power).toFixed(digits); @@ -251,7 +251,7 @@ window.qBittorrent.Misc ??= (() => { * @param {Array} terms terms to search for within the text * @returns {Boolean} true if all terms match the text, false otherwise */ - const containsAllTerms = function(text, terms) { + const containsAllTerms = (text, terms) => { const textToSearch = text.toLowerCase(); return terms.every((term) => { const isTermRequired = (term[0] === "+"); diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js index 7a22e0d05..75ae8edd8 100644 --- a/src/webui/www/private/scripts/mocha-init.js +++ b/src/webui/www/private/scripts/mocha-init.js @@ -87,7 +87,7 @@ window.qBittorrent.Dialog ??= (() => { }, resizable: true, width: 480, - onCloseComplete: function() { + onCloseComplete: () => { // make sure overlay is properly hidden upon modal closing document.getElementById("modalOverlay").style.display = "none"; } @@ -101,75 +101,75 @@ Object.freeze(window.qBittorrent.Dialog); const LocalPreferences = new window.qBittorrent.LocalPreferences.LocalPreferencesClass(); -let saveWindowSize = function() {}; -let loadWindowWidth = function() {}; -let loadWindowHeight = function() {}; -let showDownloadPage = function() {}; -let globalUploadLimitFN = function() {}; -let uploadLimitFN = function() {}; -let shareRatioFN = function() {}; -let toggleSequentialDownloadFN = function() {}; -let toggleFirstLastPiecePrioFN = function() {}; -let setSuperSeedingFN = function() {}; -let setForceStartFN = function() {}; -let globalDownloadLimitFN = function() {}; -let StatisticsLinkFN = function() {}; -let downloadLimitFN = function() {}; -let deleteSelectedTorrentsFN = function() {}; -let stopFN = function() {}; -let startFN = function() {}; -let autoTorrentManagementFN = function() {}; -let recheckFN = function() {}; -let reannounceFN = function() {}; -let setLocationFN = function() {}; -let renameFN = function() {}; -let renameFilesFN = function() {}; -let startVisibleTorrentsFN = function() {}; -let stopVisibleTorrentsFN = function() {}; -let deleteVisibleTorrentsFN = function() {}; -let torrentNewCategoryFN = function() {}; -let torrentSetCategoryFN = function() {}; -let createCategoryFN = function() {}; -let createSubcategoryFN = function() {}; -let editCategoryFN = function() {}; -let removeCategoryFN = function() {}; -let deleteUnusedCategoriesFN = function() {}; -let torrentAddTagsFN = function() {}; -let torrentSetTagsFN = function() {}; -let torrentRemoveAllTagsFN = function() {}; -let createTagFN = function() {}; -let removeTagFN = function() {}; -let deleteUnusedTagsFN = function() {}; -let deleteTrackerFN = function() {}; -let copyNameFN = function() {}; -let copyInfohashFN = function(policy) {}; -let copyMagnetLinkFN = function() {}; -let copyIdFN = function() {}; -let copyCommentFN = function() {}; -let setQueuePositionFN = function() {}; -let exportTorrentFN = function() {}; +let saveWindowSize = () => {}; +let loadWindowWidth = () => {}; +let loadWindowHeight = () => {}; +let showDownloadPage = () => {}; +let globalUploadLimitFN = () => {}; +let uploadLimitFN = () => {}; +let shareRatioFN = () => {}; +let toggleSequentialDownloadFN = () => {}; +let toggleFirstLastPiecePrioFN = () => {}; +let setSuperSeedingFN = () => {}; +let setForceStartFN = () => {}; +let globalDownloadLimitFN = () => {}; +let StatisticsLinkFN = () => {}; +let downloadLimitFN = () => {}; +let deleteSelectedTorrentsFN = () => {}; +let stopFN = () => {}; +let startFN = () => {}; +let autoTorrentManagementFN = () => {}; +let recheckFN = () => {}; +let reannounceFN = () => {}; +let setLocationFN = () => {}; +let renameFN = () => {}; +let renameFilesFN = () => {}; +let startVisibleTorrentsFN = () => {}; +let stopVisibleTorrentsFN = () => {}; +let deleteVisibleTorrentsFN = () => {}; +let torrentNewCategoryFN = () => {}; +let torrentSetCategoryFN = () => {}; +let createCategoryFN = () => {}; +let createSubcategoryFN = () => {}; +let editCategoryFN = () => {}; +let removeCategoryFN = () => {}; +let deleteUnusedCategoriesFN = () => {}; +let torrentAddTagsFN = () => {}; +let torrentSetTagsFN = () => {}; +let torrentRemoveAllTagsFN = () => {}; +let createTagFN = () => {}; +let removeTagFN = () => {}; +let deleteUnusedTagsFN = () => {}; +let deleteTrackerFN = () => {}; +let copyNameFN = () => {}; +let copyInfohashFN = (policy) => {}; +let copyMagnetLinkFN = () => {}; +let copyIdFN = () => {}; +let copyCommentFN = () => {}; +let setQueuePositionFN = () => {}; +let exportTorrentFN = () => {}; -const initializeWindows = function() { - saveWindowSize = function(windowId) { +const initializeWindows = () => { + saveWindowSize = (windowId) => { const size = $(windowId).getSize(); LocalPreferences.set("window_" + windowId + "_width", size.x); LocalPreferences.set("window_" + windowId + "_height", size.y); }; - loadWindowWidth = function(windowId, defaultValue) { + loadWindowWidth = (windowId, defaultValue) => { return LocalPreferences.get("window_" + windowId + "_width", defaultValue); }; - loadWindowHeight = function(windowId, defaultValue) { + loadWindowHeight = (windowId, defaultValue) => { return LocalPreferences.get("window_" + windowId + "_height", defaultValue); }; - function addClickEvent(el, fn) { + const addClickEvent = (el, fn) => { ["Link", "Button"].each((item) => { if ($(el + item)) $(el + item).addEventListener("click", fn); }); - } + }; addClickEvent("download", (e) => { e.preventDefault(); @@ -177,7 +177,7 @@ const initializeWindows = function() { showDownloadPage(); }); - showDownloadPage = function(urls) { + showDownloadPage = (urls) => { const id = "downloadPage"; const contentUri = new URI("download.html"); @@ -248,7 +248,7 @@ const initializeWindows = function() { paddingHorizontal: 0, width: loadWindowWidth(id, 900), height: loadWindowHeight(id, 400), - onResize: function() { + onResize: () => { saveWindowSize(id); } }); @@ -279,7 +279,7 @@ const initializeWindows = function() { updateMainData(); }); - globalUploadLimitFN = function() { + globalUploadLimitFN = () => { new MochaUI.Window({ id: "uploadLimitPage", icon: "images/qbittorrent-tray.svg", @@ -296,7 +296,7 @@ const initializeWindows = function() { }); }; - uploadLimitFN = function() { + uploadLimitFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { new MochaUI.Window({ @@ -316,7 +316,7 @@ const initializeWindows = function() { } }; - shareRatioFN = function() { + shareRatioFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { let shareRatio = null; @@ -357,7 +357,7 @@ const initializeWindows = function() { } }; - toggleSequentialDownloadFN = function() { + toggleSequentialDownloadFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { new Request({ @@ -371,7 +371,7 @@ const initializeWindows = function() { } }; - toggleFirstLastPiecePrioFN = function() { + toggleFirstLastPiecePrioFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { new Request({ @@ -385,7 +385,7 @@ const initializeWindows = function() { } }; - setSuperSeedingFN = function(val) { + setSuperSeedingFN = (val) => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { new Request({ @@ -400,7 +400,7 @@ const initializeWindows = function() { } }; - setForceStartFN = function() { + setForceStartFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { new Request({ @@ -415,7 +415,7 @@ const initializeWindows = function() { } }; - globalDownloadLimitFN = function() { + globalDownloadLimitFN = () => { new MochaUI.Window({ id: "downloadLimitPage", icon: "images/qbittorrent-tray.svg", @@ -432,7 +432,7 @@ const initializeWindows = function() { }); }; - StatisticsLinkFN = function() { + StatisticsLinkFN = () => { const id = "statisticspage"; new MochaUI.Window({ id: id, @@ -450,7 +450,7 @@ const initializeWindows = function() { }); }; - downloadLimitFN = function() { + downloadLimitFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { new MochaUI.Window({ @@ -470,7 +470,7 @@ const initializeWindows = function() { } }; - deleteSelectedTorrentsFN = function(forceDeleteFiles = false) { + deleteSelectedTorrentsFN = (forceDeleteFiles = false) => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length > 0) { if (window.qBittorrent.Cache.preferences.get().confirm_torrent_deletion) { @@ -483,11 +483,11 @@ const initializeWindows = function() { forceDeleteFiles: forceDeleteFiles }, contentURL: "views/confirmdeletion.html", - onContentLoaded: function(w) { + onContentLoaded: (w) => { MochaUI.resizeWindow(w, { centered: true }); MochaUI.centerWindow(w); }, - onCloseComplete: function() { + onCloseComplete: () => { // make sure overlay is properly hidden upon modal closing document.getElementById("modalOverlay").style.display = "none"; } @@ -501,12 +501,12 @@ const initializeWindows = function() { hashes: hashes.join("|"), deleteFiles: forceDeleteFiles }, - onSuccess: function() { + onSuccess: () => { torrentsTable.deselectAll(); updateMainData(); updatePropertiesPanel(); }, - onFailure: function() { + onFailure: () => { alert("QBT_TR(Unable to delete torrents.)QBT_TR[CONTEXT=HttpServer]"); } }).send(); @@ -520,7 +520,7 @@ const initializeWindows = function() { deleteSelectedTorrentsFN(); }); - stopFN = function() { + stopFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { new Request({ @@ -534,7 +534,7 @@ const initializeWindows = function() { } }; - startFN = function() { + startFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { new Request({ @@ -548,7 +548,7 @@ const initializeWindows = function() { } }; - autoTorrentManagementFN = function() { + autoTorrentManagementFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length > 0) { const enableAutoTMM = hashes.some((hash) => !(torrentsTable.getRow(hash).full_data.auto_tmm)); @@ -583,7 +583,7 @@ const initializeWindows = function() { } }; - recheckFN = function() { + recheckFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length > 0) { if (window.qBittorrent.Cache.preferences.get().confirm_torrent_recheck) { @@ -602,10 +602,10 @@ const initializeWindows = function() { data: { "hashes": hashes.join("|"), }, - onSuccess: function() { + onSuccess: () => { updateMainData(); }, - onFailure: function() { + onFailure: () => { alert("QBT_TR(Unable to recheck torrents.)QBT_TR[CONTEXT=HttpServer]"); } }).send(); @@ -613,7 +613,7 @@ const initializeWindows = function() { } }; - reannounceFN = function() { + reannounceFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { new Request({ @@ -627,7 +627,7 @@ const initializeWindows = function() { } }; - setLocationFN = function() { + setLocationFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { const hash = hashes[0]; @@ -650,7 +650,7 @@ const initializeWindows = function() { } }; - renameFN = function() { + renameFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length === 1) { const hash = hashes[0]; @@ -674,7 +674,7 @@ const initializeWindows = function() { } }; - renameFilesFN = function() { + renameFilesFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length === 1) { const hash = hashes[0]; @@ -700,7 +700,7 @@ const initializeWindows = function() { } }; - startVisibleTorrentsFN = function() { + startVisibleTorrentsFN = () => { const hashes = torrentsTable.getFilteredTorrentsHashes(selectedStatus, selectedCategory, selectedTag, selectedTracker); if (hashes.length > 0) { new Request({ @@ -720,7 +720,7 @@ const initializeWindows = function() { } }; - stopVisibleTorrentsFN = function() { + stopVisibleTorrentsFN = () => { const hashes = torrentsTable.getFilteredTorrentsHashes(selectedStatus, selectedCategory, selectedTag, selectedTracker); if (hashes.length > 0) { new Request({ @@ -740,7 +740,7 @@ const initializeWindows = function() { } }; - deleteVisibleTorrentsFN = function() { + deleteVisibleTorrentsFN = () => { const hashes = torrentsTable.getFilteredTorrentsHashes(selectedStatus, selectedCategory, selectedTag, selectedTracker); if (hashes.length > 0) { if (window.qBittorrent.Cache.preferences.get().confirm_torrent_deletion) { @@ -753,7 +753,7 @@ const initializeWindows = function() { isDeletingVisibleTorrents: true }, contentURL: "views/confirmdeletion.html", - onContentLoaded: function(w) { + onContentLoaded: (w) => { MochaUI.resizeWindow(w, { centered: true }); MochaUI.centerWindow(w); } @@ -780,7 +780,7 @@ const initializeWindows = function() { } }; - torrentNewCategoryFN = function() { + torrentNewCategoryFN = () => { const action = "set"; const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { @@ -801,7 +801,7 @@ const initializeWindows = function() { } }; - torrentSetCategoryFN = function(categoryHash) { + torrentSetCategoryFN = (categoryHash) => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length <= 0) return; @@ -816,13 +816,13 @@ const initializeWindows = function() { hashes: hashes.join("|"), category: categoryName }, - onSuccess: function() { + onSuccess: () => { updateMainData(); } }).send(); }; - createCategoryFN = function() { + createCategoryFN = () => { const action = "create"; new MochaUI.Window({ id: "newCategoryPage", @@ -840,7 +840,7 @@ const initializeWindows = function() { }); }; - createSubcategoryFN = function(categoryHash) { + createSubcategoryFN = (categoryHash) => { const action = "createSubcategory"; const categoryName = category_list.get(categoryHash).name + "/"; new MochaUI.Window({ @@ -859,7 +859,7 @@ const initializeWindows = function() { }); }; - editCategoryFN = function(categoryHash) { + editCategoryFN = (categoryHash) => { const action = "edit"; const category = category_list.get(categoryHash); new MochaUI.Window({ @@ -878,7 +878,7 @@ const initializeWindows = function() { }); }; - removeCategoryFN = function(categoryHash) { + removeCategoryFN = (categoryHash) => { const categoryName = category_list.get(categoryHash).name; new Request({ url: "api/v2/torrents/removeCategories", @@ -886,14 +886,14 @@ const initializeWindows = function() { data: { categories: categoryName }, - onSuccess: function() { + onSuccess: () => { setCategoryFilter(CATEGORIES_ALL); updateMainData(); } }).send(); }; - deleteUnusedCategoriesFN = function() { + deleteUnusedCategoriesFN = () => { const categories = []; category_list.forEach((category, hash) => { if (torrentsTable.getFilteredTorrentsNumber("all", hash, TAGS_ALL, TRACKERS_ALL) === 0) @@ -906,14 +906,14 @@ const initializeWindows = function() { data: { categories: categories.join("\n") }, - onSuccess: function() { + onSuccess: () => { setCategoryFilter(CATEGORIES_ALL); updateMainData(); } }).send(); }; - torrentAddTagsFN = function() { + torrentAddTagsFN = () => { const action = "set"; const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { @@ -934,7 +934,7 @@ const initializeWindows = function() { } }; - torrentSetTagsFN = function(tagHash, isSet) { + torrentSetTagsFN = (tagHash, isSet) => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length <= 0) return; @@ -950,7 +950,7 @@ const initializeWindows = function() { }).send(); }; - torrentRemoveAllTagsFN = function() { + torrentRemoveAllTagsFN = () => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { new Request({ @@ -963,7 +963,7 @@ const initializeWindows = function() { } }; - createTagFN = function() { + createTagFN = () => { const action = "create"; new MochaUI.Window({ id: "newTagPage", @@ -982,7 +982,7 @@ const initializeWindows = function() { updateMainData(); }; - removeTagFN = function(tagHash) { + removeTagFN = (tagHash) => { const tagName = tagList.get(tagHash).name; new Request({ url: "api/v2/torrents/deleteTags", @@ -994,7 +994,7 @@ const initializeWindows = function() { setTagFilter(TAGS_ALL); }; - deleteUnusedTagsFN = function() { + deleteUnusedTagsFN = () => { const tags = []; tagList.forEach((tag, hash) => { if (torrentsTable.getFilteredTorrentsNumber("all", CATEGORIES_ALL, hash, TRACKERS_ALL) === 0) @@ -1010,7 +1010,7 @@ const initializeWindows = function() { setTagFilter(TAGS_ALL); }; - deleteTrackerFN = function(trackerHash) { + deleteTrackerFN = (trackerHash) => { const trackerHashInt = Number.parseInt(trackerHash, 10); if ((trackerHashInt === TRACKERS_ALL) || (trackerHashInt === TRACKERS_TRACKERLESS)) return; @@ -1030,14 +1030,14 @@ const initializeWindows = function() { padding: 10, width: 424, height: 100, - onCloseComplete: function() { + onCloseComplete: () => { updateMainData(); setTrackerFilter(TRACKERS_ALL); } }); }; - copyNameFN = function() { + copyNameFN = () => { const selectedRows = torrentsTable.selectedRowsIds(); const names = []; if (selectedRows.length > 0) { @@ -1050,7 +1050,7 @@ const initializeWindows = function() { return names.join("\n"); }; - copyInfohashFN = function(policy) { + copyInfohashFN = (policy) => { const selectedRows = torrentsTable.selectedRowsIds(); const infohashes = []; if (selectedRows.length > 0) { @@ -1075,7 +1075,7 @@ const initializeWindows = function() { return infohashes.join("\n"); }; - copyMagnetLinkFN = function() { + copyMagnetLinkFN = () => { const selectedRows = torrentsTable.selectedRowsIds(); const magnets = []; if (selectedRows.length > 0) { @@ -1088,11 +1088,11 @@ const initializeWindows = function() { return magnets.join("\n"); }; - copyIdFN = function() { + copyIdFN = () => { return torrentsTable.selectedRowsIds().join("\n"); }; - copyCommentFN = function() { + copyCommentFN = () => { const selectedRows = torrentsTable.selectedRowsIds(); const comments = []; if (selectedRows.length > 0) { @@ -1107,7 +1107,7 @@ const initializeWindows = function() { return comments.join("\n---------\n"); }; - exportTorrentFN = async function() { + exportTorrentFN = async () => { const hashes = torrentsTable.selectedRowsIds(); for (const hash of hashes) { const row = torrentsTable.getRow(hash); @@ -1192,7 +1192,7 @@ const initializeWindows = function() { }); }); - setQueuePositionFN = function(cmd) { + setQueuePositionFN = (cmd) => { const hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { new Request({ @@ -1238,7 +1238,7 @@ const initializeWindows = function() { new Request({ url: "api/v2/auth/logout", method: "post", - onSuccess: function() { + onSuccess: () => { window.location.reload(true); } }).send(); @@ -1252,7 +1252,7 @@ const initializeWindows = function() { new Request({ url: "api/v2/app/shutdown", method: "post", - onSuccess: function() { + onSuccess: () => { const shutdownMessage = "QBT_TR(%1 has been shutdown)QBT_TR[CONTEXT=HttpServer]".replace("%1", window.qBittorrent.Client.mainTitle()); document.write(` ${shutdownMessage}

${shutdownMessage}

`); document.close(); diff --git a/src/webui/www/private/scripts/pathAutofill.js b/src/webui/www/private/scripts/pathAutofill.js index 3a14b8300..a5f9ad59c 100644 --- a/src/webui/www/private/scripts/pathAutofill.js +++ b/src/webui/www/private/scripts/pathAutofill.js @@ -40,7 +40,7 @@ window.qBittorrent.pathAutofill ??= (() => { }; }; - function showInputSuggestions(inputElement, names) { + const showInputSuggestions = (inputElement, names) => { const datalist = document.createElement("datalist"); datalist.id = inputElement.id + "Suggestions"; for (const name of names) { @@ -57,9 +57,9 @@ window.qBittorrent.pathAutofill ??= (() => { inputElement.appendChild(datalist); inputElement.setAttribute("list", datalist.id); } - } + }; - function showPathSuggestions(element, mode) { + const showPathSuggestions = (element, mode) => { const partialPath = element.value; if (partialPath === "") return; @@ -68,7 +68,7 @@ window.qBittorrent.pathAutofill ??= (() => { .then(response => response.json()) .then(filesList => { showInputSuggestions(element, filesList); }) .catch(error => {}); - } + }; function attachPathAutofill() { const directoryInputs = document.querySelectorAll(".pathDirectory:not(.pathAutoFillInitialized)"); diff --git a/src/webui/www/private/scripts/piecesbar.js b/src/webui/www/private/scripts/piecesbar.js index bfaf540e4..2a946957a 100644 --- a/src/webui/www/private/scripts/piecesbar.js +++ b/src/webui/www/private/scripts/piecesbar.js @@ -46,7 +46,7 @@ window.qBittorrent.PiecesBar ??= (() => { let piecesBarUniqueId = 0; const PiecesBar = new Class({ - initialize(pieces, parameters) { + initialize: (pieces, parameters) => { const vals = { "id": "piecesbar_" + (piecesBarUniqueId++), "width": 0, @@ -253,7 +253,7 @@ window.qBittorrent.PiecesBar ??= (() => { } } - function checkForParent(id) { + const checkForParent = (id) => { const obj = $(id); if (!obj) return; @@ -261,7 +261,7 @@ window.qBittorrent.PiecesBar ??= (() => { return setTimeout(() => { checkForParent(id); }, 100); obj.refresh(); - } + }; return exports(); })(); diff --git a/src/webui/www/private/scripts/progressbar.js b/src/webui/www/private/scripts/progressbar.js index 63f826273..cb99437bf 100644 --- a/src/webui/www/private/scripts/progressbar.js +++ b/src/webui/www/private/scripts/progressbar.js @@ -38,7 +38,7 @@ window.qBittorrent.ProgressBar ??= (() => { let ProgressBars = 0; const ProgressBar = new Class({ - initialize: function(value, parameters) { + initialize: (value, parameters) => { const vals = { "id": "progressbar_" + (ProgressBars++), "value": [value, 0].pick(), @@ -107,7 +107,7 @@ window.qBittorrent.ProgressBar ??= (() => { if (vals.width) obj.setValue(vals.value); else - setTimeout('ProgressBar_checkForParent("' + obj.id + '")'); + setTimeout(ProgressBar_checkForParent, 0, obj.id); return obj; } }); @@ -142,19 +142,19 @@ window.qBittorrent.ProgressBar ??= (() => { } } - function ProgressBar_checkForParent(id) { + const ProgressBar_checkForParent = (id) => { const obj = $(id); if (!obj) return; if (!obj.parentNode) - return setTimeout('ProgressBar_checkForParent("' + id + '")', 100); + return setTimeout(ProgressBar_checkForParent, 100, id); obj.style.width = "100%"; const w = obj.offsetWidth; obj.vals.dark.style.width = `${w}px`; obj.vals.light.style.width = `${w}px`; obj.vals.width = w; obj.setValue(obj.vals.value); - } + }; return exports(); })(); diff --git a/src/webui/www/private/scripts/prop-files.js b/src/webui/www/private/scripts/prop-files.js index b4fc5c848..a00ece320 100644 --- a/src/webui/www/private/scripts/prop-files.js +++ b/src/webui/www/private/scripts/prop-files.js @@ -53,7 +53,7 @@ window.qBittorrent.PropFiles ??= (() => { let is_seed = true; let current_hash = ""; - const normalizePriority = function(priority) { + const normalizePriority = (priority) => { switch (priority) { case FilePriority.Ignored: case FilePriority.Normal: @@ -66,7 +66,7 @@ window.qBittorrent.PropFiles ??= (() => { } }; - const getAllChildren = function(id, fileId) { + const getAllChildren = (id, fileId) => { const node = torrentFilesTable.getNode(id); if (!node.isFolder) { return { @@ -78,7 +78,7 @@ window.qBittorrent.PropFiles ??= (() => { const rowIds = []; const fileIds = []; - const getChildFiles = function(node) { + const getChildFiles = (node) => { if (node.isFolder) { node.children.each((child) => { getChildFiles(child); @@ -100,7 +100,7 @@ window.qBittorrent.PropFiles ??= (() => { }; }; - const fileCheckboxClicked = function(e) { + const fileCheckboxClicked = (e) => { e.stopPropagation(); const checkbox = e.target; @@ -114,7 +114,7 @@ window.qBittorrent.PropFiles ??= (() => { updateGlobalCheckbox(); }; - const fileComboboxChanged = function(e) { + const fileComboboxChanged = (e) => { const combobox = e.target; const priority = combobox.value; const id = combobox.getAttribute("data-id"); @@ -126,11 +126,11 @@ window.qBittorrent.PropFiles ??= (() => { updateGlobalCheckbox(); }; - const isDownloadCheckboxExists = function(id) { - return ($("cbPrio" + id) !== null); + const isDownloadCheckboxExists = (id) => { + return $("cbPrio" + id) !== null; }; - const createDownloadCheckbox = function(id, fileId, checked) { + const createDownloadCheckbox = (id, fileId, checked) => { const checkbox = new Element("input"); checkbox.type = "checkbox"; checkbox.id = "cbPrio" + id; @@ -143,12 +143,12 @@ window.qBittorrent.PropFiles ??= (() => { return checkbox; }; - const updateDownloadCheckbox = function(id, checked) { + const updateDownloadCheckbox = (id, checked) => { const checkbox = $("cbPrio" + id); updateCheckbox(checkbox, checked); }; - const updateCheckbox = function(checkbox, checked) { + const updateCheckbox = (checkbox, checked) => { switch (checked) { case TriState.Checked: setCheckboxChecked(checkbox); @@ -162,8 +162,8 @@ window.qBittorrent.PropFiles ??= (() => { } }; - const isPriorityComboExists = function(id) { - return ($("comboPrio" + id) !== null); + const isPriorityComboExists = (id) => { + return $("comboPrio" + id) !== null; }; const createPriorityCombo = (id, fileId, selectedPriority) => { @@ -195,13 +195,13 @@ window.qBittorrent.PropFiles ??= (() => { return select; }; - const updatePriorityCombo = function(id, selectedPriority) { + const updatePriorityCombo = (id, selectedPriority) => { const combobox = $("comboPrio" + id); if (parseInt(combobox.value, 10) !== selectedPriority) selectComboboxPriority(combobox, selectedPriority); }; - const selectComboboxPriority = function(combobox, priority) { + const selectComboboxPriority = (combobox, priority) => { const options = combobox.options; for (let i = 0; i < options.length; ++i) { const option = options[i]; @@ -214,7 +214,7 @@ window.qBittorrent.PropFiles ??= (() => { combobox.value = priority; }; - const switchCheckboxState = function(e) { + const switchCheckboxState = (e) => { e.stopPropagation(); const rowIds = []; @@ -256,7 +256,7 @@ window.qBittorrent.PropFiles ??= (() => { setFilePriority(rowIds, fileIds, priority); }; - const updateGlobalCheckbox = function() { + const updateGlobalCheckbox = () => { const checkbox = $("tristate_cb"); if (isAllCheckboxesChecked()) setCheckboxChecked(checkbox); @@ -266,24 +266,24 @@ window.qBittorrent.PropFiles ??= (() => { setCheckboxPartial(checkbox); }; - const setCheckboxChecked = function(checkbox) { + const setCheckboxChecked = (checkbox) => { checkbox.state = "checked"; checkbox.indeterminate = false; checkbox.checked = true; }; - const setCheckboxUnchecked = function(checkbox) { + const setCheckboxUnchecked = (checkbox) => { checkbox.state = "unchecked"; checkbox.indeterminate = false; checkbox.checked = false; }; - const setCheckboxPartial = function(checkbox) { + const setCheckboxPartial = (checkbox) => { checkbox.state = "partial"; checkbox.indeterminate = true; }; - const isAllCheckboxesChecked = function() { + const isAllCheckboxesChecked = () => { const checkboxes = $$("input.DownloadedCB"); for (let i = 0; i < checkboxes.length; ++i) { if (!checkboxes[i].checked) @@ -292,7 +292,7 @@ window.qBittorrent.PropFiles ??= (() => { return true; }; - const isAllCheckboxesUnchecked = function() { + const isAllCheckboxesUnchecked = () => { const checkboxes = $$("input.DownloadedCB"); for (let i = 0; i < checkboxes.length; ++i) { if (checkboxes[i].checked) @@ -301,7 +301,7 @@ window.qBittorrent.PropFiles ??= (() => { return true; }; - const setFilePriority = function(ids, fileIds, priority) { + const setFilePriority = (ids, fileIds, priority) => { if (current_hash === "") return; @@ -316,7 +316,7 @@ window.qBittorrent.PropFiles ??= (() => { "id": fileIds.join("|"), "priority": priority }, - onComplete: function() { + onComplete: () => { loadTorrentFilesDataTimer = loadTorrentFilesData.delay(1000); } }).send(); @@ -334,7 +334,7 @@ window.qBittorrent.PropFiles ??= (() => { }; let loadTorrentFilesDataTimer = -1; - const loadTorrentFilesData = function() { + const loadTorrentFilesData = () => { if ($("propFiles").hasClass("invisible") || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) { // Tab changed, don't do anything @@ -357,11 +357,11 @@ window.qBittorrent.PropFiles ??= (() => { url: url, method: "get", noCache: true, - onComplete: function() { + onComplete: () => { clearTimeout(loadTorrentFilesDataTimer); loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000); }, - onSuccess: function(files) { + onSuccess: (files) => { clearTimeout(torrentFilesFilterInputTimer); torrentFilesFilterInputTimer = -1; @@ -377,13 +377,13 @@ window.qBittorrent.PropFiles ??= (() => { }).send(); }; - const updateData = function() { + const updateData = () => { clearTimeout(loadTorrentFilesDataTimer); loadTorrentFilesDataTimer = -1; loadTorrentFilesData(); }; - const handleNewTorrentFiles = function(files) { + const handleNewTorrentFiles = (files) => { is_seed = (files.length > 0) ? files[0].is_seed : true; const rows = files.map((file, index) => { @@ -413,7 +413,7 @@ window.qBittorrent.PropFiles ??= (() => { updateGlobalCheckbox(); }; - const addRowsToTable = function(rows) { + const addRowsToTable = (rows) => { const selectedFiles = torrentFilesTable.selectedRowsIds(); let rowId = 0; @@ -481,7 +481,7 @@ window.qBittorrent.PropFiles ??= (() => { torrentFilesTable.reselectRows(selectedFiles); }; - const collapseIconClicked = function(event) { + const collapseIconClicked = (event) => { const id = event.getAttribute("data-id"); const node = torrentFilesTable.getNode(id); const isCollapsed = (event.parentElement.getAttribute("data-collapsed") === "true"); @@ -492,19 +492,19 @@ window.qBittorrent.PropFiles ??= (() => { collapseNode(node); }; - const expandFolder = function(id) { + const expandFolder = (id) => { const node = torrentFilesTable.getNode(id); if (node.isFolder) expandNode(node); }; - const collapseFolder = function(id) { + const collapseFolder = (id) => { const node = torrentFilesTable.getNode(id); if (node.isFolder) collapseNode(node); }; - const filesPriorityMenuClicked = function(priority) { + const filesPriorityMenuClicked = (priority) => { const selectedRows = torrentFilesTable.selectedRowsIds(); if (selectedRows.length === 0) return; @@ -532,7 +532,7 @@ window.qBittorrent.PropFiles ??= (() => { setFilePriority(Object.keys(uniqueRowIds), Object.keys(uniqueFileIds), priority); }; - const singleFileRename = function(hash) { + const singleFileRename = (hash) => { const rowId = torrentFilesTable.selectedRowsIds()[0]; if (rowId === undefined) return; @@ -560,7 +560,7 @@ window.qBittorrent.PropFiles ??= (() => { }); }; - const multiFileRename = function(hash) { + const multiFileRename = (hash) => { new MochaUI.Window({ id: "multiRenamePage", icon: "images/qbittorrent-tray.svg", @@ -583,7 +583,7 @@ window.qBittorrent.PropFiles ??= (() => { targets: "#torrentFilesTableDiv tr", menu: "torrentFilesMenu", actions: { - Rename: function(element, ref) { + Rename: (element, ref) => { const hash = torrentsTable.getCurrentTorrentID(); if (!hash) return; @@ -594,16 +594,16 @@ window.qBittorrent.PropFiles ??= (() => { singleFileRename(hash); }, - FilePrioIgnore: function(element, ref) { + FilePrioIgnore: (element, ref) => { filesPriorityMenuClicked(FilePriority.Ignored); }, - FilePrioNormal: function(element, ref) { + FilePrioNormal: (element, ref) => { filesPriorityMenuClicked(FilePriority.Normal); }, - FilePrioHigh: function(element, ref) { + FilePrioHigh: (element, ref) => { filesPriorityMenuClicked(FilePriority.High); }, - FilePrioMaximum: function(element, ref) { + FilePrioMaximum: (element, ref) => { filesPriorityMenuClicked(FilePriority.Maximum); } }, @@ -662,7 +662,7 @@ window.qBittorrent.PropFiles ??= (() => { /** * Show/hide a node's row */ - const _hideNode = function(node, shouldHide) { + const _hideNode = (node, shouldHide) => { const span = $("filesTablefileName" + node.rowId); // span won't exist if row has been filtered out if (span === null) @@ -677,7 +677,7 @@ window.qBittorrent.PropFiles ??= (() => { /** * Update a node's collapsed state and icon */ - const _updateNodeState = function(node, isCollapsed) { + const _updateNodeState = (node, isCollapsed) => { const span = $("filesTablefileName" + node.rowId); // span won't exist if row has been filtered out if (span === null) @@ -695,7 +695,7 @@ window.qBittorrent.PropFiles ??= (() => { collapseIcon.removeClass("rotate"); }; - const _isCollapsed = function(node) { + const _isCollapsed = (node) => { const span = $("filesTablefileName" + node.rowId); if (span === null) return true; @@ -704,15 +704,15 @@ window.qBittorrent.PropFiles ??= (() => { return td.getAttribute("data-collapsed") === "true"; }; - const expandNode = function(node) { + const expandNode = (node) => { _collapseNode(node, false, false, false); }; - const collapseNode = function(node) { + const collapseNode = (node) => { _collapseNode(node, true, false, false); }; - const expandAllNodes = function() { + const expandAllNodes = () => { const root = torrentFilesTable.getRoot(); root.children.each((node) => { node.children.each((child) => { @@ -721,7 +721,7 @@ window.qBittorrent.PropFiles ??= (() => { }); }; - const collapseAllNodes = function() { + const collapseAllNodes = () => { const root = torrentFilesTable.getRoot(); root.children.each((node) => { node.children.each((child) => { @@ -737,7 +737,7 @@ window.qBittorrent.PropFiles ??= (() => { * @param {boolean} applyToChildren true if the node's children should also be collapsed, recursively * @param {boolean} isChildNode true if the current node is a child of the original node we collapsed/expanded */ - const _collapseNode = function(node, shouldCollapse, applyToChildren, isChildNode) { + const _collapseNode = (node, shouldCollapse, applyToChildren, isChildNode) => { if (!node.isFolder) return; @@ -764,7 +764,7 @@ window.qBittorrent.PropFiles ??= (() => { }); }; - const clear = function() { + const clear = () => { torrentFilesTable.clear(); }; diff --git a/src/webui/www/private/scripts/prop-general.js b/src/webui/www/private/scripts/prop-general.js index f1cafe066..5d0e0a324 100644 --- a/src/webui/www/private/scripts/prop-general.js +++ b/src/webui/www/private/scripts/prop-general.js @@ -42,7 +42,7 @@ window.qBittorrent.PropGeneral ??= (() => { }); $("progress").appendChild(piecesBar); - const clearData = function() { + const clearData = () => { $("time_elapsed").textContent = ""; $("eta").textContent = ""; $("nb_connections").textContent = ""; @@ -74,7 +74,7 @@ window.qBittorrent.PropGeneral ??= (() => { }; let loadTorrentDataTimer = -1; - const loadTorrentData = function() { + const loadTorrentData = () => { if ($("propGeneral").hasClass("invisible") || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) { // Tab changed, don't do anything @@ -91,12 +91,12 @@ window.qBittorrent.PropGeneral ??= (() => { url: url, method: "get", noCache: true, - onFailure: function() { + onFailure: () => { $("error_div").textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]"; clearTimeout(loadTorrentDataTimer); loadTorrentDataTimer = loadTorrentData.delay(10000); }, - onSuccess: function(data) { + onSuccess: (data) => { $("error_div").textContent = ""; if (data) { // Update Torrent data @@ -229,12 +229,12 @@ window.qBittorrent.PropGeneral ??= (() => { url: piecesUrl, method: "get", noCache: true, - onFailure: function() { + onFailure: () => { $("error_div").textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]"; clearTimeout(loadTorrentDataTimer); loadTorrentDataTimer = loadTorrentData.delay(10000); }, - onSuccess: function(data) { + onSuccess: (data) => { $("error_div").textContent = ""; if (data) @@ -248,13 +248,13 @@ window.qBittorrent.PropGeneral ??= (() => { }).send(); }; - const updateData = function() { + const updateData = () => { clearTimeout(loadTorrentDataTimer); loadTorrentDataTimer = -1; loadTorrentData(); }; - const clear = function() { + const clear = () => { clearData(); }; diff --git a/src/webui/www/private/scripts/prop-peers.js b/src/webui/www/private/scripts/prop-peers.js index dddfc0d50..40dbca28f 100644 --- a/src/webui/www/private/scripts/prop-peers.js +++ b/src/webui/www/private/scripts/prop-peers.js @@ -42,7 +42,7 @@ window.qBittorrent.PropPeers ??= (() => { let syncTorrentPeersLastResponseId = 0; let show_flags = true; - const loadTorrentPeersData = function() { + const loadTorrentPeersData = () => { if ($("propPeers").hasClass("invisible") || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) { syncTorrentPeersLastResponseId = 0; @@ -63,11 +63,11 @@ window.qBittorrent.PropPeers ??= (() => { url: url, method: "get", noCache: true, - onComplete: function() { + onComplete: () => { clearTimeout(loadTorrentPeersTimer); loadTorrentPeersTimer = loadTorrentPeersData.delay(window.qBittorrent.Client.getSyncMainDataInterval()); }, - onSuccess: function(response) { + onSuccess: (response) => { $("error_div").textContent = ""; if (response) { const full_update = (response["full_update"] === true); @@ -106,13 +106,13 @@ window.qBittorrent.PropPeers ??= (() => { }).send(); }; - const updateData = function() { + const updateData = () => { clearTimeout(loadTorrentPeersTimer); loadTorrentPeersTimer = -1; loadTorrentPeersData(); }; - const clear = function() { + const clear = () => { torrentPeersTable.clear(); }; @@ -120,7 +120,7 @@ window.qBittorrent.PropPeers ??= (() => { targets: "#torrentPeersTableDiv", menu: "torrentPeersMenu", actions: { - addPeer: function(element, ref) { + addPeer: (element, ref) => { const hash = torrentsTable.getCurrentTorrentID(); if (!hash) return; @@ -140,7 +140,7 @@ window.qBittorrent.PropPeers ??= (() => { height: 260 }); }, - banPeer: function(element, ref) { + banPeer: (element, ref) => { const selectedPeers = torrentPeersTable.selectedRowsIds(); if (selectedPeers.length === 0) return; @@ -176,7 +176,7 @@ window.qBittorrent.PropPeers ??= (() => { }); new ClipboardJS("#CopyPeerInfo", { - text: function(trigger) { + text: (trigger) => { return torrentPeersTable.selectedRowsIds().join("\n"); } }); diff --git a/src/webui/www/private/scripts/prop-trackers.js b/src/webui/www/private/scripts/prop-trackers.js index d1dd69f27..06449dcef 100644 --- a/src/webui/www/private/scripts/prop-trackers.js +++ b/src/webui/www/private/scripts/prop-trackers.js @@ -42,7 +42,7 @@ window.qBittorrent.PropTrackers ??= (() => { const torrentTrackersTable = new window.qBittorrent.DynamicTable.TorrentTrackersTable(); let loadTrackersDataTimer = -1; - const loadTrackersData = function() { + const loadTrackersData = () => { if ($("propTrackers").hasClass("invisible") || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) { // Tab changed, don't do anything @@ -63,11 +63,11 @@ window.qBittorrent.PropTrackers ??= (() => { url: url, method: "get", noCache: true, - onComplete: function() { + onComplete: () => { clearTimeout(loadTrackersDataTimer); loadTrackersDataTimer = loadTrackersData.delay(10000); }, - onSuccess: function(trackers) { + onSuccess: (trackers) => { const selectedTrackers = torrentTrackersTable.selectedRowsIds(); torrentTrackersTable.clear(); @@ -117,7 +117,7 @@ window.qBittorrent.PropTrackers ??= (() => { }).send(); }; - const updateData = function() { + const updateData = () => { clearTimeout(loadTrackersDataTimer); loadTrackersDataTimer = -1; loadTrackersData(); @@ -127,15 +127,15 @@ window.qBittorrent.PropTrackers ??= (() => { targets: "#torrentTrackersTableDiv", menu: "torrentTrackersMenu", actions: { - AddTracker: function(element, ref) { + AddTracker: (element, ref) => { addTrackerFN(); }, - EditTracker: function(element, ref) { + EditTracker: (element, ref) => { // only allow editing of one row element.firstChild.click(); editTrackerFN(element); }, - RemoveTracker: function(element, ref) { + RemoveTracker: (element, ref) => { removeTrackerFN(element); } }, @@ -162,7 +162,7 @@ window.qBittorrent.PropTrackers ??= (() => { } }); - const addTrackerFN = function() { + const addTrackerFN = () => { if (current_hash.length === 0) return; new MochaUI.Window({ @@ -179,13 +179,13 @@ window.qBittorrent.PropTrackers ??= (() => { paddingHorizontal: 0, width: 500, height: 260, - onCloseComplete: function() { + onCloseComplete: () => { updateData(); } }); }; - const editTrackerFN = function(element) { + const editTrackerFN = (element) => { if (current_hash.length === 0) return; @@ -204,13 +204,13 @@ window.qBittorrent.PropTrackers ??= (() => { paddingHorizontal: 0, width: 500, height: 150, - onCloseComplete: function() { + onCloseComplete: () => { updateData(); } }); }; - const removeTrackerFN = function(element) { + const removeTrackerFN = (element) => { if (current_hash.length === 0) return; @@ -222,18 +222,18 @@ window.qBittorrent.PropTrackers ??= (() => { hash: current_hash, urls: selectedTrackers.map(encodeURIComponent).join("|") }, - onSuccess: function() { + onSuccess: () => { updateData(); } }).send(); }; - const clear = function() { + const clear = () => { torrentTrackersTable.clear(); }; new ClipboardJS("#CopyTrackerUrl", { - text: function(trigger) { + text: (trigger) => { return torrentTrackersTable.selectedRowsIds().join("\n"); } }); diff --git a/src/webui/www/private/scripts/prop-webseeds.js b/src/webui/www/private/scripts/prop-webseeds.js index a55a482e4..7cebc49c8 100644 --- a/src/webui/www/private/scripts/prop-webseeds.js +++ b/src/webui/www/private/scripts/prop-webseeds.js @@ -42,7 +42,7 @@ window.qBittorrent.PropWebseeds ??= (() => { let current_hash = ""; let loadWebSeedsDataTimer = -1; - const loadWebSeedsData = function() { + const loadWebSeedsData = () => { if ($("propWebSeeds").hasClass("invisible") || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) { // Tab changed, don't do anything @@ -62,11 +62,11 @@ window.qBittorrent.PropWebseeds ??= (() => { url: new URI("api/v2/torrents/webseeds").setData("hash", current_hash), method: "get", noCache: true, - onComplete: function() { + onComplete: () => { clearTimeout(loadWebSeedsDataTimer); loadWebSeedsDataTimer = loadWebSeedsData.delay(10000); }, - onSuccess: function(webseeds) { + onSuccess: (webseeds) => { const selectedWebseeds = torrentWebseedsTable.selectedRowsIds(); torrentWebseedsTable.clear(); @@ -88,7 +88,7 @@ window.qBittorrent.PropWebseeds ??= (() => { }).send(); }; - const updateData = function() { + const updateData = () => { clearTimeout(loadWebSeedsDataTimer); loadWebSeedsDataTimer = -1; loadWebSeedsData(); @@ -98,15 +98,15 @@ window.qBittorrent.PropWebseeds ??= (() => { targets: "#torrentWebseedsTableDiv", menu: "torrentWebseedsMenu", actions: { - AddWebSeeds: function(element, ref) { + AddWebSeeds: (element, ref) => { addWebseedFN(); }, - EditWebSeed: function(element, ref) { + EditWebSeed: (element, ref) => { // only allow editing of one row element.firstChild.click(); editWebSeedFN(element); }, - RemoveWebSeed: function(element, ref) { + RemoveWebSeed: (element, ref) => { removeWebSeedFN(element); } }, @@ -134,7 +134,7 @@ window.qBittorrent.PropWebseeds ??= (() => { } }); - const addWebseedFN = function() { + const addWebseedFN = () => { if (current_hash.length === 0) return; @@ -151,13 +151,13 @@ window.qBittorrent.PropWebseeds ??= (() => { paddingHorizontal: 0, width: 500, height: 260, - onCloseComplete: function() { + onCloseComplete: () => { updateData(); } }); }; - const editWebSeedFN = function(element) { + const editWebSeedFN = (element) => { if (current_hash.length === 0) return; @@ -180,13 +180,13 @@ window.qBittorrent.PropWebseeds ??= (() => { paddingHorizontal: 0, width: 500, height: 150, - onCloseComplete: function() { + onCloseComplete: () => { updateData(); } }); }; - const removeWebSeedFN = function(element) { + const removeWebSeedFN = (element) => { if (current_hash.length === 0) return; @@ -198,18 +198,18 @@ window.qBittorrent.PropWebseeds ??= (() => { hash: current_hash, urls: selectedWebseeds.map(webseed => encodeURIComponent(webseed)).join("|") }, - onSuccess: function() { + onSuccess: () => { updateData(); } }).send(); }; - const clear = function() { + const clear = () => { torrentWebseedsTable.clear(); }; new ClipboardJS("#CopyWebseedUrl", { - text: function(trigger) { + text: (trigger) => { return torrentWebseedsTable.selectedRowsIds().join("\n"); } }); diff --git a/src/webui/www/private/scripts/rename-files.js b/src/webui/www/private/scripts/rename-files.js index d4c2ad1ca..029370a05 100644 --- a/src/webui/www/private/scripts/rename-files.js +++ b/src/webui/www/private/scripts/rename-files.js @@ -44,10 +44,10 @@ window.qBittorrent.MultiRename ??= (() => { replaceAll: false, fileEnumerationStart: 0, - onChanged: function(rows) {}, - onInvalidRegex: function(err) {}, - onRenamed: function(rows) {}, - onRenameError: function(err) {}, + onChanged: (rows) => {}, + onInvalidRegex: (err) => {}, + onRenamed: (rows) => {}, + onRenameError: (err) => {}, _inner_update: function() { const findMatches = (regex, str) => { diff --git a/src/webui/www/private/scripts/search.js b/src/webui/www/private/scripts/search.js index f710cb68f..6080e9be0 100644 --- a/src/webui/www/private/scripts/search.js +++ b/src/webui/www/private/scripts/search.js @@ -105,7 +105,7 @@ window.qBittorrent.Search ??= (() => { } }); - const init = function() { + const init = () => { // load "Search in" preference from local storage $("searchInTorrentName").value = (LocalPreferences.get("search_in_filter") === "names") ? "names" : "everywhere"; const searchResultsTableContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({ @@ -166,15 +166,15 @@ window.qBittorrent.Search ??= (() => { createSearchTab(id, pattern); }; - const numSearchTabs = function() { + const numSearchTabs = () => { return $("searchTabs").getElements("li").length; }; - const getSearchIdFromTab = function(tab) { + const getSearchIdFromTab = (tab) => { return Number(tab.id.substring(searchTabIdPrefix.length)); }; - const createSearchTab = function(searchId, pattern) { + const createSearchTab = (searchId, pattern) => { const newTabId = `${searchTabIdPrefix}${searchId}`; const tabElem = new Element("a", { text: pattern, @@ -233,7 +233,7 @@ window.qBittorrent.Search ??= (() => { updateSearchResultsData(searchId); }; - const closeSearchTab = function(el) { + const closeSearchTab = (el) => { const tab = el.closest("li.searchTab"); if (!tab) return; @@ -282,7 +282,7 @@ window.qBittorrent.Search ??= (() => { } }; - const saveCurrentTabState = function() { + const saveCurrentTabState = () => { const currentSearchId = getSelectedSearchId(); if (!currentSearchId) return; @@ -313,7 +313,7 @@ window.qBittorrent.Search ??= (() => { state.selectedRowIds = [...searchResultsTable.selectedRows]; }; - const setActiveTab = function(tab) { + const setActiveTab = (tab) => { const searchId = getSearchIdFromTab(tab); if (searchId === getSelectedSearchId()) return; @@ -377,7 +377,7 @@ window.qBittorrent.Search ??= (() => { setupSearchTableEvents(true); }; - const getStatusIconElement = function(text, image) { + const getStatusIconElement = (text, image) => { return new Element("img", { alt: text, title: text, @@ -388,7 +388,7 @@ window.qBittorrent.Search ??= (() => { }); }; - const updateStatusIconElement = function(searchId, text, image) { + const updateStatusIconElement = (searchId, text, image) => { const searchTab = $(`${searchTabIdPrefix}${searchId}`); if (searchTab) { const statusIcon = searchTab.getElement(".statusIcon"); @@ -398,7 +398,7 @@ window.qBittorrent.Search ??= (() => { } }; - const startSearch = function(pattern, category, plugins) { + const startSearch = (pattern, category, plugins) => { searchPatternChanged = false; const url = new URI("api/v2/search/start"); @@ -422,7 +422,7 @@ window.qBittorrent.Search ??= (() => { }).send(); }; - const stopSearch = function(searchId) { + const stopSearch = (searchId) => { const url = new URI("api/v2/search/stop"); new Request({ url: url, @@ -430,7 +430,7 @@ window.qBittorrent.Search ??= (() => { data: { id: searchId }, - onSuccess: function(response) { + onSuccess: (response) => { resetSearchState(searchId); // not strictly necessary to do this when the tab is being closed, but there's no harm in it updateStatusIconElement(searchId, "QBT_TR(Search aborted)QBT_TR[CONTEXT=SearchJobWidget]", "images/task-reject.svg"); @@ -438,12 +438,12 @@ window.qBittorrent.Search ??= (() => { }).send(); }; - const getSelectedSearchId = function() { + const getSelectedSearchId = () => { const selectedTab = $("searchTabs").getElement("li.selected"); return selectedTab ? getSearchIdFromTab(selectedTab) : null; }; - const startStopSearch = function() { + const startStopSearch = () => { const currentSearchId = getSelectedSearchId(); const state = searchState.get(currentSearchId); const isSearchRunning = state && state.running; @@ -463,12 +463,12 @@ window.qBittorrent.Search ??= (() => { } }; - const openSearchTorrentDescriptionUrl = function() { + const openSearchTorrentDescriptionUrl = () => { for (const rowID of searchResultsTable.selectedRowsIds()) window.open(searchResultsTable.getRow(rowID).full_data.descrLink, "_blank"); }; - const copySearchTorrentName = function() { + const copySearchTorrentName = () => { const names = []; searchResultsTable.selectedRowsIds().each((rowId) => { names.push(searchResultsTable.getRow(rowId).full_data.fileName); @@ -476,7 +476,7 @@ window.qBittorrent.Search ??= (() => { return names.join("\n"); }; - const copySearchTorrentDownloadLink = function() { + const copySearchTorrentDownloadLink = () => { const urls = []; searchResultsTable.selectedRowsIds().each((rowId) => { urls.push(searchResultsTable.getRow(rowId).full_data.fileUrl); @@ -484,7 +484,7 @@ window.qBittorrent.Search ??= (() => { return urls.join("\n"); }; - const copySearchTorrentDescriptionUrl = function() { + const copySearchTorrentDescriptionUrl = () => { const urls = []; searchResultsTable.selectedRowsIds().each((rowId) => { urls.push(searchResultsTable.getRow(rowId).full_data.descrLink); @@ -492,7 +492,7 @@ window.qBittorrent.Search ??= (() => { return urls.join("\n"); }; - const downloadSearchTorrent = function() { + const downloadSearchTorrent = () => { const urls = []; for (const rowID of searchResultsTable.selectedRowsIds()) urls.push(searchResultsTable.getRow(rowID).full_data.fileUrl); @@ -504,7 +504,7 @@ window.qBittorrent.Search ??= (() => { showDownloadPage(urls); }; - const manageSearchPlugins = function() { + const manageSearchPlugins = () => { const id = "searchPlugins"; if (!$(id)) { new MochaUI.Window({ @@ -522,10 +522,10 @@ window.qBittorrent.Search ??= (() => { onResize: window.qBittorrent.Misc.createDebounceHandler(500, (e) => { saveWindowSize(id); }), - onBeforeBuild: function() { + onBeforeBuild: () => { loadSearchPlugins(); }, - onClose: function() { + onClose: () => { clearTimeout(loadSearchPluginsTimer); loadSearchPluginsTimer = -1; } @@ -533,12 +533,12 @@ window.qBittorrent.Search ??= (() => { } }; - const loadSearchPlugins = function() { + const loadSearchPlugins = () => { getPlugins(); loadSearchPluginsTimer = loadSearchPlugins.delay(2000); }; - const onSearchPatternChanged = function() { + const onSearchPatternChanged = () => { const currentSearchId = getSelectedSearchId(); const state = searchState.get(currentSearchId); const currentSearchPattern = $("searchPattern").value.trim(); @@ -553,11 +553,11 @@ window.qBittorrent.Search ??= (() => { } }; - const categorySelected = function() { + const categorySelected = () => { selectedCategory = $("categorySelect").value; }; - const pluginSelected = function() { + const pluginSelected = () => { selectedPlugin = $("pluginsSelect").value; if (selectedPlugin !== prevSelectedPlugin) { @@ -566,7 +566,7 @@ window.qBittorrent.Search ??= (() => { } }; - const reselectCategory = function() { + const reselectCategory = () => { for (let i = 0; i < $("categorySelect").options.length; ++i) { if ($("categorySelect").options[i].get("value") === selectedCategory) $("categorySelect").options[i].selected = true; @@ -575,7 +575,7 @@ window.qBittorrent.Search ??= (() => { categorySelected(); }; - const reselectPlugin = function() { + const reselectPlugin = () => { for (let i = 0; i < $("pluginsSelect").options.length; ++i) { if ($("pluginsSelect").options[i].get("value") === selectedPlugin) $("pluginsSelect").options[i].selected = true; @@ -584,7 +584,7 @@ window.qBittorrent.Search ??= (() => { pluginSelected(); }; - const resetSearchState = function(searchId) { + const resetSearchState = (searchId) => { document.getElementById("startSearchButton").lastChild.textContent = "QBT_TR(Search)QBT_TR[CONTEXT=SearchEngineWidget]"; const state = searchState.get(searchId); if (state) { @@ -642,7 +642,7 @@ window.qBittorrent.Search ??= (() => { reselectCategory(); }; - const getPlugins = function() { + const getPlugins = () => { new Request.JSON({ url: new URI("api/v2/search/plugins"), method: "get", @@ -706,7 +706,7 @@ window.qBittorrent.Search ??= (() => { }).send(); }; - const getPlugin = function(name) { + const getPlugin = (name) => { for (let i = 0; i < searchPlugins.length; ++i) { if (searchPlugins[i].name === name) return searchPlugins[i]; @@ -715,7 +715,7 @@ window.qBittorrent.Search ??= (() => { return null; }; - const resetFilters = function() { + const resetFilters = () => { searchText.filterPattern = ""; $("searchInNameFilter").value = ""; @@ -734,23 +734,23 @@ window.qBittorrent.Search ??= (() => { $("searchMaxSizePrefix").value = searchSizeFilter.maxUnit; }; - const getSearchInTorrentName = function() { + const getSearchInTorrentName = () => { return ($("searchInTorrentName").value === "names") ? "names" : "everywhere"; }; - const searchInTorrentName = function() { + const searchInTorrentName = () => { LocalPreferences.set("search_in_filter", getSearchInTorrentName()); searchFilterChanged(); }; - const searchSeedsFilterChanged = function() { + const searchSeedsFilterChanged = () => { searchSeedsFilter.min = $("searchMinSeedsFilter").value; searchSeedsFilter.max = $("searchMaxSeedsFilter").value; searchFilterChanged(); }; - const searchSizeFilterChanged = function() { + const searchSizeFilterChanged = () => { searchSizeFilter.min = $("searchMinSizeFilter").value; searchSizeFilter.minUnit = $("searchMinSizePrefix").value; searchSizeFilter.max = $("searchMaxSizeFilter").value; @@ -759,17 +759,17 @@ window.qBittorrent.Search ??= (() => { searchFilterChanged(); }; - const searchSizeFilterPrefixChanged = function() { + const searchSizeFilterPrefixChanged = () => { if ((Number($("searchMinSizeFilter").value) !== 0) || (Number($("searchMaxSizeFilter").value) !== 0)) searchSizeFilterChanged(); }; - const searchFilterChanged = function() { + const searchFilterChanged = () => { searchResultsTable.updateTable(); $("numSearchResultsVisible").textContent = searchResultsTable.getFilteredAndSortedRows().length; }; - const setupSearchTableEvents = function(enable) { + const setupSearchTableEvents = (enable) => { const clickHandler = (e) => { downloadSearchTorrent(); }; if (enable) { $$(".searchTableRow").each((target) => { @@ -881,7 +881,7 @@ window.qBittorrent.Search ??= (() => { }; new ClipboardJS(".copySearchDataToClipboard", { - text: function(trigger) { + text: (trigger) => { switch (trigger.id) { case "copySearchTorrentName": return copySearchTorrentName(); diff --git a/src/webui/www/private/scripts/speedslider.js b/src/webui/www/private/scripts/speedslider.js index 8cbc45e90..171fb2079 100644 --- a/src/webui/www/private/scripts/speedslider.js +++ b/src/webui/www/private/scripts/speedslider.js @@ -29,7 +29,7 @@ "use strict"; MochaUI.extend({ - addUpLimitSlider: function(hashes) { + addUpLimitSlider: (hashes) => { if ($("uplimitSliderarea")) { // Get global upload limit let maximum = 500; @@ -37,7 +37,7 @@ MochaUI.extend({ url: "api/v2/transfer/uploadLimit", method: "get", data: {}, - onSuccess: function(data) { + onSuccess: (data) => { if (data) { const tmp = data.toInt(); if (tmp > 0) { @@ -61,7 +61,7 @@ MochaUI.extend({ steps: maximum, offset: 0, initialStep: up_limit.round(), - onChange: function(pos) { + onChange: (pos) => { if (pos > 0) { $("uplimitUpdatevalue").value = pos; $("upLimitUnit").style.visibility = "visible"; @@ -70,7 +70,7 @@ MochaUI.extend({ $("uplimitUpdatevalue").value = "∞"; $("upLimitUnit").style.visibility = "hidden"; } - }.bind(this) + } }); // Set default value if (up_limit === 0) { @@ -89,7 +89,7 @@ MochaUI.extend({ data: { hashes: hashes.join("|") }, - onSuccess: function(data) { + onSuccess: (data) => { if (data) { let up_limit = data[hashes[0]]; for (const key in data) { @@ -104,7 +104,7 @@ MochaUI.extend({ steps: maximum, offset: 0, initialStep: (up_limit / 1024.0).round(), - onChange: function(pos) { + onChange: (pos) => { if (pos > 0) { $("uplimitUpdatevalue").value = pos; $("upLimitUnit").style.visibility = "visible"; @@ -113,7 +113,7 @@ MochaUI.extend({ $("uplimitUpdatevalue").value = "∞"; $("upLimitUnit").style.visibility = "hidden"; } - }.bind(this) + } }); // Set default value if (up_limit === 0) { @@ -133,7 +133,7 @@ MochaUI.extend({ } }, - addDlLimitSlider: function(hashes) { + addDlLimitSlider: (hashes) => { if ($("dllimitSliderarea")) { // Get global upload limit let maximum = 500; @@ -141,7 +141,7 @@ MochaUI.extend({ url: "api/v2/transfer/downloadLimit", method: "get", data: {}, - onSuccess: function(data) { + onSuccess: (data) => { if (data) { const tmp = data.toInt(); if (tmp > 0) { @@ -165,7 +165,7 @@ MochaUI.extend({ steps: maximum, offset: 0, initialStep: dl_limit.round(), - onChange: function(pos) { + onChange: (pos) => { if (pos > 0) { $("dllimitUpdatevalue").value = pos; $("dlLimitUnit").style.visibility = "visible"; @@ -174,7 +174,7 @@ MochaUI.extend({ $("dllimitUpdatevalue").value = "∞"; $("dlLimitUnit").style.visibility = "hidden"; } - }.bind(this) + } }); // Set default value if (dl_limit === 0) { @@ -193,7 +193,7 @@ MochaUI.extend({ data: { hashes: hashes.join("|") }, - onSuccess: function(data) { + onSuccess: (data) => { if (data) { let dl_limit = data[hashes[0]]; for (const key in data) { @@ -208,7 +208,7 @@ MochaUI.extend({ steps: maximum, offset: 0, initialStep: (dl_limit / 1024.0).round(), - onChange: function(pos) { + onChange: (pos) => { if (pos > 0) { $("dllimitUpdatevalue").value = pos; $("dlLimitUnit").style.visibility = "visible"; @@ -217,7 +217,7 @@ MochaUI.extend({ $("dllimitUpdatevalue").value = "∞"; $("dlLimitUnit").style.visibility = "hidden"; } - }.bind(this) + } }); // Set default value if (dl_limit === 0) { diff --git a/src/webui/www/private/setlocation.html b/src/webui/www/private/setlocation.html index 57aced981..0b7c888ac 100644 --- a/src/webui/www/private/setlocation.html +++ b/src/webui/www/private/setlocation.html @@ -56,10 +56,10 @@ hashes: hashesList, location: location }, - onSuccess: function() { + onSuccess: () => { window.parent.qBittorrent.Client.closeWindows(); }, - onFailure: function(xhr) { + onFailure: (xhr) => { $("error_div").textContent = xhr.response; } }).send(); diff --git a/src/webui/www/private/shareratio.html b/src/webui/www/private/shareratio.html index 95d79fb3e..e7e4f141e 100644 --- a/src/webui/www/private/shareratio.html +++ b/src/webui/www/private/shareratio.html @@ -112,14 +112,14 @@ seedingTimeLimit: seedingTimeLimitValue, inactiveSeedingTimeLimit: inactiveSeedingTimeLimitValue }, - onComplete: function() { + onComplete: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); }); }); - function getSelectedRadioValue(name) { + const getSelectedRadioValue = (name) => { const radios = document.getElementsByName(name); for (let i = 0; i < radios.length; ++i) { @@ -127,9 +127,9 @@ if (radio.checked) return radio.value; } - } + }; - function setSelectedRadioValue(name, value) { + const setSelectedRadioValue = (name, value) => { const radios = document.getElementsByName(name); for (let i = 0; i < radios.length; ++i) { @@ -137,9 +137,9 @@ if (radio.value === value) radio.checked = true; } - } + }; - function shareLimitChanged() { + const shareLimitChanged = () => { const customShareLimit = getSelectedRadioValue("shareLimit") === "custom"; $("setRatio").disabled = !customShareLimit; $("setTotalMinutes").disabled = !customShareLimit; @@ -148,20 +148,20 @@ enableInputBoxes(); $("save").disabled = !isFormValid(); - } + }; - function enableInputBoxes() { + const enableInputBoxes = () => { $("ratio").disabled = $("setRatio").disabled || !$("setRatio").checked; $("totalMinutes").disabled = $("setTotalMinutes").disabled || !$("setTotalMinutes").checked; $("inactiveMinutes").disabled = $("setInactiveMinutes").disabled || !$("setInactiveMinutes").checked; $("save").disabled = !isFormValid(); - } + }; - function isFormValid() { + const isFormValid = () => { return !((getSelectedRadioValue("shareLimit") === "custom") && !$("setRatio").checked && !$("setTotalMinutes").checked && !$("setInactiveMinutes").checked); - } + }; diff --git a/src/webui/www/private/uploadlimit.html b/src/webui/www/private/uploadlimit.html index 0a3a998e6..c0bd10d7b 100644 --- a/src/webui/www/private/uploadlimit.html +++ b/src/webui/www/private/uploadlimit.html @@ -32,7 +32,7 @@ "use strict"; const hashes = new URI().getData("hashes").split("|"); - const setUpLimit = function() { + const setUpLimit = () => { const limit = $("uplimitUpdatevalue").value.toInt() * 1024; if (hashes[0] === "global") { new Request({ @@ -41,7 +41,7 @@ data: { "limit": limit }, - onComplete: function() { + onComplete: () => { window.parent.updateMainData(); window.parent.qBittorrent.Client.closeWindows(); } @@ -55,7 +55,7 @@ "hashes": hashes.join("|"), "limit": limit }, - onComplete: function() { + onComplete: () => { window.parent.qBittorrent.Client.closeWindows(); } }).send(); diff --git a/src/webui/www/private/views/aboutToolbar.html b/src/webui/www/private/views/aboutToolbar.html index b95e8ed48..21f25080d 100644 --- a/src/webui/www/private/views/aboutToolbar.html +++ b/src/webui/www/private/views/aboutToolbar.html @@ -13,7 +13,7 @@