-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
256 lines (216 loc) · 10.5 KB
/
script.js
File metadata and controls
256 lines (216 loc) · 10.5 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
const USER = 'DrapBS';
const REPO = 'DrapPlugins';
const FOLDER = 'plugins';
// Show download notification
function showDownloadNotification(filename) {
const notification = document.getElementById('download-notification');
const notificationText = notification.querySelector('.notification-text');
notificationText.textContent = `Downloading ${filename}...`;
notification.classList.add('show');
// Hide after 3 seconds
setTimeout(() => {
notification.classList.remove('show');
notification.classList.add('hide');
setTimeout(() => {
notification.classList.remove('hide');
}, 500);
}, 3000);
}
// Download file from GitHub
async function downloadFile(url, filename) {
try {
showDownloadNotification(filename);
const response = await fetch(url);
const blob = await response.blob();
// Create download link
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// Clean up
window.URL.revokeObjectURL(link.href);
} catch (error) {
console.error('خطأ في التحميل:', error);
alert('حدث خطأ في تحميل الملف. حاول مرة أخرى.');
}
}
// Load mods from GitHub
async function loadMods() {
const container = document.getElementById('mods-container');
try {
const res = await fetch(`https://api.github.com/repos/${USER}/${REPO}/contents/${FOLDER}`);
const files = await res.json();
// Clear loading spinner
container.innerHTML = '';
if (!Array.isArray(files) || files.length === 0) {
container.innerHTML = '<p style="text-align: center; color: #94a3b8;">لا توجد مودات حالياً.</p>';
return;
}
for (let file of files) {
if (file.name.endsWith('.py')) {
const fileRes = await fetch(file.download_url);
const text = await fileRes.text();
const match = text.match(/drpmod\s*\{([\s\S]*?)\}/);
if (match) {
const dataRaw = match[1].replace(/'/g, '"');
try {
const data = JSON.parse('{' + dataRaw + '}');
// Prepare image
let imgHtml = data.Picture !== "None"
? `<img src="${data.Picture}" alt="${data.Name}">`
: `<div class="no-img">💣</div>`;
// Prepare video
let vidHtml = data.Video !== "None"
? `<video controls src="${data.Video}"></video>`
: '';
// Create card
const card = document.createElement('div');
card.className = 'mod-card';
card.innerHTML = `
<div class="card-header">
${imgHtml}
<h3>${data.Name}</h3>
</div>
<div class="card-details">
<p>${data.Description}</p>
${vidHtml}
<a href="#" class="dl-btn" data-url="${file.download_url}" data-filename="${file.name}">
📥 تحميل المود
</a>
<span class="version">الإصدار: ${data.Version}</span>
</div>
`;
// Toggle card details on click
card.addEventListener('click', (e) => {
// Don't toggle if clicking download button or video
if (e.target.closest('.dl-btn') || e.target.tagName === 'VIDEO') {
return;
}
card.classList.toggle('active');
});
// Handle download button click
const downloadBtn = card.querySelector('.dl-btn');
downloadBtn.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
const url = e.currentTarget.dataset.url;
const filename = e.currentTarget.dataset.filename;
downloadFile(url, filename);
});
container.appendChild(card);
} catch(e) {
console.log("خطأ في قراءة بيانات: " + file.name, e);
}
}
}
}
if(container.children.length === 0) {
container.innerHTML = '<p style="text-align: center; color: #94a3b8;">لا توجد مودات متاحة حالياً.</p>';
}
} catch (e) {
console.error('خطأ في تحميل المودات:', e);
container.innerHTML = `
<div style="text-align: center; padding: 40px;">
<p style="color: #ef4444; font-size: 1.2rem;">⚠️ حدث خطأ في تحميل المودات</p>
<p style="color: #94a3b8; margin-top: 10px;">تحقق من الاتصال بالإنترنت وحاول مرة أخرى</p>
</div>
`;
}
}
// Load mods when page is ready
loadMods();
document.body.removeChild(link);
// Clean up
window.URL.revokeObjectURL(link.href);
} catch (error) {
console.error('خطأ في التحميل:', error);
alert('حدث خطأ في تحميل الملف. حاول مرة أخرى.');
}
}
// Load mods from GitHub
async function loadMods() {
const container = document.getElementById('mods-container');
try {
const res = await fetch(`https://api.github.com/repos/${USER}/${REPO}/contents/${FOLDER}`);
const files = await res.json();
// Clear loading spinner
container.innerHTML = '';
if (!Array.isArray(files) || files.length === 0) {
container.innerHTML = '<p style="text-align: center; color: #94a3b8;">لا توجد مودات حالياً.</p>';
return;
}
for (let file of files) {
if (file.name.endsWith('.py')) {
const fileRes = await fetch(file.download_url);
const text = await fileRes.text();
const match = text.match(/drpmod\s*\{([\s\S]*?)\}/);
if (match) {
const dataRaw = match[1].replace(/'/g, '"');
try {
const data = JSON.parse('{' + dataRaw + '}');
// Prepare image
let imgHtml = data.Picture !== "None"
? `<img src="${data.Picture}" alt="${data.Name}">`
: `<div class="no-img">💣</div>`;
// Prepare video
let vidHtml = data.Video !== "None"
? `<video controls src="${data.Video}"></video>`
: '';
// Create card
const card = document.createElement('div');
card.className = 'mod-card';
card.innerHTML = `
<div class="card-header">
${imgHtml}
<h3>${data.Name}</h3>
</div>
<div class="card-details">
<p>${data.Description}</p>
${vidHtml}
<a href="#" class="dl-btn" data-url="${file.download_url}" data-filename="${file.name}">
📥 تحميل المود
</a>
<span class="version">الإصدار: ${data.Version}</span>
</div>
`;
// Toggle card details on click
card.addEventListener('click', (e) => {
// Don't toggle if clicking download button or video
if (e.target.closest('.dl-btn') || e.target.tagName === 'VIDEO') {
return;
}
card.classList.toggle('active');
});
// Handle download button click
const downloadBtn = card.querySelector('.dl-btn');
downloadBtn.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
const url = e.currentTarget.dataset.url;
const filename = e.currentTarget.dataset.filename;
downloadFile(url, filename);
});
container.appendChild(card);
} catch(e) {
console.log("خطأ في قراءة بيانات: " + file.name, e);
}
}
}
}
if(container.children.length === 0) {
container.innerHTML = '<p style="text-align: center; color: #94a3b8;">لا توجد مودات متاحة حالياً.</p>';
}
} catch (e) {
console.error('خطأ في تحميل المودات:', e);
container.innerHTML = `
<div style="text-align: center; padding: 40px;">
<p style="color: #ef4444; font-size: 1.2rem;">⚠️ حدث خطأ في تحميل المودات</p>
<p style="color: #94a3b8; margin-top: 10px;">تحقق من الاتصال بالإنترنت وحاول مرة أخرى</p>
</div>
`;
}
}
// Load mods when page is ready
loadMods();