1
- var baseUrl = "https://raw.githubusercontent.com/nmssilva/sensation/master/"
1
+ var baseUrl = "https://raw.githubusercontent.com/nmssilva/sensation/master/" ;
2
2
3
- var apiBaseUrl = "https://www.googleapis.com/customsearch/v1"
4
- var imageApikey = "AIzaSyB258Pcb4kRI4JtH4Q4KjRcLDAj22YxLOE"
5
- var searchEngineId = "009202958278043524580:1mrllu72sxk"
6
- var searchType = "image"
7
- var imgSize = "huge"
8
- var minWidth = 1920
3
+ var apiBaseUrl = "https://www.googleapis.com/customsearch/v1" ;
4
+ var imageApikey = "AIzaSyB258Pcb4kRI4JtH4Q4KjRcLDAj22YxLOE" ;
5
+ var searchEngineId = "009202958278043524580:1mrllu72sxk" ;
6
+ var searchType = "image" ;
7
+ var imgSize = "huge" ;
8
+ var minWidth = 1920 ;
9
9
10
10
var sensation , imageUrl ;
11
11
@@ -19,7 +19,7 @@ function hashCode(num) {
19
19
hash |= 0 ; // Convert to 32bit integer
20
20
}
21
21
return hash ;
22
- } ;
22
+ }
23
23
24
24
function readIntroFile ( file , num ) {
25
25
var rawFile = new XMLHttpRequest ( ) ;
@@ -35,7 +35,7 @@ function readIntroFile(file, num) {
35
35
document . getElementById ( "title" ) . innerHTML += intro + "... " ;
36
36
}
37
37
}
38
- }
38
+ } ;
39
39
rawFile . send ( null ) ;
40
40
}
41
41
@@ -53,7 +53,7 @@ function readTextFile(file, num) {
53
53
document . getElementById ( "title" ) . innerHTML += sensation + " sensation :O" ;
54
54
}
55
55
}
56
- }
56
+ } ;
57
57
rawFile . send ( null ) ;
58
58
}
59
59
@@ -72,47 +72,57 @@ function getImage(sensation) {
72
72
success : function ( response ) {
73
73
// alert(response.status);
74
74
var imageList = response [ 'items' ] ;
75
- i = 0 ;
75
+ var i = 0 ;
76
76
// Get a suitable image
77
77
while ( true ) {
78
78
if ( imageList [ i ] != null ) {
79
-
80
79
console . log ( "ASD" ) ;
81
80
var width = imageList [ i ] [ 'image' ] [ 'width' ] ;
82
81
var height = imageList [ i ] [ 'image' ] [ 'height' ] ;
83
82
//if (width > height && width >= 1920 && height >= 1080) {
83
+ document . body . style [ "background-image" ] = "url( " + imageList [ i ] [ 'link' ] + ")" ;
84
+ var img = new Image ( ) ;
85
+ img . onload = function ( ) {
86
+ document . getElementById ( "loader" ) . style . display = "none" ;
87
+ document . getElementById ( "main" ) . style . display = "block" ;
88
+ } ;
89
+ img . onerror = function ( ) {
90
+ document . body . style [ "background-image" ] = "url(bg.jpg)" ;
91
+ document . getElementById ( "loader" ) . style . display = "none" ;
92
+ document . getElementById ( "main" ) . style . display = "block" ;
93
+ } ;
94
+ img . src = imageList [ i ] [ 'link' ] ;
95
+ break ;
96
+ }
97
+ i ++ ;
98
+ /*
84
99
document.body.style["background-image"] = "url( " + imageList[i]['link'] + ")";
85
100
break;
86
101
87
-
88
- /* var newImg = new Image;
102
+ var newImg = new Image;
89
103
newImg.onload = function() {
90
104
document.body.style["background-image"] = this.src;
91
105
};
92
106
newImg.src = imageList[i]['link'];
93
107
break;
94
- */
95
108
//}
96
109
}
97
-
98
110
i++;
99
-
111
+ */
100
112
}
101
113
} ,
102
114
error : function ( ) {
103
- document . body . style . background = "url(https://raw.githubusercontent.com/nmssilva/sensation/master/ bg.jpg)" ;
115
+ document . body . style [ " background-image" ] = "url(bg.jpg)" ;
104
116
}
105
117
} ) ;
106
118
}
107
119
108
120
window . onload = function ( ) {
109
-
110
121
var d = new Date ( ) ;
111
122
var num = d . getDate ( ) * 10000000 + d . getMonth ( ) * 10000 + d . getFullYear ( ) ;
112
123
num = hashCode ( num . toString ( ) ) ;
124
+ document . body . style . backgroundColor = "grey" ;
113
125
readIntroFile ( baseUrl + "misc/intros.txt" , num ) ;
114
126
readTextFile ( baseUrl + "misc/sensations.txt" , num ) ;
115
- document . body . style . backgroundColor = "grey" ;
116
127
getImage ( sensation ) ;
117
-
118
- }
128
+ } ;
0 commit comments