Spaces:
Running
Running
Commit ·
729a778
1
Parent(s): 6b68bae
Dict
Browse files- ArkReCode/script.js +63 -74
ArkReCode/script.js
CHANGED
|
@@ -1,33 +1,34 @@
|
|
| 1 |
-
|
| 2 |
-
const baseURL = "https://gilbertclaus.pythonanywhere.com";
|
| 3 |
|
| 4 |
function playVideo(button) {
|
| 5 |
const charName = button.textContent.trim();
|
| 6 |
-
const videoPath =
|
| 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 |
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 |
-
|
| 48 |
-
|
| 49 |
-
notif.remove();
|
| 50 |
-
}, 500); // Tunggu animasi selesai
|
| 51 |
}, duration);
|
| 52 |
}
|
| 53 |
|
| 54 |
function fetchData() {
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 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(
|
| 93 |
.then(res => res.json())
|
| 94 |
.then(data => {
|
| 95 |
const container = document.getElementById("charButtons");
|
| 96 |
|
| 97 |
-
//
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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");
|