blob: 755caaf21ef0ee3db0595ead2d2d0554a2d76362 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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 %}
|