Conditionally hide settings in Advanced Options

This commit is contained in:
Chocobo1
2024-02-04 13:32:33 +08:00
parent 5fe5c333b5
commit 9b64d50660
6 changed files with 129 additions and 64 deletions

View File

@@ -40,6 +40,7 @@ window.qBittorrent.Misc = (function() {
friendlyPercentage: friendlyPercentage,
friendlyFloat: friendlyFloat,
parseHtmlLinks: parseHtmlLinks,
parseVersion: parseVersion,
escapeHtml: escapeHtml,
naturalSortCollator: naturalSortCollator,
safeTrim: safeTrim,
@@ -171,6 +172,29 @@ window.qBittorrent.Misc = (function() {
return text.replace(exp, "<a target='_blank' rel='noopener noreferrer' href='$1'>$1</a>");
};
const parseVersion = function(versionString) {
const failure = {
valid: false
};
if (typeof versionString !== 'string')
return failure;
const tryToNumber = (str) => {
const num = Number(str);
return (isNaN(num) ? str : num);
};
const ver = versionString.split('.', 4).map(val => tryToNumber(val));
return {
valid: true,
major: ver[0],
minor: ver[1],
fix: ver[2],
patch: ver[3]
};
};
const escapeHtml = function(str) {
const div = document.createElement('div');
div.appendChild(document.createTextNode(str));