Skip to content

Commit 7ba8d53

Browse files
use a download button instead of 910234123 confusing direct links
1 parent af14f13 commit 7ba8d53

File tree

3 files changed

+82
-34
lines changed

3 files changed

+82
-34
lines changed

catalog/events.js

+33-18
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
1+
const REPO_URL = "https://raw.githubusercontent.com/DaringCuteSeal/wallpapers"
2+
const BRANCH = "gh-pages"
3+
//https://raw.githubusercontent.com/DaringCuteSeal/wallpapers/main/os/artix-iceberg/artix-iceberg-light.png
4+
15
/* Create a new preview object */
2-
var preview = function(name, variants)
3-
{
4-
this.name = name;
5-
this.variants = variants;
6-
}
6+
class preview {
7+
constructor(name, variants, variants_filename, category) {
8+
this.name = name;
9+
this.variants = variants;
10+
this.category = category;
11+
this.variants_filename = variants_filename;
12+
this.selected_variant = 0;
13+
}
14+
/* Show image based on given index */
15+
showImg(n) {
16+
this.selected_variant = n;
17+
this.imgs = document.getElementsByClassName("preview-img-" + this.name);
18+
this.nImgs = this.imgs.length;
719

20+
/* Hide every image */
21+
for (let i = 0; i < this.nImgs; i++) {
22+
this.imgs[i].style.display = "none";
23+
}
824

9-
/* Show image based on given index */
10-
preview.prototype.showImg = function(n)
11-
{
12-
this.imgs = document.getElementsByClassName("preview-img-" + this.name);
13-
this.nImgs = this.imgs.length;
25+
/* Show image based on given index */
26+
this.imgs[n].style.display = "block";
27+
}
1428

15-
/* Hide every image */
16-
for(i = 0; i < this.nImgs; i++)
17-
{
18-
this.imgs[i].style.display = "none";
29+
/* Open high-resolution image in new tab */
30+
openImageInNewTab() {
31+
window.open(REPO_URL + "/" + BRANCH + "/" + this.category + "/" + this.name + "/" + this.variants_filename[this.selected_variant])
1932
}
2033

21-
/* Show image based on given index */
22-
this.imgs[n].style.display = "block";
2334
}
2435

2536
/* Attach event listeners to each preview */
@@ -32,7 +43,7 @@ for (let j = 0; j < previews.length; j++)
3243

3344
variantBtns[j] = document.getElementsByClassName(current_name + '-vars');
3445

35-
imgPreview[j] = new preview(current_name, previews[j].variants);
46+
imgPreview[j] = new preview(current_name, previews[j].variants, previews[j].variants_filename, previews[j].category);
3647

3748
for(let k = 0; k < variantBtns[j].length; k++)
3849
{
@@ -57,8 +68,12 @@ for (let j = 0; j < previews.length; j++)
5768
/* Make the first button inactive */
5869
variantBtns[j][0].classList.add('btn-var-curr');
5970

60-
6171
}
72+
73+
document.getElementById(current_name + '-download').addEventListener('click', function()
74+
{
75+
imgPreview[j].openImageInNewTab()
76+
})
6277
}
6378

6479
/* Copy link to image to user's clipboard */

catalog/generate-catalog.sh

+21-14
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,8 @@ EOF
312312

313313
write "<br>\n" 4
314314

315-
write "<b>Images:</b> " 3
316-
317-
m=0
318-
for l in "${!variants[@]}"
319-
do
320-
write "<a href=\"https://raw.githubusercontent.com/DaringCuteSeal/wallpapers/main/$category/$parsable_name/${variants[$l]}\">${variants[$l]} ($l)</a>"
321-
m=$(($m+1))
322-
if [[ $m -lt ${#variants[@]} ]]
323-
then
324-
write " &bull; "
325-
fi
326-
done
315+
write "<button id=\"$parsable_name-download\" class=\"download-btn\">Download Variant</button>" 4
327316
write "\n</p>\n"
328-
unset m
329317

330318
write_stdin << EOF
331319
<p>
@@ -376,6 +364,22 @@ vars_str(){
376364
unset k
377365
}
378366

367+
filenames_str(){
368+
echo -n "["
369+
k=0
370+
for j in "${variants[@]}"
371+
do
372+
echo -n "'$j'"
373+
k=$(($k+1))
374+
if [[ $k -lt ${#variants[@]} ]]
375+
then
376+
echo -n ", "
377+
fi
378+
done
379+
echo -n "]"
380+
unset k
381+
}
382+
379383
work "Generating previews JSON..." # and yes it isn't JSON but hey it's called "JavaScript Object Notation" so...
380384
cat > "$out_previews" <<< "var previews = ["
381385

@@ -388,10 +392,13 @@ do
388392
write_js_stdin << EOF
389393
{
390394
'name': '$parsable_name',
395+
'category': '$category',
391396
EOF
392397

393398
m=$(($m+1))
394-
write_js "'variants': `vars_str`\n" 2
399+
write_js "'variants': $(vars_str),\n" 2
400+
401+
write_js "'variants_filename': $(filenames_str)\n" 2
395402
write_js "}" 1
396403

397404
if [[ $m -lt ${#infos[@]} ]]

catalog/styles.css

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
@media (prefers-color-scheme: dark) {
42
.btn-var-curr {
53
background-color: #3B4656;
@@ -18,6 +16,21 @@
1816
transition: 0.1s ease;
1917
background-color: #445062;
2018
}
19+
20+
21+
.download-btn {
22+
font-weight: bold;
23+
background-color: #46726B;
24+
font-size: 100%;
25+
padding: 10px;
26+
margin-top: 1em;
27+
}
28+
29+
.download-btn:hover {
30+
background-color: #334D49;
31+
}
32+
33+
2134
}
2235

2336
@media (prefers-color-scheme: light) {
@@ -39,6 +52,19 @@
3952
transition: 0.1s ease;
4053
background-color: #9FA2A5;
4154
}
55+
56+
.download-btn {
57+
font-weight: bold;
58+
background-color: #68AFA3;
59+
font-size: 100%;
60+
padding: 10px;
61+
margin-top: 1em;
62+
}
63+
64+
.download-btn:hover {
65+
background-color: #58847D;
66+
}
67+
4268
}
4369

4470

0 commit comments

Comments
 (0)