-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (63 loc) · 2.65 KB
/
script.js
File metadata and controls
76 lines (63 loc) · 2.65 KB
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
// أضف روابط الفيديوهات من ImageKit هنا
const videos = [
{ file: "https://ik.imagekit.io/xgs3yjnd5videoDHXTR2/Jujutsu?updatedAt=1771240427739" },
// مثال: { file: "https://ik.imagekit.io/your_account_id/video2.mp4" },
];
const container = document.getElementById("videos");
videos.forEach(v => {
let urlParts = v.file.split("/");
let title = urlParts[urlParts.length - 1].split("?")[0];
title = title.replace(/_/g, " ").replace(/\.mp4/, "");
const id = title.replace(/\s/g, "-");
// اللايك والديسلايك
const likes = localStorage.getItem(id + "_likes") || 0;
const dislikes = localStorage.getItem(id + "_dislikes") || 0;
const userVoted = localStorage.getItem(id + "_voted") || null;
// التعليقات المخزنة
const savedComments = JSON.parse(localStorage.getItem(id + "_comments") || "[]");
container.innerHTML += `
<div class="card">
<h3>${title}</h3>
<video src="${v.file}" controls></video>
<div class="actions">
<button id="like-${id}" ${userVoted ? "disabled" : ""} onclick="vote('${id}','likes')">
👍 <span id="l-${id}">${likes}</span>
</button>
<button id="dislike-${id}" ${userVoted ? "disabled" : ""} onclick="vote('${id}','dislikes')">
👎 <span id="d-${id}">${dislikes}</span>
</button>
</div>
<div class="comments">
<input type="text" id="input-${id}" placeholder="اكتب تعليق...">
<button onclick="addComment('${id}')">💬 إضافة</button>
<div class="comment-list" id="list-${id}">
${savedComments.map(c => `<div class="comment-item">${c}</div>`).join("")}
</div>
</div>
</div>
`;
});
function vote(id, type) {
if(localStorage.getItem(id + "_voted")) return;
let count = localStorage.getItem(id + "_" + type) || 0;
count++;
localStorage.setItem(id + "_" + type, count);
localStorage.setItem(id + "_voted", type);
document.getElementById("like-" + id).disabled = true;
document.getElementById("dislike-" + id).disabled = true;
document.getElementById((type === "likes" ? "l-" : "d-") + id).innerText = count;
}
function addComment(id) {
const input = document.getElementById("input-" + id);
const text = input.value.trim();
if(!text) return;
const savedComments = JSON.parse(localStorage.getItem(id + "_comments") || "[]");
savedComments.push(text);
localStorage.setItem(id + "_comments", JSON.stringify(savedComments));
const list = document.getElementById("list-" + id);
const div = document.createElement("div");
div.className = "comment-item";
div.innerText = text;
list.appendChild(div);
input.value = "";
}