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
+
1
5
/* 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 ;
7
19
20
+ /* Hide every image */
21
+ for ( let i = 0 ; i < this . nImgs ; i ++ ) {
22
+ this . imgs [ i ] . style . display = "none" ;
23
+ }
8
24
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
+ }
14
28
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 ] )
19
32
}
20
33
21
- /* Show image based on given index */
22
- this . imgs [ n ] . style . display = "block" ;
23
34
}
24
35
25
36
/* Attach event listeners to each preview */
@@ -32,7 +43,7 @@ for (let j = 0; j < previews.length; j++)
32
43
33
44
variantBtns [ j ] = document . getElementsByClassName ( current_name + '-vars' ) ;
34
45
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 ) ;
36
47
37
48
for ( let k = 0 ; k < variantBtns [ j ] . length ; k ++ )
38
49
{
@@ -57,8 +68,12 @@ for (let j = 0; j < previews.length; j++)
57
68
/* Make the first button inactive */
58
69
variantBtns [ j ] [ 0 ] . classList . add ( 'btn-var-curr' ) ;
59
70
60
-
61
71
}
72
+
73
+ document . getElementById ( current_name + '-download' ) . addEventListener ( 'click' , function ( )
74
+ {
75
+ imgPreview [ j ] . openImageInNewTab ( )
76
+ } )
62
77
}
63
78
64
79
/* Copy link to image to user's clipboard */
0 commit comments