Update scripts.js
Browse files- scripts.js +34 -65
scripts.js
CHANGED
@@ -1,85 +1,54 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
installUrl: "#",
|
6 |
-
iconUrl: "https://via.placeholder.com/50"
|
7 |
-
},
|
8 |
-
{
|
9 |
-
name: "App Two",
|
10 |
-
description: "This is the second app.",
|
11 |
-
installUrl: "#",
|
12 |
-
iconUrl: "https://via.placeholder.com/50"
|
13 |
-
},
|
14 |
-
{
|
15 |
-
name: "App Three",
|
16 |
-
description: "This is the third app.",
|
17 |
-
installUrl: "#",
|
18 |
-
iconUrl: "https://via.placeholder.com/50"
|
19 |
-
},
|
20 |
-
{
|
21 |
-
name: "App Four",
|
22 |
-
description: "This is the fourth app.",
|
23 |
-
installUrl: "#",
|
24 |
-
iconUrl: "https://via.placeholder.com/50"
|
25 |
-
}
|
26 |
-
];
|
27 |
|
28 |
-
function renderAppList() {
|
29 |
const listContainer = document.getElementById('app-list-container');
|
30 |
listContainer.innerHTML = '';
|
31 |
-
|
32 |
const item = document.createElement('div');
|
33 |
item.className = 'grid-item';
|
|
|
34 |
item.innerHTML = `
|
35 |
<img src="${app.iconUrl}" alt="${app.name}">
|
36 |
<h2>${app.name}</h2>
|
37 |
`;
|
38 |
-
item.addEventListener('click', () => showAppDetail(
|
39 |
listContainer.appendChild(item);
|
40 |
});
|
41 |
}
|
42 |
|
43 |
function renderAppDetail(app) {
|
44 |
-
const
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
detail.appendChild(description);
|
62 |
-
detail.appendChild(installButton);
|
63 |
-
|
64 |
-
return detail;
|
65 |
}
|
66 |
|
67 |
-
function
|
68 |
-
const
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
const appDetail = renderAppDetail(manifest[index]);
|
73 |
-
document.getElementById('app').appendChild(appDetail);
|
74 |
}
|
75 |
|
76 |
-
document.addEventListener('DOMContentLoaded', () => {
|
77 |
-
|
|
|
78 |
|
79 |
-
document.getElementById('browse-button').addEventListener('click',
|
80 |
-
const detailView = document.getElementById('app-detail');
|
81 |
-
if (detailView) {
|
82 |
-
detailView.remove();
|
83 |
-
}
|
84 |
-
});
|
85 |
});
|
|
|
1 |
+
async function fetchManifest() {
|
2 |
+
const response = await fetch('manifest.json');
|
3 |
+
return await response.json();
|
4 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
function renderAppList(apps) {
|
7 |
const listContainer = document.getElementById('app-list-container');
|
8 |
listContainer.innerHTML = '';
|
9 |
+
apps.forEach((app, index) => {
|
10 |
const item = document.createElement('div');
|
11 |
item.className = 'grid-item';
|
12 |
+
item.style.background = `linear-gradient(135deg, ${app.gradient[0]}, ${app.gradient[1]})`;
|
13 |
item.innerHTML = `
|
14 |
<img src="${app.iconUrl}" alt="${app.name}">
|
15 |
<h2>${app.name}</h2>
|
16 |
`;
|
17 |
+
item.addEventListener('click', () => showAppDetail(app));
|
18 |
listContainer.appendChild(item);
|
19 |
});
|
20 |
}
|
21 |
|
22 |
function renderAppDetail(app) {
|
23 |
+
const detailContainer = document.getElementById('app-detail-container');
|
24 |
+
detailContainer.innerHTML = `
|
25 |
+
<div class="detail-view">
|
26 |
+
<h2>${app.name}</h2>
|
27 |
+
<p>${app.description}</p>
|
28 |
+
${app.screenshots.map(src => `<img src="${src}" alt="${app.name} Screenshot">`).join('')}
|
29 |
+
<button onclick="backToList()">Back to List</button>
|
30 |
+
</div>
|
31 |
+
`;
|
32 |
+
}
|
33 |
+
|
34 |
+
function showAppDetail(app) {
|
35 |
+
const listContainer = document.getElementById('app-list-container');
|
36 |
+
const detailContainer = document.getElementById('app-detail-container');
|
37 |
+
listContainer.classList.add('hidden');
|
38 |
+
detailContainer.classList.remove('hidden');
|
39 |
+
renderAppDetail(app);
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
|
42 |
+
function backToList() {
|
43 |
+
const listContainer = document.getElementById('app-list-container');
|
44 |
+
const detailContainer = document.getElementById('app-detail-container');
|
45 |
+
listContainer.classList.remove('hidden');
|
46 |
+
detailContainer.classList.add('hidden');
|
|
|
|
|
47 |
}
|
48 |
|
49 |
+
document.addEventListener('DOMContentLoaded', async () => {
|
50 |
+
const apps = await fetchManifest();
|
51 |
+
renderAppList(apps);
|
52 |
|
53 |
+
document.getElementById('browse-button').addEventListener('click', backToList);
|
|
|
|
|
|
|
|
|
|
|
54 |
});
|