From cab414e80895933b4ae874be5fd77b90b8c13f3f Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 7 Mar 2024 17:16:39 +0100 Subject: [PATCH] Fix: fix #1813. For some reason, importing a .js-file suddenly fails, so ported it to typescript --- src/UI/RemoveOtherLanguages.js | 31 ------------------------------- src/UI/RemoveOtherLanguages.ts | 32 ++++++++++++++++++++++++++++++++ theme.html | 2 +- 3 files changed, 33 insertions(+), 32 deletions(-) delete mode 100644 src/UI/RemoveOtherLanguages.js create mode 100644 src/UI/RemoveOtherLanguages.ts diff --git a/src/UI/RemoveOtherLanguages.js b/src/UI/RemoveOtherLanguages.js deleted file mode 100644 index 7486047ca..000000000 --- a/src/UI/RemoveOtherLanguages.js +++ /dev/null @@ -1,31 +0,0 @@ -let lang = ( - (navigator.languages && navigator.languages[0]) || - navigator.language || - navigator["userLanguage"] || - "en" -).substr(0, 2) - -function filterLangs(maindiv) { - let foundLangs = 0 - for (const child of Array.from(maindiv.children)) { - if (child.attributes.getNamedItem("lang")?.value === lang) { - foundLangs++ - } - } - if (foundLangs === 0) { - lang = "en" - } - for (const child of Array.from(maindiv.children)) { - const childLang = child.attributes.getNamedItem("lang") - if (childLang === undefined) { - continue - } - if (childLang.value === lang) { - continue - } - child.parentElement.removeChild(child) - } -} - -filterLangs(document.getElementById("descriptions-while-loading")) -filterLangs(document.getElementById("default-title")) diff --git a/src/UI/RemoveOtherLanguages.ts b/src/UI/RemoveOtherLanguages.ts new file mode 100644 index 000000000..207a64098 --- /dev/null +++ b/src/UI/RemoveOtherLanguages.ts @@ -0,0 +1,32 @@ +export {} +let lang = ( + (navigator.languages && navigator.languages[0]) || + navigator.language || + navigator["userLanguage"] || + "en" +).substr(0, 2) + +function filterLangs(maindiv) { + let foundLangs = 0 + for (const child of Array.from(maindiv.children)) { + if (child.attributes.getNamedItem("lang")?.value === lang) { + foundLangs++ + } + } + if (foundLangs === 0) { + lang = "en" + } + for (const child of Array.from(maindiv.children)) { + const childLang = child.attributes.getNamedItem("lang") + if (childLang === undefined) { + continue + } + if (childLang.value === lang) { + continue + } + child.parentElement.removeChild(child) + } +} + +filterLangs(document.getElementById("descriptions-while-loading")) +filterLangs(document.getElementById("default-title")) diff --git a/theme.html b/theme.html index e8674e27e..239c52c56 100644 --- a/theme.html +++ b/theme.html @@ -73,7 +73,7 @@ - +