forked from MapComplete/MapComplete
Fix: fix #1813. For some reason, importing a .js-file suddenly fails, so ported it to typescript
This commit is contained in:
parent
c70ab96427
commit
cab414e808
3 changed files with 33 additions and 32 deletions
|
@ -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"))
|
|
32
src/UI/RemoveOtherLanguages.ts
Normal file
32
src/UI/RemoveOtherLanguages.ts
Normal file
|
@ -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"))
|
|
@ -73,7 +73,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div aria-hidden="true" id="belowmap" class="absolute top-0 left-0 -z-10">Below</div>
|
<div aria-hidden="true" id="belowmap" class="absolute top-0 left-0 -z-10">Below</div>
|
||||||
<script src="./src/UI/RemoveOtherLanguages.js"></script>
|
<script src="./src/UI/RemoveOtherLanguages.ts" type="module"></script>
|
||||||
<script async src="./src/InstallServiceWorker.ts" type="module"></script>
|
<script async src="./src/InstallServiceWorker.ts" type="module"></script>
|
||||||
<script defer src="./src/index.ts" type="module"></script>
|
<script defer src="./src/index.ts" type="module"></script>
|
||||||
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="https://gc.zgo.at/count.js" crossorigin="anonymous" integrity="sha384-nx5O+otcqJoqMhdDt8jUzmia6ng81Z5zZozYr69TzPkOLjVhLKMxu5zHCV9/0MPn"></script>
|
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="https://gc.zgo.at/count.js" crossorigin="anonymous" integrity="sha384-nx5O+otcqJoqMhdDt8jUzmia6ng81Z5zZozYr69TzPkOLjVhLKMxu5zHCV9/0MPn"></script>
|
||||||
|
|
Loading…
Reference in a new issue