-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
60 lines (50 loc) · 2.14 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homework List</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1 class="title">My HTML Homeworks</h1>
<button class="add-btn" onclick="openFormPage()">Add Homework</button>
<div class="product-container" id="product-container">
</div>
<script>
const apiUrl = "https://673f23ffa9bc276ec4b75913.mockapi.io/site/v1/Sites"
const ghFile = 'https://raw.githubusercontent.com/sargisx/Projects/master'
const ghPage = 'https://sargisx.github.io/Projects'
function openFormPage() {
window.location.href = "form.html"
}
async function loadHomework() {
const container = document.getElementById("product-container")
try {
const response = await fetch(apiUrl)
const homeworkData = await response.json()
homeworkData.forEach(homework => {
const { img, title, description, id } = homework
const newCard = document.createElement("a")
newCard.classList.add("product-card")
newCard.href = `${ghPage}/Homeworks/ahhhhh${id}/index.html`
const imgElement = document.createElement("img")
imgElement.src = `${ghFile}/${img}`
imgElement.alt = title
newCard.appendChild(imgElement)
const titleElement = document.createElement("h3")
titleElement.textContent = title
newCard.appendChild(titleElement)
const descriptionElement = document.createElement("p")
descriptionElement.textContent = description
newCard.appendChild(descriptionElement)
container.appendChild(newCard)
})
} catch (error) {
console.error("Error fetching data from MockAPI:", error)
}
}
window.onload = loadHomework
</script>
</body>
</html>