Skip to content

Commit

Permalink
fix: move javascript to index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
yokoberek authored May 6, 2024
1 parent 2af37ad commit 58df32a
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,46 @@
<h1>Daftar Cerita Mop</h1>
<div id="stories-container"></div>

<script src="script.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
const storiesContainer = document.getElementById("stories-container");

// Ambil data cerita dari URL
fetch("https://raw.githubusercontent.com/papua-opensource/mops/master/data.json")
.then(response => response.json())
.then(data => {
// Tampilkan cerita dalam HTML
data.stories.forEach(story => {
const storyElement = document.createElement("div");
storyElement.classList.add("story");

const titleElement = document.createElement("h2");
titleElement.textContent = story.title;
storyElement.appendChild(titleElement);

const descriptionElement = document.createElement("p");
descriptionElement.textContent = story.description;
storyElement.appendChild(descriptionElement);

const scenesElement = document.createElement("ul");
story.scenes.forEach(scene => {
const sceneElement = document.createElement("li");
if (scene.type === "description") {
sceneElement.textContent = scene.content;
} else if (scene.type === "dialogue") {
sceneElement.textContent = `${scene.speaker}: ${scene.message}`;
}
scenesElement.appendChild(sceneElement);
});
storyElement.appendChild(scenesElement);

storiesContainer.appendChild(storyElement);
});
})
.catch(error => {
console.error("Error fetching stories:", error);
});
});
</script>
</body>
</html>

0 comments on commit 58df32a

Please sign in to comment.