mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-10-22 10:46:04 +03:00
Simplify code
This commit is contained in:
parent
963a7faab8
commit
16a91f26fb
3 changed files with 95 additions and 106 deletions
|
@ -264,29 +264,21 @@ window.addEventListener("DOMContentLoaded", function() {
|
||||||
initializeWindows();
|
initializeWindows();
|
||||||
|
|
||||||
// Show Top Toolbar is enabled by default
|
// Show Top Toolbar is enabled by default
|
||||||
let showTopToolbar = true;
|
let showTopToolbar = LocalPreferences.get('show_top_toolbar', 'true') == "true";
|
||||||
if (LocalPreferences.get('show_top_toolbar') !== null)
|
|
||||||
showTopToolbar = LocalPreferences.get('show_top_toolbar') == "true";
|
|
||||||
if (!showTopToolbar) {
|
if (!showTopToolbar) {
|
||||||
$('showTopToolbarLink').firstChild.style.opacity = '0';
|
$('showTopToolbarLink').firstChild.style.opacity = '0';
|
||||||
$('mochaToolbar').addClass('invisible');
|
$('mochaToolbar').addClass('invisible');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show Status Bar is enabled by default
|
// Show Status Bar is enabled by default
|
||||||
let showStatusBar = true;
|
let showStatusBar = LocalPreferences.get('show_status_bar', 'true') === "true";
|
||||||
if (LocalPreferences.get('show_status_bar') !== null)
|
|
||||||
showStatusBar = LocalPreferences.get('show_status_bar') === "true";
|
|
||||||
if (!showStatusBar) {
|
if (!showStatusBar) {
|
||||||
$('showStatusBarLink').firstChild.style.opacity = '0';
|
$('showStatusBarLink').firstChild.style.opacity = '0';
|
||||||
$('desktopFooterWrapper').addClass('invisible');
|
$('desktopFooterWrapper').addClass('invisible');
|
||||||
}
|
}
|
||||||
|
|
||||||
const getShowFiltersSidebar = function() {
|
// Show Filters Sidebar is enabled by default
|
||||||
// Show Filters Sidebar is enabled by default
|
let showFiltersSidebar = LocalPreferences.get('show_filters_sidebar', 'true') === "true";
|
||||||
const show = LocalPreferences.get('show_filters_sidebar');
|
|
||||||
return (show === null) || (show === 'true');
|
|
||||||
};
|
|
||||||
const showFiltersSidebar = getShowFiltersSidebar();
|
|
||||||
if (!showFiltersSidebar) {
|
if (!showFiltersSidebar) {
|
||||||
$('showFiltersSidebarLink').firstChild.style.opacity = '0';
|
$('showFiltersSidebarLink').firstChild.style.opacity = '0';
|
||||||
$('filtersColumn').addClass('invisible');
|
$('filtersColumn').addClass('invisible');
|
||||||
|
@ -1032,7 +1024,7 @@ window.addEventListener("DOMContentLoaded", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
$('showFiltersSidebarLink').addEvent('click', function(e) {
|
$('showFiltersSidebarLink').addEvent('click', function(e) {
|
||||||
const showFiltersSidebar = !getShowFiltersSidebar();
|
showFiltersSidebar = !showFiltersSidebar;
|
||||||
LocalPreferences.set('show_filters_sidebar', showFiltersSidebar.toString());
|
LocalPreferences.set('show_filters_sidebar', showFiltersSidebar.toString());
|
||||||
if (showFiltersSidebar) {
|
if (showFiltersSidebar) {
|
||||||
$('showFiltersSidebarLink').firstChild.style.opacity = '1';
|
$('showFiltersSidebarLink').firstChild.style.opacity = '1';
|
||||||
|
|
|
@ -100,113 +100,110 @@ window.qBittorrent.PropGeneral = (function() {
|
||||||
onSuccess: function(data) {
|
onSuccess: function(data) {
|
||||||
$('error_div').set('html', '');
|
$('error_div').set('html', '');
|
||||||
if (data) {
|
if (data) {
|
||||||
let temp;
|
|
||||||
// Update Torrent data
|
// 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("%1", window.qBittorrent.Misc.friendlyDuration(data.time_elapsed))
|
||||||
.replace("%2", window.qBittorrent.Misc.friendlyDuration(data.seeding_time));
|
.replace("%2", window.qBittorrent.Misc.friendlyDuration(data.seeding_time))
|
||||||
else
|
: window.qBittorrent.Misc.friendlyDuration(data.time_elapsed);
|
||||||
temp = window.qBittorrent.Misc.friendlyDuration(data.time_elapsed);
|
$('time_elapsed').set('html', timeElapsed);
|
||||||
$('time_elapsed').set('html', temp);
|
|
||||||
|
|
||||||
$('eta').set('html', window.qBittorrent.Misc.friendlyDuration(data.eta, window.qBittorrent.Misc.MAX_ETA));
|
$('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("%1", data.nb_connections)
|
||||||
.replace("%2", data.nb_connections_limit < 0 ? "∞" : data.nb_connections_limit);
|
.replace("%2", ((data.nb_connections_limit < 0) ? "∞" : data.nb_connections_limit));
|
||||||
$('nb_connections').set('html', temp);
|
$('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("%1", window.qBittorrent.Misc.friendlyUnit(data.total_downloaded))
|
||||||
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.total_downloaded_session));
|
.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("%1", window.qBittorrent.Misc.friendlyUnit(data.total_uploaded))
|
||||||
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.total_uploaded_session));
|
.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("%1", window.qBittorrent.Misc.friendlyUnit(data.dl_speed, true))
|
||||||
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.dl_speed_avg, 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("%1", window.qBittorrent.Misc.friendlyUnit(data.up_speed, true))
|
||||||
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.up_speed_avg, 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));
|
const dlLimit = (data.dl_limit === -1)
|
||||||
$('dl_limit').set('html', temp);
|
? "∞"
|
||||||
|
: 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));
|
const upLimit = (data.up_limit === -1)
|
||||||
$('up_limit').set('html', temp);
|
? "∞"
|
||||||
|
: window.qBittorrent.Misc.friendlyUnit(data.up_limit, true);
|
||||||
|
$('up_limit').set('html', upLimit);
|
||||||
|
|
||||||
$('total_wasted').set('html', window.qBittorrent.Misc.friendlyUnit(data.total_wasted));
|
$('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("%1", data.seeds)
|
||||||
.replace("%2", data.seeds_total);
|
.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("%1", data.peers)
|
||||||
.replace("%2", data.peers_total);
|
.replace("%2", data.peers_total);
|
||||||
$('peers').set('html', temp);
|
$('peers').set('html', peers);
|
||||||
|
|
||||||
$('share_ratio').set('html', data.share_ratio.toFixed(2));
|
$('share_ratio').set('html', data.share_ratio.toFixed(2));
|
||||||
|
|
||||||
$('reannounce').set('html', window.qBittorrent.Misc.friendlyDuration(data.reannounce));
|
$('reannounce').set('html', window.qBittorrent.Misc.friendlyDuration(data.reannounce));
|
||||||
|
|
||||||
if (data.last_seen != -1)
|
const lastSeen = (data.last_seen >= 0)
|
||||||
temp = new Date(data.last_seen * 1000).toLocaleString();
|
? new Date(data.last_seen * 1000).toLocaleString()
|
||||||
else
|
: "QBT_TR(Never)QBT_TR[CONTEXT=PropertiesWidget]";
|
||||||
temp = "QBT_TR(Never)QBT_TR[CONTEXT=PropertiesWidget]";
|
$('last_seen').set('html', lastSeen);
|
||||||
$('last_seen').set('html', temp);
|
|
||||||
|
|
||||||
temp = (data.total_size >= 0) ? window.qBittorrent.Misc.friendlyUnit(data.total_size) : "";
|
const totalSize = (data.total_size >= 0) ? window.qBittorrent.Misc.friendlyUnit(data.total_size) : "";
|
||||||
$('total_size').set('html', temp);
|
$('total_size').set('html', totalSize);
|
||||||
|
|
||||||
if (data.pieces_num >= 0) {
|
const pieces = (data.pieces_num >= 0)
|
||||||
temp = "QBT_TR(%1 x %2 (have %3))QBT_TR[CONTEXT=PropertiesWidget]"
|
? "QBT_TR(%1 x %2 (have %3))QBT_TR[CONTEXT=PropertiesWidget]"
|
||||||
.replace("%1", data.pieces_num)
|
.replace("%1", data.pieces_num)
|
||||||
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.piece_size))
|
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.piece_size))
|
||||||
.replace("%3", data.pieces_have);
|
.replace("%3", data.pieces_have)
|
||||||
}
|
: '';
|
||||||
else {
|
$('pieces').set('html', pieces);
|
||||||
temp = "";
|
|
||||||
}
|
|
||||||
$('pieces').set('html', temp);
|
|
||||||
|
|
||||||
$('created_by').set('text', data.created_by);
|
$('created_by').set('text', data.created_by);
|
||||||
|
|
||||||
if (data.addition_date != -1)
|
const additionDate = (data.addition_date >= 0)
|
||||||
temp = new Date(data.addition_date * 1000).toLocaleString();
|
? new Date(data.addition_date * 1000).toLocaleString()
|
||||||
else
|
: "QBT_TR(Unknown)QBT_TR[CONTEXT=HttpServer]";
|
||||||
temp = "QBT_TR(Unknown)QBT_TR[CONTEXT=HttpServer]";
|
$('addition_date').set('html', additionDate);
|
||||||
$('addition_date').set('html', temp);
|
|
||||||
|
|
||||||
if (data.completion_date != -1)
|
const completionDate = (data.completion_date >= 0)
|
||||||
temp = new Date(data.completion_date * 1000).toLocaleString();
|
? new Date(data.completion_date * 1000).toLocaleString()
|
||||||
else
|
: "";
|
||||||
temp = "";
|
$('completion_date').set('html', completionDate);
|
||||||
$('completion_date').set('html', temp);
|
|
||||||
|
|
||||||
temp = (data.creation_date >= 0) ? (new Date(data.creation_date * 1000).toLocaleString()) : "";
|
const creationDate = (data.creation_date >= 0)
|
||||||
$('creation_date').set('html', temp);
|
? new Date(data.creation_date * 1000).toLocaleString()
|
||||||
|
: "";
|
||||||
|
$('creation_date').set('html', creationDate);
|
||||||
|
|
||||||
if (data.infohash_v1 === "")
|
const torrentHashV1 = (data.infohash_v1 !== "")
|
||||||
temp = "QBT_TR(N/A)QBT_TR[CONTEXT=PropertiesWidget]";
|
? data.infohash_v1
|
||||||
else
|
: "QBT_TR(N/A)QBT_TR[CONTEXT=PropertiesWidget]";
|
||||||
temp = data.infohash_v1;
|
$('torrent_hash_v1').set('html', torrentHashV1);
|
||||||
$('torrent_hash_v1').set('html', temp);
|
|
||||||
|
|
||||||
if (data.infohash_v2 === "")
|
const torrentHashV2 = (data.infohash_v2 !== "")
|
||||||
temp = "QBT_TR(N/A)QBT_TR[CONTEXT=PropertiesWidget]";
|
? data.infohash_v2
|
||||||
else
|
: "QBT_TR(N/A)QBT_TR[CONTEXT=PropertiesWidget]";
|
||||||
temp = data.infohash_v2;
|
$('torrent_hash_v2').set('html', torrentHashV2);
|
||||||
$('torrent_hash_v2').set('html', temp);
|
|
||||||
|
|
||||||
$('save_path').set('html', data.save_path);
|
$('save_path').set('html', data.save_path);
|
||||||
|
|
||||||
|
|
|
@ -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
|
// Behavior tab
|
||||||
const numberInputLimiter = (input) => {
|
const numberInputLimiter = (input) => {
|
||||||
const min = input.getAttribute("min");
|
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() {
|
$('networkInterface').addEvent('change', function() {
|
||||||
updateInterfaceAddresses($(this).getProperty('value'), '');
|
updateInterfaceAddresses($(this).getProperty('value'), '');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue