Simplify code

This commit is contained in:
Chocobo1 2024-02-10 19:04:15 +08:00
parent 963a7faab8
commit 16a91f26fb
3 changed files with 95 additions and 106 deletions

View file

@ -264,29 +264,21 @@ window.addEventListener("DOMContentLoaded", function() {
initializeWindows();
// Show Top Toolbar is enabled by default
let showTopToolbar = true;
if (LocalPreferences.get('show_top_toolbar') !== null)
showTopToolbar = LocalPreferences.get('show_top_toolbar') == "true";
let showTopToolbar = LocalPreferences.get('show_top_toolbar', 'true') == "true";
if (!showTopToolbar) {
$('showTopToolbarLink').firstChild.style.opacity = '0';
$('mochaToolbar').addClass('invisible');
}
// Show Status Bar is enabled by default
let showStatusBar = true;
if (LocalPreferences.get('show_status_bar') !== null)
showStatusBar = LocalPreferences.get('show_status_bar') === "true";
let showStatusBar = LocalPreferences.get('show_status_bar', 'true') === "true";
if (!showStatusBar) {
$('showStatusBarLink').firstChild.style.opacity = '0';
$('desktopFooterWrapper').addClass('invisible');
}
const getShowFiltersSidebar = function() {
// Show Filters Sidebar is enabled by default
const show = LocalPreferences.get('show_filters_sidebar');
return (show === null) || (show === 'true');
};
const showFiltersSidebar = getShowFiltersSidebar();
// Show Filters Sidebar is enabled by default
let showFiltersSidebar = LocalPreferences.get('show_filters_sidebar', 'true') === "true";
if (!showFiltersSidebar) {
$('showFiltersSidebarLink').firstChild.style.opacity = '0';
$('filtersColumn').addClass('invisible');
@ -1032,7 +1024,7 @@ window.addEventListener("DOMContentLoaded", function() {
});
$('showFiltersSidebarLink').addEvent('click', function(e) {
const showFiltersSidebar = !getShowFiltersSidebar();
showFiltersSidebar = !showFiltersSidebar;
LocalPreferences.set('show_filters_sidebar', showFiltersSidebar.toString());
if (showFiltersSidebar) {
$('showFiltersSidebarLink').firstChild.style.opacity = '1';

View file

@ -100,113 +100,110 @@ window.qBittorrent.PropGeneral = (function() {
onSuccess: function(data) {
$('error_div').set('html', '');
if (data) {
let temp;
// Update Torrent data
if (data.seeding_time > 0)
temp = "QBT_TR(%1 (seeded for %2))QBT_TR[CONTEXT=PropertiesWidget]"
const timeElapsed = (data.seeding_time > 0)
? "QBT_TR(%1 (seeded for %2))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", window.qBittorrent.Misc.friendlyDuration(data.time_elapsed))
.replace("%2", window.qBittorrent.Misc.friendlyDuration(data.seeding_time));
else
temp = window.qBittorrent.Misc.friendlyDuration(data.time_elapsed);
$('time_elapsed').set('html', temp);
.replace("%2", window.qBittorrent.Misc.friendlyDuration(data.seeding_time))
: window.qBittorrent.Misc.friendlyDuration(data.time_elapsed);
$('time_elapsed').set('html', timeElapsed);
$('eta').set('html', window.qBittorrent.Misc.friendlyDuration(data.eta, window.qBittorrent.Misc.MAX_ETA));
temp = "QBT_TR(%1 (%2 max))QBT_TR[CONTEXT=PropertiesWidget]"
const nbConnections = "QBT_TR(%1 (%2 max))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", data.nb_connections)
.replace("%2", data.nb_connections_limit < 0 ? "∞" : data.nb_connections_limit);
$('nb_connections').set('html', temp);
.replace("%2", ((data.nb_connections_limit < 0) ? "∞" : data.nb_connections_limit));
$('nb_connections').set('html', nbConnections);
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
const totalDownloaded = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", window.qBittorrent.Misc.friendlyUnit(data.total_downloaded))
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.total_downloaded_session));
$('total_downloaded').set('html', temp);
$('total_downloaded').set('html', totalDownloaded);
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
const totalUploaded = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", window.qBittorrent.Misc.friendlyUnit(data.total_uploaded))
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.total_uploaded_session));
$('total_uploaded').set('html', temp);
$('total_uploaded').set('html', totalUploaded);
temp = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]"
const dlSpeed = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", window.qBittorrent.Misc.friendlyUnit(data.dl_speed, true))
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.dl_speed_avg, true));
$('dl_speed').set('html', temp);
$('dl_speed').set('html', dlSpeed);
temp = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]"
const upSpeed = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", window.qBittorrent.Misc.friendlyUnit(data.up_speed, true))
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.up_speed_avg, true));
$('up_speed').set('html', temp);
$('up_speed').set('html', upSpeed);
temp = (data.dl_limit == -1 ? "∞" : window.qBittorrent.Misc.friendlyUnit(data.dl_limit, true));
$('dl_limit').set('html', temp);
const dlLimit = (data.dl_limit === -1)
? "∞"
: window.qBittorrent.Misc.friendlyUnit(data.dl_limit, true);
$('dl_limit').set('html', dlLimit);
temp = (data.up_limit == -1 ? "∞" : window.qBittorrent.Misc.friendlyUnit(data.up_limit, true));
$('up_limit').set('html', temp);
const upLimit = (data.up_limit === -1)
? "∞"
: window.qBittorrent.Misc.friendlyUnit(data.up_limit, true);
$('up_limit').set('html', upLimit);
$('total_wasted').set('html', window.qBittorrent.Misc.friendlyUnit(data.total_wasted));
temp = "QBT_TR(%1 (%2 total))QBT_TR[CONTEXT=PropertiesWidget]"
const seeds = "QBT_TR(%1 (%2 total))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", data.seeds)
.replace("%2", data.seeds_total);
$('seeds').set('html', temp);
$('seeds').set('html', seeds);
temp = "QBT_TR(%1 (%2 total))QBT_TR[CONTEXT=PropertiesWidget]"
const peers = "QBT_TR(%1 (%2 total))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", data.peers)
.replace("%2", data.peers_total);
$('peers').set('html', temp);
$('peers').set('html', peers);
$('share_ratio').set('html', data.share_ratio.toFixed(2));
$('reannounce').set('html', window.qBittorrent.Misc.friendlyDuration(data.reannounce));
if (data.last_seen != -1)
temp = new Date(data.last_seen * 1000).toLocaleString();
else
temp = "QBT_TR(Never)QBT_TR[CONTEXT=PropertiesWidget]";
$('last_seen').set('html', temp);
const lastSeen = (data.last_seen >= 0)
? new Date(data.last_seen * 1000).toLocaleString()
: "QBT_TR(Never)QBT_TR[CONTEXT=PropertiesWidget]";
$('last_seen').set('html', lastSeen);
temp = (data.total_size >= 0) ? window.qBittorrent.Misc.friendlyUnit(data.total_size) : "";
$('total_size').set('html', temp);
const totalSize = (data.total_size >= 0) ? window.qBittorrent.Misc.friendlyUnit(data.total_size) : "";
$('total_size').set('html', totalSize);
if (data.pieces_num >= 0) {
temp = "QBT_TR(%1 x %2 (have %3))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", data.pieces_num)
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.piece_size))
.replace("%3", data.pieces_have);
}
else {
temp = "";
}
$('pieces').set('html', temp);
const pieces = (data.pieces_num >= 0)
? "QBT_TR(%1 x %2 (have %3))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", data.pieces_num)
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.piece_size))
.replace("%3", data.pieces_have)
: '';
$('pieces').set('html', pieces);
$('created_by').set('text', data.created_by);
if (data.addition_date != -1)
temp = new Date(data.addition_date * 1000).toLocaleString();
else
temp = "QBT_TR(Unknown)QBT_TR[CONTEXT=HttpServer]";
$('addition_date').set('html', temp);
const additionDate = (data.addition_date >= 0)
? new Date(data.addition_date * 1000).toLocaleString()
: "QBT_TR(Unknown)QBT_TR[CONTEXT=HttpServer]";
$('addition_date').set('html', additionDate);
if (data.completion_date != -1)
temp = new Date(data.completion_date * 1000).toLocaleString();
else
temp = "";
$('completion_date').set('html', temp);
const completionDate = (data.completion_date >= 0)
? new Date(data.completion_date * 1000).toLocaleString()
: "";
$('completion_date').set('html', completionDate);
temp = (data.creation_date >= 0) ? (new Date(data.creation_date * 1000).toLocaleString()) : "";
$('creation_date').set('html', temp);
const creationDate = (data.creation_date >= 0)
? new Date(data.creation_date * 1000).toLocaleString()
: "";
$('creation_date').set('html', creationDate);
if (data.infohash_v1 === "")
temp = "QBT_TR(N/A)QBT_TR[CONTEXT=PropertiesWidget]";
else
temp = data.infohash_v1;
$('torrent_hash_v1').set('html', temp);
const torrentHashV1 = (data.infohash_v1 !== "")
? data.infohash_v1
: "QBT_TR(N/A)QBT_TR[CONTEXT=PropertiesWidget]";
$('torrent_hash_v1').set('html', torrentHashV1);
if (data.infohash_v2 === "")
temp = "QBT_TR(N/A)QBT_TR[CONTEXT=PropertiesWidget]";
else
temp = data.infohash_v2;
$('torrent_hash_v2').set('html', temp);
const torrentHashV2 = (data.infohash_v2 !== "")
? data.infohash_v2
: "QBT_TR(N/A)QBT_TR[CONTEXT=PropertiesWidget]";
$('torrent_hash_v2').set('html', torrentHashV2);
$('save_path').set('html', data.save_path);

View file

@ -1574,34 +1574,6 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
};
};
// hide entries
const buildInfo = window.qBittorrent.Cache.buildInfo.get();
const libtorrentVersion = window.qBittorrent.Misc.parseVersion(buildInfo.libtorrent);
if (libtorrentVersion.valid) {
if (libtorrentVersion.major >= 2) {
$('rowDiskCache').style.display = 'none';
$('rowDiskCacheExpiryInterval').style.display = 'none';
$('rowCoalesceReadsAndWrites').style.display = 'none';
}
else {
$('fieldsetI2p').style.display = 'none';
$('rowMemoryWorkingSetLimit').style.display = 'none';
$('rowHashingThreads').style.display = 'none';
$('rowDiskIOType').style.display = 'none';
$('rowI2pInboundQuantity').style.display = 'none';
$('rowI2pOutboundQuantity').style.display = 'none';
$('rowI2pInboundLength').style.display = 'none';
$('rowI2pOutboundLength').style.display = 'none';
}
if (!((libtorrentVersion.major >= 2) && (libtorrentVersion.minor >= 0) && (libtorrentVersion.fix >= 6)))
$('diskIOWriteModeWriteThrough').style.display = 'none';
}
if ((buildInfo.platform !== 'macos') && (buildInfo.platform !== 'windows'))
$('rowMarkOfTheWeb').style.display = 'none';
// Behavior tab
const numberInputLimiter = (input) => {
const min = input.getAttribute("min");
@ -2848,6 +2820,34 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
});
};
// hide entries
const buildInfo = window.qBittorrent.Cache.buildInfo.get();
const libtorrentVersion = window.qBittorrent.Misc.parseVersion(buildInfo.libtorrent);
if (libtorrentVersion.valid) {
if (libtorrentVersion.major >= 2) {
$('rowDiskCache').style.display = 'none';
$('rowDiskCacheExpiryInterval').style.display = 'none';
$('rowCoalesceReadsAndWrites').style.display = 'none';
}
else {
$('fieldsetI2p').style.display = 'none';
$('rowMemoryWorkingSetLimit').style.display = 'none';
$('rowHashingThreads').style.display = 'none';
$('rowDiskIOType').style.display = 'none';
$('rowI2pInboundQuantity').style.display = 'none';
$('rowI2pOutboundQuantity').style.display = 'none';
$('rowI2pInboundLength').style.display = 'none';
$('rowI2pOutboundLength').style.display = 'none';
}
if (!((libtorrentVersion.major >= 2) && (libtorrentVersion.minor >= 0) && (libtorrentVersion.fix >= 6)))
$('diskIOWriteModeWriteThrough').style.display = 'none';
}
if ((buildInfo.platform !== 'macos') && (buildInfo.platform !== 'windows'))
$('rowMarkOfTheWeb').style.display = 'none';
$('networkInterface').addEvent('change', function() {
updateInterfaceAddresses($(this).getProperty('value'), '');
});