GilbertClaus commited on
Commit
729a778
·
1 Parent(s): 6b68bae
Files changed (1) hide show
  1. ArkReCode/script.js +63 -74
ArkReCode/script.js CHANGED
@@ -1,33 +1,34 @@
1
- // Ganti domain kamu di sini:
2
- const baseURL = "https://gilbertclaus.pythonanywhere.com";
3
 
4
  function playVideo(button) {
5
  const charName = button.textContent.trim();
6
- const videoPath = `${baseURL}/video/${encodeURIComponent("Ark ReCode")}/${encodeURIComponent(charName)}.mp4`;
7
-
8
- const wrapper = document.getElementById("videoWrapper");
9
- wrapper.innerHTML = "";
10
-
11
- const video = document.createElement("video");
12
- video.src = videoPath;
13
- video.width = 360;
14
- video.controls = true;
15
- video.autoplay = true
16
- video.loop = true;
17
- video.volume = 0.01;
18
- video.style.marginTop = "20px";
19
- wrapper.appendChild(video);
20
-
21
- // Minta fullscreen setelah video ditambahkan ke halaman
22
- // video.addEventListener("loadedmetadata", () => {
23
- if (video.requestFullscreen) {
24
- video.requestFullscreen();
25
- } else if (video.webkitRequestFullscreen) { // Safari
26
- video.webkitRequestFullscreen();
27
- } else if (video.msRequestFullscreen) { // IE11
28
- video.msRequestFullscreen();
29
- }
30
- // });
 
 
31
  }
32
 
33
  function showNotif(message, duration = 3000) {
@@ -36,66 +37,54 @@ function showNotif(message, duration = 3000) {
36
  notif.textContent = message;
37
 
38
  document.body.appendChild(notif);
 
39
 
40
- // Trigger fade-in
41
- requestAnimationFrame(() => {
42
- notif.style.opacity = 1;
43
- });
44
-
45
- // Auto-hide
46
  setTimeout(() => {
47
- notif.style.opacity = 0;
48
- setTimeout(() => {
49
- notif.remove();
50
- }, 500); // Tunggu animasi selesai
51
  }, duration);
52
  }
53
 
54
  function fetchData() {
55
- // Ambil elemen tombol karakter
56
- const input = document.getElementById("charName").value.trim();
57
- const charaBtns = document.querySelectorAll(".chara");
58
-
59
- // Ambil elemen video
60
- const video = document.getElementById("bgVideo");
61
- const source = video.querySelector("source");
62
-
63
- if (input === "") {
64
- // Ambil status tombol pertama sebagai acuan
65
- const isHidden = charaBtns[0].style.display === "none" || charaBtns[0].style.display === "";
66
-
67
- // Toggle semua tombol
68
- charaBtns.forEach(btn => {
69
- btn.style.display = isHidden ? "inline-block" : "none";
70
- });
71
-
72
- // Cek apakah sedang bukan video Edalia
73
- const isSafe = !source.src.includes("Edalia");
74
-
75
- // Pilih URL video berdasarkan status tombol
76
- const newVideoURL = isSafe
77
- ? `${baseURL}/video/${encodeURIComponent("Ark ReCode - Edalia Skill")}.mp4`
78
- : `https://video.twimg.com/ext_tw_video/1892164405464629249/pu/vid/avc1/1280x720/cgW9XdNOX1DPI6Rq.mp4`;
79
-
80
- // Set dan muat ulang video
81
- source.src = newVideoURL;
82
- video.load();
83
- video.play();
84
-
85
- } else {
86
- showNotif(`Fungsi fetchData untuk karakter "${input}" belum diimplementasikan`);
87
- }
88
  }
89
 
90
- // Ambil daftar karakter dari server
91
  window.onload = () => {
92
- fetch(`${baseURL}/list-videos-ark-recode`)
93
  .then(res => res.json())
94
  .then(data => {
95
  const container = document.getElementById("charButtons");
96
 
97
- // Urutkan nama-nama video secara alfabet
98
- const sortedNames = data.videos.sort((a, b) => a.localeCompare(b));
 
 
 
 
 
99
 
100
  sortedNames.forEach(name => {
101
  const btn = document.createElement("button");
 
1
+ const videoMap = {}; // name => url
 
2
 
3
  function playVideo(button) {
4
  const charName = button.textContent.trim();
5
+ const videoPath = videoMap[charName]; // Ambil dari map
6
+
7
+ if (!videoPath) {
8
+ showNotif(`Video untuk "${charName}" tidak ditemukan`);
9
+ return;
10
+ }
11
+
12
+ const wrapper = document.getElementById("videoWrapper");
13
+ wrapper.innerHTML = "";
14
+
15
+ const video = document.createElement("video");
16
+ video.src = videoPath;
17
+ video.width = 360;
18
+ video.controls = true;
19
+ video.autoplay = true;
20
+ video.loop = true;
21
+ video.volume = 0.01;
22
+ video.style.marginTop = "20px";
23
+ wrapper.appendChild(video);
24
+
25
+ if (video.requestFullscreen) {
26
+ video.requestFullscreen();
27
+ } else if (video.webkitRequestFullscreen) {
28
+ video.webkitRequestFullscreen();
29
+ } else if (video.msRequestFullscreen) {
30
+ video.msRequestFullscreen();
31
+ }
32
  }
33
 
34
  function showNotif(message, duration = 3000) {
 
37
  notif.textContent = message;
38
 
39
  document.body.appendChild(notif);
40
+ requestAnimationFrame(() => notif.style.opacity = 1);
41
 
 
 
 
 
 
 
42
  setTimeout(() => {
43
+ notif.style.opacity = 0;
44
+ setTimeout(() => notif.remove(), 500);
 
 
45
  }, duration);
46
  }
47
 
48
  function fetchData() {
49
+ const input = document.getElementById("charName").value.trim();
50
+ const charaBtns = document.querySelectorAll(".chara");
51
+
52
+ const video = document.getElementById("bgVideo");
53
+ const source = video.querySelector("source");
54
+
55
+ if (input === "") {
56
+ const isHidden = charaBtns[0].style.display === "none" || charaBtns[0].style.display === "";
57
+ charaBtns.forEach(btn => {
58
+ btn.style.display = isHidden ? "inline-block" : "none";
59
+ });
60
+
61
+ const isSafe = !source.src.includes("Edalia");
62
+ const newVideoURL = isSafe
63
+ ? videoMap["Edalia"]
64
+ : "https://video.twimg.com/ext_tw_video/1892164405464629249/pu/vid/avc1/1280x720/cgW9XdNOX1DPI6Rq.mp4";
65
+
66
+ source.src = newVideoURL;
67
+ video.load();
68
+ video.play();
69
+ } else {
70
+ showNotif(`Fungsi fetchData untuk karakter "${input}" belum diimplementasikan`);
71
+ }
 
 
 
 
 
 
 
 
 
 
72
  }
73
 
74
+ // Ambil daftar karakter dan URL dari server
75
  window.onload = () => {
76
+ fetch("https://gilbertclaus.pythonanywhere.com/list-videos-ark-recode")
77
  .then(res => res.json())
78
  .then(data => {
79
  const container = document.getElementById("charButtons");
80
 
81
+ // Simpan ke videoMap
82
+ Object.entries(data).forEach(([name, url]) => {
83
+ videoMap[name] = url;
84
+ });
85
+
86
+ // Urutkan nama-nama berdasarkan key
87
+ const sortedNames = Object.keys(videoMap).sort((a, b) => a.localeCompare(b));
88
 
89
  sortedNames.forEach(name => {
90
  const btn = document.createElement("button");