-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathscript.js
More file actions
251 lines (226 loc) · 9.62 KB
/
script.js
File metadata and controls
251 lines (226 loc) · 9.62 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
const proxAPI = "https://scriptblox-api-proxy.vercel.app/api/fetch";
const searchproxAPI = "https://scriptblox-api-proxy.vercel.app/api/search";
const scriptsGrid = document.getElementById("scripts-grid");
const searchInput = document.getElementById("search-input");
const filter = document.getElementById("filter-select");
const search = document.getElementById("search-button");
const prev = document.getElementById("prev-button");
const next = document.getElementById("next-button");
const error_msg = document.getElementById("error-message");
const modal = document.getElementById("script-details-modal");
const modalTitle = document.getElementById("modal-title");
const modalDetails = document.getElementById("modal-details");
const closeModal = document.getElementById("close-modal");
const S_Cache = new Map();
let currentPage = 1;
let isModes = false;
let Querys = "";
let Modes = "";
async function fetchScripts(page = 1) {
if (S_Cache.has(page)) {
displayScripts(S_Cache.get(page));
return;
}
try {
const response = await fetch(`${proxAPI}?page=${page}`);
if (!response.ok) {
if (response.status === 429) {
throw new Error("Too many requests. Please wait a moment and try again.");
}
throw new Error(`API Error: ${response.status} - ${response.statusText}`);
}
const data = await response.json();
if (!data.result || !data.result.scripts.length) throw new Error("No scripts found.");
S_Cache.set(page, data.result.scripts); // Cache result
displayScripts(data.result.scripts);
error_msg.textContent = "";
} catch (error) {
displayError(error.message);
}
}
async function searchScripts(query, mode, page = 1) {
try {
const url = new URL(searchproxAPI);
url.searchParams.append("q", query);
if (mode) url.searchParams.append("mode", mode);
url.searchParams.append("page", page);
const response = await fetch(url);
if (!response.ok) {
if (response.status === 429) {
throw new Error("Too many requests. Please wait a moment and try again.");
}
throw new Error(`API Error: ${response.status} - ${response.statusText}`);
}
const data = await response.json();
if (!data.result || !data.result.scripts.length) throw new Error("No search results found.");
displayScripts(data.result.scripts);
error_msg.textContent = "";
} catch (error) {
displayError(error.message);
}
}
function displayScripts(scripts) {
scriptsGrid.innerHTML = "";
const maxTitleLength = 60;
scripts.forEach((script) => {
let displayTitle = script.title;
if (displayTitle.length > maxTitleLength) {
displayTitle = displayTitle.substring(0, maxTitleLength) + "...";
}
let imageSrc;
if (script.game?.imageUrl && script.game.imageUrl.startsWith("http")) {
imageSrc = script.game.imageUrl;
} else {
imageSrc = `https://scriptblox.com${script.game?.imageUrl || ""}`;
}
const fallbackImage = "https://files.catbox.moe/gamwb1.jpg";
const card = document.createElement("div");
card.className = "card";
card.innerHTML = `
<img src="${imageSrc}" alt="${displayTitle}" loading="lazy"
onerror="this.src='${fallbackImage}';">
<div class="card-content">
<h2 class="card-title">${displayTitle}</h2>
<p class="card-game">Game: ${script.game?.name || "Universal"}</p>
</div>
`;
card.addEventListener("click", () => displayDetails(script));
scriptsGrid.appendChild(card);
});
}
function displayDetails(script) {
const gameName = script.game?.name || "Universal";
const gameImage = script.game?.imageUrl
? script.game.imageUrl.startsWith("http")
? script.game.imageUrl
: `https://scriptblox.com${script.game.imageUrl}`
: "https://files.catbox.moe/gamwb1.jpg";
if (!script.script) {
window.location.href = `https://scriptblox.com/script/${script.slug}`;
return;
}
const maxModalTitleLength = 20;
const modalDisplayTitle = script.title.length > maxModalTitleLength
? script.title.substring(0, maxModalTitleLength) + "..."
: script.title;
modalTitle.textContent = "Script Details";
modalDetails.innerHTML = `
<div class="minimal-details-card">
<div class="details-header">
<div class="header-image">
<img src="${gameImage}" alt="${gameName}" onerror="this.src='https://files.catbox.moe/gamwb1.jpg';">
</div>
<div class="header-info">
<h3>${modalDisplayTitle}</h3>
<div class="details-tags">
<span class="tag ${script.verified ? 'verified' : 'not-verified'}">
<i class="fas fa-${script.verified ? 'check-circle' : 'times-circle'}"></i>
${script.verified ? "Verified" : "Not Verified"}
</span>
<span class="tag ${script.isPatched ? 'patched' : 'active'}">
<i class="fas fa-${script.isPatched ? 'ban' : 'check'}"></i>
${script.isPatched ? "Patched" : "Active"}
</span>
<span class="tag ${script.scriptType === 'paid' ? 'paid' : ''}">
<i class="fas fa-${script.scriptType === 'paid' ? 'dollar-sign' : 'code'}"></i>
${script.scriptType.charAt(0).toUpperCase() + script.scriptType.slice(1)}
</span>
${script.key ? `
<span class="tag key">
<i class="fas fa-key"></i>
Requires Key
</span>
` : ''}
</div>
</div>
</div>
<div class="details-section">
<h4><i class="fas fa-info-circle"></i> Details</h4>
<div class="details-info">
<div class="info-item">
<i class="fas fa-eye"></i>
<span>${script.views.toLocaleString()} Views</span>
</div>
<div class="info-item">
<i class="fas fa-calendar-alt"></i>
<span>Created: ${new Date(script.createdAt).toLocaleDateString()}</span>
</div>
<div class="info-item">
<i class="fas fa-calendar-check"></i>
<span>Updated: ${new Date(script.updatedAt).toLocaleDateString()}</span>
</div>
${script.key ? `
<div class="info-item">
<i class="fas fa-key"></i>
<a href="${script.keyLink}" target="_blank" rel="noopener noreferrer" style="color: white; text-decoration: underline;">Get Key</a>
</div>
` : ''}
</div>
</div>
<div class="script-box">
<h4><i class="fas fa-code"></i> Script</h4>
<div class="code-container">
<pre>${script.script || "No script available."}</pre>
<button class="copy-button">
<i class="fas fa-copy"></i>
Copy Script
</button>
</div>
</div>
</div>
`;
const copyButton = modalDetails.querySelector(".copy-button");
copyButton.addEventListener("click", () => {
navigator.clipboard.writeText(script.script || "No script available.").then(() => {
copyButton.innerHTML = '<i class="fas fa-check"></i> Copied!';
setTimeout(() => {
copyButton.innerHTML = '<i class="fas fa-copy"></i> Copy Script';
}, 2000);
});
});
modal.style.display = "flex";
}
function displayError(message) {
scriptsGrid.innerHTML = "";
error_msg.textContent = message;
}
search.addEventListener("click", () => {
Querys = searchInput.value.trim();
Modes = filter.value;
currentPage = 1;
isModes = !!Querys;
isModes ? searchScripts(Querys, Modes, currentPage) : fetchScripts(currentPage);
});
prev.addEventListener("click", () => {
if (currentPage > 1) {
currentPage--;
if (isModes && Querys) {
searchScripts(Querys, Modes, currentPage);
} else {
fetchScripts(currentPage);
}
}
});
next.addEventListener("click", () => {
currentPage++;
if (isModes && Querys) {
searchScripts(Querys, Modes, currentPage);
} else {
fetchScripts(currentPage);
}
});
closeModal.addEventListener("click", () => {
modal.style.display = "none";
});
searchInput.addEventListener("focus", () => {
searchInput.parentElement.style.transform = "scale(1.02)";
});
searchInput.addEventListener("blur", () => {
searchInput.parentElement.style.transform = "scale(1)";
});
searchInput.addEventListener("keydown", (event) => {
if (event.key === "Enter") {
search.click();
}
});
fetchScripts();