Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebUI: use template literals instead of string concatenation #22177

Merged
merged 2 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/webui/www/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default [
"operator-assignment": "error",
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-template": "error",
"radix": "error",
"PreferArrowFunctions/prefer-arrow-functions": "error",
"Stylistic/no-mixed-operators": [
Expand Down
2 changes: 1 addition & 1 deletion src/webui/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@stylistic/eslint-plugin": "*",
"eslint": "*",
"eslint-plugin-html": "*",
"eslint-plugin-prefer-arrow-functions": "3.4.2",
"eslint-plugin-prefer-arrow-functions": "*",
"eslint-plugin-regexp": "*",
"html-validate": "*",
"js-beautify": "*",
Expand Down
2 changes: 1 addition & 1 deletion src/webui/www/private/newcategory.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
})
.then((response) => {
if (!response.ok) {
alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=Category] " + window.qBittorrent.Misc.escapeHtml(categoryName));
alert(`QBT_TR(Unable to create category)QBT_TR[CONTEXT=Category] ${window.qBittorrent.Misc.escapeHtml(categoryName)}`);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/webui/www/private/rename_files.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
// Update renamed column for matched rows
for (let i = 0; i < matchedRows.length; ++i) {
const row = matchedRows[i];
$("filesTablefileRenamed" + row.rowId).textContent = row.renamed;
$(`filesTablefileRenamed${row.rowId}`).textContent = row.renamed;
}
};
fileRenamer.onInvalidRegex = (err) => {
Expand Down
26 changes: 13 additions & 13 deletions src/webui/www/private/scripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ window.qBittorrent.Client ??= (() => {
const mainTitle = () => {
const emDash = "\u2014";
const qbtVersion = window.qBittorrent.Cache.qbtVersion.get();
const suffix = window.qBittorrent.Cache.preferences.get()["app_instance_name"] || "";
const title = `qBittorrent ${qbtVersion} QBT_TR(WebUI)QBT_TR[CONTEXT=OptionsDialog]`
+ ((suffix.length > 0) ? ` ${emDash} ${suffix}` : "");
let suffix = window.qBittorrent.Cache.preferences.get()["app_instance_name"] || "";
if (suffix.length > 0)
suffix = ` ${emDash} ${suffix}`;
const title = `qBittorrent ${qbtVersion} QBT_TR(WebUI)QBT_TR[CONTEXT=OptionsDialog]${suffix}`;
return title;
};

Expand Down Expand Up @@ -952,13 +953,13 @@ window.addEventListener("DOMContentLoaded", () => {
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) + "]";
transfer_info += " (" + window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_data, false) + ")";
transfer_info += ` [${window.qBittorrent.Misc.friendlyUnit(serverState.dl_rate_limit, true)}]`;
transfer_info += ` (${window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_data, false)})`;
$("DlInfos").textContent = transfer_info;
transfer_info = window.qBittorrent.Misc.friendlyUnit(serverState.up_info_speed, true);
if (serverState.up_rate_limit > 0)
transfer_info += " [" + window.qBittorrent.Misc.friendlyUnit(serverState.up_rate_limit, true) + "]";
transfer_info += " (" + window.qBittorrent.Misc.friendlyUnit(serverState.up_info_data, false) + ")";
transfer_info += ` [${window.qBittorrent.Misc.friendlyUnit(serverState.up_rate_limit, true)}]`;
transfer_info += ` (${window.qBittorrent.Misc.friendlyUnit(serverState.up_info_data, false)})`;
$("UpInfos").textContent = transfer_info;

document.title = (speedInTitle
Expand Down Expand Up @@ -1010,12 +1011,12 @@ window.addEventListener("DOMContentLoaded", () => {
$("TotalWastedSession").textContent = window.qBittorrent.Misc.friendlyUnit(serverState.total_wasted_session, false);
$("GlobalRatio").textContent = serverState.global_ratio;
$("TotalPeerConnections").textContent = serverState.total_peer_connections;
$("ReadCacheHits").textContent = serverState.read_cache_hits + "%";
$("ReadCacheHits").textContent = `${serverState.read_cache_hits}%`;
$("TotalBuffersSize").textContent = window.qBittorrent.Misc.friendlyUnit(serverState.total_buffers_size, false);
$("WriteCacheOverload").textContent = serverState.write_cache_overload + "%";
$("ReadCacheOverload").textContent = serverState.read_cache_overload + "%";
$("WriteCacheOverload").textContent = `${serverState.write_cache_overload}%`;
$("ReadCacheOverload").textContent = `${serverState.read_cache_overload}%`;
$("QueuedIOJobs").textContent = serverState.queued_io_jobs;
$("AverageTimeInQueue").textContent = serverState.average_time_queue + " ms";
$("AverageTimeInQueue").textContent = `${serverState.average_time_queue} ms`;
$("TotalQueuedSize").textContent = window.qBittorrent.Misc.friendlyUnit(serverState.total_queued_size, false);
}

Expand Down Expand Up @@ -1149,8 +1150,7 @@ window.addEventListener("DOMContentLoaded", () => {
hashParams.set("download", "");

const templateHashString = hashParams.toString().replace("download=", "download=%s");
const templateUrl = location.origin + location.pathname
+ location.search + "#" + templateHashString;
const templateUrl = `${location.origin}${location.pathname}${location.search}#${templateHashString}`;

navigator.registerProtocolHandler("magnet", templateUrl,
"qBittorrent WebUI magnet handler");
Expand Down
Loading
Loading