diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2025-03-27 18:24:46 -0600 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2025-03-27 18:24:46 -0600 |
commit | 4fcfb52f60f20cb091dcb4dbdf4a365fdea14651 (patch) | |
tree | 11cc0c9d1df7fd31ff12930cfb963f3f9fed1c56 /_includes/appstoreconnect.html | |
parent | 9eefba4a229a404eb1088db477a05e84b61e28b9 (diff) |
initial commit
Diffstat (limited to '_includes/appstoreconnect.html')
-rw-r--r-- | _includes/appstoreconnect.html | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/_includes/appstoreconnect.html b/_includes/appstoreconnect.html new file mode 100644 index 0000000..755caaf --- /dev/null +++ b/_includes/appstoreconnect.html @@ -0,0 +1,81 @@ +{% if site.ios_app_id %} +<script> +document.addEventListener("DOMContentLoaded", function () { + const iosAppId = "{{ site.ios_app_id }}"; + const iosAppCountry = "{{ site.ios_app_country }}"; + + if (iosAppId) { + const apiURL = `https://itunes.apple.com/lookup?id=${iosAppId}&country=${iosAppCountry}&callback=?`; + + fetch(apiURL.replace("&callback=?", "")) + .then(response => response.json()) + .then(json => { + if (json.results && json.results.length) { + console.info("Image strings loaded from Apple API."); + const appInfo = json.results[0]; + + const favicon = document.querySelector('link[rel="shortcut icon"]'); + if (favicon) favicon.href = appInfo.artworkUrl512; + + // // Set page title + const pageTitle = document.querySelector(".pageTitle"); + if (pageTitle && pageTitle.textContent.trim().length === 0) { + pageTitle.textContent = appInfo.trackName; + } + + // Set large app icon + const appIconLarge = document.getElementById("largeIcon"); + if (appIconLarge && (!appIconLarge.getAttribute("src") || + appIconLarge.getAttribute("src") === "{{ '/assets/placeholder-icon.png' | relative_url }}")) { + appIconLarge.setAttribute("src", appInfo.artworkUrl512); + } + + // Set header app icon + const appIconHeader = document.getElementById("headerIcon"); + if (appIconHeader && (!appIconHeader.getAttribute("src") || + appIconHeader.getAttribute("src") === "{{ '/assets/placeholder-icon.png' | relative_url }}")) { + appIconHeader.setAttribute("src", appInfo.artworkUrl512); + console.log(appInfo.artworkUrl512); + } + + // Set app name + const appName = document.getElementById("appName"); + if (appName) { + if (appName.textContent.trim().length === 0 || appName.textContent.trim() === "Your App Name") { + appName.textContent = appInfo.trackName; + } + } + + // Set header name + const headerName = document.getElementById("headerName"); + if ((headerName.textContent.trim().length === 0) || headerName.textContent.trim() === "Your App Name") { + headerName.textContent = appInfo.trackName; + } + + // Set price + const appPrice = document.getElementById("appPrice"); + if (appPrice && appPrice.textContent.trim().length === 0) { + appPrice.textContent = appInfo.formattedPrice; + } + + // Set App Store link + const appStoreLink = document.getElementById("appStoreLink"); + if (appStoreLink && appStoreLink.getAttribute("href").trim().length === 0) { + appStoreLink.setAttribute("href", appInfo.trackViewUrl); + } + + // Set App Description + const appDescription = document.getElementById("appDescription"); + if (appDescription && appDescription.textContent.trim().length === 0) { + appDescription.textContent = appInfo.description; + } + + console.info(appInfo); + } + }) + .catch(error => console.error("Error fetching App Store info:", error)); + } +}); +</script> + +{% endif %} |