-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
449 lines (394 loc) · 13.1 KB
/
index.html
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Plugin Selector</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer">
<style>
.small,
small {
font-size: .7em;
color: slategray;
}
.remove-btn {
float: right;
margin: 3px;
}
#selected-plugins {
display: flex;
flex-wrap: wrap;
gap: 10px;
align-items: stretch;
flex-direction: row;
margin-bottom: 5px;
border: 2px dashed black;
background-color: #8ddd70;
padding: 4px;
}
#selected-plugins .code-block {
min-width: 200px;
flex-basis: auto;
flex-grow: 1;
box-shadow: 0px 0px 2px;
background-color: #d2ffce;
padding: 4px;
max-width: 33.3%;
}
.circle {
position: absolute;
border: 3px solid transparent;
border-top-color: #9ee925;
border-radius: 50%;
-webkit-animation: rotate linear infinite;
animation: rotate linear infinite;
}
.circle.one {
height: 50px;
width: 50px;
left: 50px;
top: 50px;
-webkit-animation-duration: 0.85s;
animation-duration: 0.85s;
}
.circle.two {
height: 75px;
width: 75px;
top: 38px;
left: 38px;
-webkit-animation-duration: 0.95s;
animation-duration: 0.95s;
}
.circle.three {
height: 100px;
width: 100px;
top: 25px;
left: 25px;
-webkit-animation-duration: 1.05s;
animation-duration: 1.05s;
}
#loader {
position: absolute;
top: 50%;
left: 50%;
margin: -90px 0 0 -90px;
z-index: 1000;
}
#overlay {
position: fixed;
display: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 2;
cursor: wait;
}
@-webkit-keyframes rotate {
from {
transform: rotateZ(360deg);
}
to {
transform: rotateZ(0deg);
}
}
@keyframes rotate {
from {
transform: rotateZ(360deg);
}
to {
transform: rotateZ(0deg);
}
}
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(1);
}
}
#permalink {
display: flex;
justify-content: center;
align-items: center;
}
#permalink.clicked {
position: relative;
animation: pulse 0.5s;
}
</style>
</head>
<body>
<div id="overlay"></div>
<div class="container">
<div id="loader" class="d-none">
<div class="circle one"></div>
<div class="circle two"></div>
<div class="circle three"></div>
</div>
<h1 class="my-4">Plugin Selector</h1>
<h5 class="my-4">Compiles a wordpress.zip file with the selected plugins embedded<br>
<small>Optionally activates all plugins, and removes default plugins.</small>
</h5>
<div id="plugin_selection" class="d-none">
<h6>Plugin activation/deletion</h6>
<label>
<input type="checkbox" id="activate_plugins" value="1"> Auto-activate plugins
</label>
<label>
<input type="checkbox" id="deactivate_plugins" value="1"> Remove Askiment and Hello Dolly
</label>
<h4>Selected Plugins</h4>
<div id="selected-plugins"></div>
<button id="compile_wp" type="button" class="btn btn-success pull-right">Download Wordpress 6.1.1 with selected plugins</button>
</div>
<form>
<div class="mb-3">
<label for="searchInput" class="form-label">Search for Plugins:</label>
<input type="text" class="form-control" id="searchInput" placeholder="Enter plugin name">
</div>
<button type="submit" class="btn btn-primary">Search</button>
</form>
<div class="m-3">
<div id="permalink_wrap">
<div id="permalink" class="mb-3" onclick="copyPermalink()" style="cursor: pointer;"></div>
</div>
<div id="pluginList" class="mt-4"></div>
</div>
<div id="downloadToken"></div>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/js/all.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.3/js/bootstrap.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
$(document).on("click", ".remove-btn", function () {
var slug = $(this).data("slug");
remove_codeblock(slug);
});
$(document).on("change", ".select-plugin", function () {
var slug = $(this).data("slug");
if ($(this).prop("checked")) {
add_codeblock(slug);
} else {
remove_codeblock(slug);
}
});
$(document).on("click", "#compile_wp", function () {
var downloadToken = blockResubmit();
$("#loader").removeClass("d-none");
$("#overlay").css("display", "block");
var hash = window.location.hash.substr(1);
var args = [];
if ($("#deactivate_plugins").prop("checked")) {
args.push("deactivate");
}
if ($("#activate_plugins").prop("checked")) {
args.push("activate");
}
if (args.length) {
window.location.href = "./build.php?downloadToken=" + downloadToken + "&" + args.join("&") + "&p=" + hash;
} else {
window.location.href = "./build.php?downloadToken=" + downloadToken + "&p=" + hash;
}
});
function updateUrlHash() {
var hash = $('#selected-plugins .remove-btn').map(function () {
return $(this).data('slug');
}).get().sort().join(';');
window.location.hash = hash;
$("#permalink").text(window.location);
if (hash != "") {
$("#plugin_selection").removeClass("d-none");
} else {
$("#plugin_selection").addClass("d-none");
}
}
function add_codeblock(slug) {
if ($("#selected-" + slug).length == 0) {
var block = '<div class="code-block" id="selected-' + slug + '"><button type="button" class="btn btn-sm btn-danger remove-btn" data-slug="' + slug + '">×</button> ' + slug + '</div>';
$('#selected-plugins').append(block);
updateUrlHash();
}
}
function remove_codeblock(slug) {
$("#selected-" + slug).remove();
$("#checkbox-" + slug).prop("checked", false);
updateUrlHash();
}
function readUrlHash() {
var hash = window.location.hash.substr(1);
if (hash.length > 0) {
var slugs = hash.split(';').sort();
for (var i = 0; i < slugs.length; i++) {
add_codeblock(slugs[i]);
}
}
}
$(document).ready(function () {
readUrlHash();
});
// Function to render plugin data to HTML
function renderPlugin(plugin) {
if ($("#selected-" + plugin.slug).length == 0) {
var is_checked = "";
} else {
var is_checked = "checked";
}
let totalRatings = 0;
let numRatings = 0;
for (let rating in plugin.ratings) {
totalRatings += rating * plugin.ratings[rating];
numRatings += plugin.ratings[rating];
}
let averageRating = totalRatings / numRatings;
return `
<div class="card my-3">
<div class="card-body">
<h5 class="card-title">
<label>
<input type="checkbox" class="checkbox select-plugin" id="checkbox-${plugin.slug}" data-slug="${plugin.slug}" data-name="${plugin.name}" ${is_checked}> ${plugin.name}
</label>
<small>
Version: ${plugin.version}
</small>
</h5>
<h6 class="card-subtitle mb-2 text-muted">${plugin.slug}</h6>
<div class="accordion" id="accordion-${plugin.slug}">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse-${plugin.slug}" aria-expanded="true" aria-controls="collapseOne">
${plugin.short_description}
</button>
</h2>
<div id="collapse-${plugin.slug}" class="accordion-collapse collapse" aria-labelledby="headingOne" data-bs-parent="#accordion-${plugin.slug}">
<div class="accordion-body">
<p>${plugin.description}</p>
</div>
</div>
</div>
</div>
${rating_html(averageRating * 20)}
<small>
Active Installs: ${plugin.active_installs}
</small>
</div>
</div>`;
}
function rating_html(percentage) {
const maxStars = 5;
const filledStars = Math.round((percentage / 100) * maxStars);
const halfStar = (filledStars < (percentage / 100) * maxStars + 0.5) ? true : false;
let html = '<div class="star-rating"><span class="card-text">Ratings: ';
for (let i = 1; i <= maxStars; i++) {
if (i <= filledStars) {
html += '<i class="fa-solid fa-star"></i>';
} else if (halfStar && i === filledStars + 1) {
html += '<i class="fa-solid fa-star-half-stroke"></i>';
} else {
html += '<i class="fa-regular fa-star"></i>';
}
}
html += '</span></div>';
return html;
}
// Function to handle AJAX response
function handleResponse(response) {
// Get plugin data from response
const plugins = response.plugins;
// Render plugin data to HTML
const pluginListHtml = plugins.map(renderPlugin).join('');
// Append plugin data to pluginList div
$('#pluginList').html(pluginListHtml);
}
// Function to handle AJAX errors
function handleError(error) {
console.error('Error:', error);
}
// Function to handle form submission
function handleSubmit(event) {
event.preventDefault();
// Get search query from input field
const query = $('#searchInput').val();
// Send AJAX request to API
$.ajax({
url: 'https://api.wordpress.org/plugins/info/1.2/',
type: 'POST',
data: {
action: 'query_plugins',
request: {
per_page: 250,
search: query
}
},
dataType: 'jsonp',
success: handleResponse,
error: handleError
});
}
$('form').on('submit', handleSubmit);
function getCookie(name) {
var parts = document.cookie.split(name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
function expireCookie(cName) {
document.cookie =
encodeURIComponent(cName) + "=deleted; expires=" + new Date(0).toUTCString();
}
function setCursor(docStyle, buttonStyle) {
$("body").css("cursor", docStyle);
$("#compile_wp").css("cursor", buttonStyle);
}
function setFormToken() {
var downloadToken = new Date().getTime();
return downloadToken;
}
var downloadTimer;
var attempts = 60;
function blockResubmit() {
var downloadToken = setFormToken();
setCursor("wait", "wait");
$("#compile_wp").attr("disabled", "disabled");
downloadTimer = window.setInterval(function () {
var token = getCookie("downloadToken");
if ((token == downloadToken) || (attempts == 0)) {
unblockSubmit();
}
attempts--;
}, 1000);
return downloadToken;
}
function unblockSubmit() {
$("#loader").addClass("d-none");
$("#overlay").css("display", "none");
$("#compile_wp").removeAttr("disabled");
setCursor("auto", "pointer");
window.clearInterval(downloadTimer);
expireCookie("downloadToken");
attempts = 60;
}
function copyPermalink() {
const permalink = document.getElementById("permalink");
$(permalink).addClass("clicked");
const range = document.createRange();
range.selectNode(permalink);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand("copy");
window.getSelection().removeAllRanges();
setTimeout(function () {
$(permalink).removeClass("clicked");
}, 600);
}
</script>
</body>
</html>