WebUI: prefer for loop over Array.forEach method

These were missed in 6ac0c5a8b8.
Also refactor the code a bit.

PR #23231.
This commit is contained in:
Chocobo1
2025-09-07 16:16:31 +08:00
committed by GitHub
parent 0a9316382a
commit 5c0010ac6c
2 changed files with 32 additions and 34 deletions

View File

@@ -16,34 +16,32 @@
(() => {
MochaUI.initializeTabs("aboutTabs");
const showContent = (element) => {
for (const content of document.querySelectorAll(".aboutTabContent")) {
if (content === element)
content.classList.remove("invisible");
else
content.classList.add("invisible");
}
};
document.getElementById("aboutAboutLink").addEventListener("click", (event) => {
Array.prototype.forEach.call(document.querySelectorAll(".aboutTabContent"), (tab => tab.classList.add("invisible")));
document.getElementById("aboutAboutContent").classList.remove("invisible");
showContent(document.getElementById("aboutAboutContent"));
});
document.getElementById("aboutAuthorLink").addEventListener("click", (event) => {
Array.prototype.forEach.call(document.querySelectorAll(".aboutTabContent"), (tab => tab.classList.add("invisible")));
document.getElementById("aboutAuthorContent").classList.remove("invisible");
showContent(document.getElementById("aboutAuthorContent"));
});
document.getElementById("aboutSpecialThanksLink").addEventListener("click", (event) => {
Array.prototype.forEach.call(document.querySelectorAll(".aboutTabContent"), (tab => tab.classList.add("invisible")));
document.getElementById("aboutSpecialThanksContent").classList.remove("invisible");
showContent(document.getElementById("aboutSpecialThanksContent"));
});
document.getElementById("aboutTranslatorsLink").addEventListener("click", (event) => {
Array.prototype.forEach.call(document.querySelectorAll(".aboutTabContent"), (tab => tab.classList.add("invisible")));
document.getElementById("aboutTranslatorsContent").classList.remove("invisible");
showContent(document.getElementById("aboutTranslatorsContent"));
});
document.getElementById("aboutLicenseLink").addEventListener("click", (event) => {
Array.prototype.forEach.call(document.querySelectorAll(".aboutTabContent"), (tab => tab.classList.add("invisible")));
document.getElementById("aboutLicenseContent").classList.remove("invisible");
showContent(document.getElementById("aboutLicenseContent"));
});
document.getElementById("aboutSoftwareUsedLink").addEventListener("click", (event) => {
Array.prototype.forEach.call(document.querySelectorAll(".aboutTabContent"), (tab => tab.classList.add("invisible")));
document.getElementById("aboutSoftwareUsedContent").classList.remove("invisible");
showContent(document.getElementById("aboutSoftwareUsedContent"));
});
})();
</script>

View File

@@ -33,40 +33,40 @@
"use strict";
(() => {
// Tabs
MochaUI.initializeTabs("preferencesTabs");
const showTab = (element) => {
for (const tab of document.querySelectorAll(".PrefTab")) {
if (tab === element)
tab.classList.remove("invisible");
else
tab.classList.add("invisible");
}
};
document.getElementById("PrefBehaviorLink").addEventListener("click", (e) => {
Array.prototype.forEach.call(document.querySelectorAll(".PrefTab"), (tab => tab.classList.add("invisible")));
document.getElementById("BehaviorTab").classList.remove("invisible");
showTab(document.getElementById("BehaviorTab"));
});
document.getElementById("PrefDownloadsLink").addEventListener("click", (e) => {
Array.prototype.forEach.call(document.querySelectorAll(".PrefTab"), (tab => tab.classList.add("invisible")));
document.getElementById("DownloadsTab").classList.remove("invisible");
showTab(document.getElementById("DownloadsTab"));
});
document.getElementById("PrefConnectionLink").addEventListener("click", (e) => {
Array.prototype.forEach.call(document.querySelectorAll(".PrefTab"), (tab => tab.classList.add("invisible")));
document.getElementById("ConnectionTab").classList.remove("invisible");
showTab(document.getElementById("ConnectionTab"));
});
document.getElementById("PrefSpeedLink").addEventListener("click", (e) => {
Array.prototype.forEach.call(document.querySelectorAll(".PrefTab"), (tab => tab.classList.add("invisible")));
document.getElementById("SpeedTab").classList.remove("invisible");
showTab(document.getElementById("SpeedTab"));
});
document.getElementById("PrefBittorrentLink").addEventListener("click", (e) => {
Array.prototype.forEach.call(document.querySelectorAll(".PrefTab"), (tab => tab.classList.add("invisible")));
document.getElementById("BittorrentTab").classList.remove("invisible");
showTab(document.getElementById("BittorrentTab"));
});
document.getElementById("PrefRSSLink").addEventListener("click", (e) => {
Array.prototype.forEach.call(document.querySelectorAll(".PrefTab"), (tab => tab.classList.add("invisible")));
document.getElementById("RSSTab").classList.remove("invisible");
showTab(document.getElementById("RSSTab"));
});
document.getElementById("PrefWebUILink").addEventListener("click", (e) => {
Array.prototype.forEach.call(document.querySelectorAll(".PrefTab"), (tab => tab.classList.add("invisible")));
document.getElementById("WebUITab").classList.remove("invisible");
showTab(document.getElementById("WebUITab"));
});
document.getElementById("PrefAdvancedLink").addEventListener("click", (e) => {
Array.prototype.forEach.call(document.querySelectorAll(".PrefTab"), (tab => tab.classList.add("invisible")));
document.getElementById("AdvancedTab").classList.remove("invisible");
showTab(document.getElementById("AdvancedTab"));
});
})();
</script>