File size: 2,796 Bytes
e0449c8
 
 
 
 
 
899d1e1
 
 
 
 
f88e88a
899d1e1
 
 
165859f
899d1e1
 
165859f
 
 
 
 
 
 
 
 
 
 
f88e88a
1d818b8
899d1e1
e0449c8
899d1e1
0afeddc
899d1e1
e0449c8
 
 
 
899d1e1
 
 
 
 
 
e0449c8
899d1e1
e0449c8
 
 
 
 
 
 
 
 
 
 
 
 
 
899d1e1
 
 
0bcdffe
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
// Ganti domain kamu di sini:
const baseURL = "https://gilbertclaus.pythonanywhere.com";

function playVideo(button) {
  const charName = button.textContent.trim();
  const videoPath = `${baseURL}/video/${encodeURIComponent("Ark ReCode")}/${encodeURIComponent(charName)}.mp4`;

    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.volume = 0.01;
    video.style.marginTop = "20px";
    wrapper.appendChild(video);
    
    // Minta fullscreen setelah video ditambahkan ke halaman
    video.addEventListener("loadedmetadata", () => {
      if (video.requestFullscreen) {
        video.requestFullscreen();
      } else if (video.webkitRequestFullscreen) { // Safari
        video.webkitRequestFullscreen();
      } else if (video.msRequestFullscreen) { // IE11
        video.msRequestFullscreen();
      }
    });
}

function fetchData() {
    // Ambil elemen tombol karakter
    const input = document.getElementById("charName").value.trim();
    const charaBtns = document.querySelectorAll(".chara");

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

    if (input === "") {
        // Ambil status tombol pertama sebagai acuan
        const isHidden = charaBtns[0].style.display === "none" || charaBtns[0].style.display === "";

        // Toggle semua tombol
        charaBtns.forEach(btn => {
            btn.style.display = isHidden ? "inline-block" : "none";
        });

        // Cek apakah sedang bukan video Edalia
        const isSafe = !source.src.includes("Edalia");

        // Pilih URL video berdasarkan status tombol
        const newVideoURL = isSafe
            ? `${baseURL}/video/${encodeURIComponent("Edalia Skill")}.mp4`
            : `https://video.twimg.com/ext_tw_video/1892164405464629249/pu/vid/avc1/1280x720/cgW9XdNOX1DPI6Rq.mp4`;

        // Set dan muat ulang video
        source.src = newVideoURL;
        video.load();
        video.play();

    } else {
        const name = document.getElementById("charName").value;
        alert(`Fungsi fetchData untuk karakter "${name}" belum diimplementasikan`);
    }
}

// Ambil daftar karakter dari server
window.onload = () => {
  fetch(`${baseURL}/list-videos`)
    .then(res => res.json())
    .then(data => {
      const container = document.getElementById("charButtons");
      data.videos.forEach(name => {
        const btn = document.createElement("button");
        btn.textContent = name;
        btn.className = "chara";
        btn.onclick = () => playVideo(name);
        container.appendChild(btn);
      });
    });
};