File size: 2,955 Bytes
729a778
e0449c8
 
 
729a778
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f88e88a
1d818b8
cba261e
 
 
 
 
 
729a778
cba261e
 
729a778
 
cba261e
 
 
899d1e1
729a778
 
 
 
 
 
 
 
 
 
 
 
 
 
d6652a2
729a778
 
 
 
 
 
 
 
e0449c8
 
729a778
e0449c8
729a778
e0449c8
 
 
cba261e
729a778
 
 
 
 
 
 
cba261e
 
e0449c8
 
 
cba261e
 
 
e0449c8
 
cba261e
 
 
e0449c8
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const videoMap = {}; // name => url

function playVideo(button) {
  const charName = button.textContent.trim();
  const videoPath = videoMap[charName]; // Ambil dari map

  if (!videoPath) {
    showNotif(`Video untuk "${charName}" tidak ditemukan`);
    return;
  }

  const wrapper = document.getElementById("videoWrapper");
  wrapper.innerHTML = "";

  const video = document.createElement("video");
  video.src = videoPath;
  video.width = 360;
  video.controls = true;
  video.autoplay = true;
  video.loop = true;
  video.volume = 0.01;
  video.style.marginTop = "20px";
  wrapper.appendChild(video);

  if (video.requestFullscreen) {
    video.requestFullscreen();
  } else if (video.webkitRequestFullscreen) {
    video.webkitRequestFullscreen();
  } else if (video.msRequestFullscreen) {
    video.msRequestFullscreen();
  }
}

function showNotif(message, duration = 3000) {
  const notif = document.createElement("div");
  notif.className = "notif";
  notif.textContent = message;

  document.body.appendChild(notif);
  requestAnimationFrame(() => notif.style.opacity = 1);

  setTimeout(() => {
    notif.style.opacity = 0;
    setTimeout(() => notif.remove(), 500);
  }, duration);
}

function fetchData() {
  const input = document.getElementById("charName").value.trim();
  const charaBtns = document.querySelectorAll(".chara");

  const video = document.getElementById("bgVideo");
  const source = video.querySelector("source");

  if (input === "") {
    const isHidden = charaBtns[0].style.display === "none" || charaBtns[0].style.display === "";
    charaBtns.forEach(btn => {
      btn.style.display = isHidden ? "inline-block" : "none";
    });

    const isSafe = !source.src.includes("Edalia");
    const newVideoURL = isSafe
      ? videoMap["Ark ReCode - Edalia Skill"]
      : "https://video.twimg.com/ext_tw_video/1892164405464629249/pu/vid/avc1/1280x720/cgW9XdNOX1DPI6Rq.mp4";

    source.src = newVideoURL;
    video.load();
    video.play();
  } else {
    showNotif(`Fungsi fetchData untuk karakter "${input}" belum diimplementasikan`);
  }
}

// Ambil daftar karakter dan URL dari server
window.onload = () => {
  fetch("https://gilbertclaus.pythonanywhere.com/list-videos-ark-recode")
    .then(res => res.json())
    .then(data => {
      const container = document.getElementById("charButtons");

      // Simpan ke videoMap
      Object.entries(data).forEach(([name, url]) => {
        videoMap[name] = url;
      });

      // Urutkan nama-nama berdasarkan key
      const sortedNames = Object.keys(videoMap).sort((a, b) => a.localeCompare(b));

      sortedNames.forEach(name => {
        const btn = document.createElement("button");
        btn.textContent = name;
        btn.className = "chara";
        btn.onclick = function () {
          playVideo(this);
        };
        container.appendChild(btn);
      });
    })
    .catch(err => {
      showNotif("Gagal ambil daftar karakter dari server");
    });
};