-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
224 lines (200 loc) · 8.32 KB
/
script.js
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
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 = "";
scripts.forEach((script) => {
let imageSrc;
if (script.game?.imageUrl.startsWith("http")) {
imageSrc = script.game.imageUrl;
} else {
imageSrc = `https://scriptblox.com${script.game?.imageUrl || ""}`;
}
const fallbackImage = "https://c4.wallpaperflare.com/wallpaper/673/92/53/404-not-found-anime-girls-glowing-eyes-wallpaper-thumb.jpg";
const card = document.createElement("div");
card.className = "card";
card.innerHTML = `
<img src="${imageSrc}" alt="${script.title}" loading="lazy"
onerror="this.src='${fallbackImage}';">
<div class="card-content">
<h2 class="card-title">${script.title}</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
? `https://scriptblox.com${script.game.imageUrl}`
: "https://c4.wallpaperflare.com/wallpaper/673/92/53/404-not-found-anime-girls-glowing-eyes-wallpaper-thumb.jpg";
const keyLink = script.key
? `<a href="${script.keyLink}" target="_blank" rel="noopener noreferrer" class="key-link">Get Key</a>`
: "No Key Required";
if (!script.script) {
// Redirects to the original post if no script is found
window.location.href = `https://scriptblox.com/script/${script.slug}`;
return;
}
modalTitle.textContent = "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://c4.wallpaperflare.com/wallpaper/673/92/53/404-not-found-anime-girls-glowing-eyes-wallpaper-thumb.jpg';">
</div>
<div class="header-info">
<h3>${script.title}</h3>
<p class="tag">${script.scriptType.charAt(0).toUpperCase() + script.scriptType.slice(1)}</p>
<p class="tag ${script.verified ? 'verified' : 'not-verified'}">
${script.verified ? "Verified" : "Not Verified"}
</p>
</div>
</div>
<div class="details-tags">
<span class="tag">${gameName}</span>
<span class="tag">${script.visibility}</span>
<span class="tag ${script.isPatched ? 'patched' : 'active'}">
${script.isPatched ? "Patched" : "Active"}
</span>
</div>
<div class="details-section">
<h4>Details</h4>
<p><i class="fas fa-eye"></i> Views: ${script.views}</p>
<p><i class="fas fa-calendar-alt"></i> Created At: ${new Date(script.createdAt).toLocaleString()}</p>
<p><i class="fas fa-calendar-check"></i> Updated At: ${new Date(script.updatedAt).toLocaleString()}</p>
<p><i class="fas fa-key"></i> Requires Key: ${keyLink}</p>
</div>
<div class="script-box">
<h4>Script</h4>
<div class="code-container">
<pre>${script.script || "No script available."}</pre>
<button class="copy-button">Copy Script</button>
</div>
</div>
</div>
`;
const copyButton = modalDetails.querySelector(".copy-button");
copyButton.addEventListener("click", () => {
navigator.clipboard.writeText(script.script || "No script available.").then(() => {
alert("Script copied to clipboard!");
});
});
modal.style.display = "flex";
}
// function CClick(slug) {
// window.open(`https://scriptblox-api-proxy.vercel.app/script/${slug}`, "_blank");
// }
function displayError(message) {
scriptsGrid.innerHTML = "";
error_msg.textContent = message;
}
search.addEventListener("click", () => {
Querys = searchInput.value.trim();
Modes = filter.value;
currentPage = 1;
isModes = !!Querys;
// searchScripts(Querys, Modes, currentPage);
isModes ? searchScripts(Querys, Modes, currentPage) : fetchScripts(currentPage);
});
// search.addEventListener("click", () => {
// const query = searchInput.value.trim();
// if (!query) {
// fetchScripts();
// } else {
// searchScripts(query, Modes, currentPage); // 1 (uh..)
// }
// });
// let debounceTimeout;
// searchInput.addEventListener("input", () => {
// clearTimeout(debounceTimeout);
// debounceTimeout = setTimeout(() => {
// const query = searchInput.value.trim();
// if (query) {
// searchScripts(query, filter.value, 1);
// } else {
// fetchScripts();
// }
// }, 300);
// });
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";
});
fetchScripts();