Updated remote access and flag JS

This commit is contained in:
John Crisp
2025-06-11 11:58:16 +02:00
parent 22fbb582d2
commit eb05438d80
2 changed files with 52 additions and 39 deletions

View File

@@ -208,7 +208,7 @@ document.addEventListener('DOMContentLoaded', () => {
//if (!response.ok) throw new Error('Country not found');
//const data = await response.json();
//// Return the name in the native language
//return data[0].name.common;
//return data[0].name.common;
//} catch (error) {
//console.error(error);
//return 'Unknown Country';
@@ -222,7 +222,7 @@ document.addEventListener('DOMContentLoaded', () => {
function getCountryCodeFromLanguage(language) {
return languageToCountryMap[language] ? languageToCountryMap[language].code : null;
}
function getCountryNameFromCountryCode(countryCode) {
//alert(`Country code: ${countryCode}`);
for (const language in languageToCountryMap) {
@@ -263,11 +263,15 @@ document.addEventListener('DOMContentLoaded', () => {
function displayLocaleAndFlag() {
// Get the browser locale
const userLocale = navigator.language || navigator.userLanguage;
const userLocale = navigator.languages && navigator.languages.length
? navigator.languages[0]
: navigator.language;
//alert(`User Locale: ${userLocale}`); // Alert the detected locale
//console.log(navigator.languages); // Log language to console
const { flag, isUnknown, countryCode } = getFlagEmoji(userLocale);
//alert(`Country Code: ${countryCode}, Is Unknown: ${isUnknown}`); // Debug country code and unknown flag status
// Display the locale and the corresponding flag (or fallback)
@@ -278,7 +282,7 @@ function displayLocaleAndFlag() {
fallbackDiv.className = 'fallback-box';
fallbackDiv.textContent = `? ${userLocale.toUpperCase()}`; // Show ? and locale code inside the box
document.getElementById('flag-container').appendChild(fallbackDiv);
// Tooltip for fallback
fallbackDiv.title = "Unknown Country"; // Tooltip for fallback
//alert('Fallback triggered: Unknown Country'); // Debug fallback
@@ -290,7 +294,7 @@ function displayLocaleAndFlag() {
flagSpan.textContent = flag; // Use flag emoji
flagSpan.title = countryName; // Tooltip for the flag in country language
document.getElementById('flag-container').appendChild(flagSpan);
//alert(`Flag Emoji: ${flag}`); // Debug flag emoji display
}
}