From 1aaf730c4bffee8e0ca49204ddfc90f84c4f8a24 Mon Sep 17 00:00:00 2001 From: Andrii Lundiak Date: Mon, 21 Oct 2024 23:15:08 +0200 Subject: [PATCH] v1.8.1 --- flags.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/flags.js b/flags.js index 497a787..0dc9ed0 100644 --- a/flags.js +++ b/flags.js @@ -51,9 +51,18 @@ function createFlagButtons(flagsData) { } function copyToClipboard(codeObject) { - navigator.clipboard.writeText(codeObject.flag).then(() => { + // vA + // const flagEmoji = codeObject.flag; + // const countryName = codeObject.name; + + // vB + const keys = Object.keys(codeObject); + const flagEmoji = keys[0]; + const countryName = codeObject[flagEmoji]; + + navigator.clipboard.writeText(flagEmoji).then(() => { // console.log(`Copied: ${flagEmoji}`); - showToast(`Copied: ${codeObject.flag} ${codeObject.name}`); + showToast(`Copied: ${flagEmoji} ${countryName}`); }).catch(err => { console.error('Failed to copy: ', err); }); @@ -74,6 +83,7 @@ function showToast(message) { } getCountryFlags().then(flagsFromApi => { + console.log(flagsFromApi); // console.log(JSON.stringify(flagsFromApi)); createFlagButtons(flagsFromApi); });