-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
221 lines (206 loc) · 8.06 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
// List of alpums elmints
var alpums =[
{'title':'Art', 'url':'Art.html', 'mainUrl':'imges/Art'},
{'title':'Nature', 'url':'Nature.html','mainUrl':'imges/Nature'},
{'title':'Cats', 'url':'Cats.html','mainUrl':'imges/Cats'}
];
function set(num){
document.getElementById("title_of_alpum").innerHTML = alpums[num].title;
document.getElementById("url_of_alpum").href = alpums[num].url;
document.getElementById("img_of_alpum").src = alpums[num].mainUrl + '/' + Math.floor((Math.random()*15)+1) + '.jpg';
}
// Current alpum
var current_alpum = Math.floor(Math.random()*3); // Get random value from 0 to 2
// Set alpum
function set_alpum(){
set(current_alpum);
}
// Next buttn
function next(){
if(current_alpum == 2)
current_alpum = 0;
else
current_alpum++;
// Set
set(current_alpum);
}
// Prev buttn
function prev(){
if(current_alpum == 0)
current_alpum = 2;
else
current_alpum--;
// Set
set(current_alpum);
}
//load imges
function loadImgs(alpum){
var tempHtml= ' ';
current_alpum = alpum;
for(var i = 0; i < 15; i++)
tempHtml += '<div class="card" id="card_' + (i+1) + '">' +
'<div class="card-cild">' +
'<img alt="" src="' + alpums[alpum].mainUrl + '/' + (i+1) + '.jpg' + '"/>' +
'<div class="toolbar">' +
'<div class="link">' +
'<a href="' + alpums[alpum].mainUrl + '/' + (i+1) + '.jpg' + '" download>' +
'<div class="download">' +
'<p>Download</p>' +
'</div>' +
'</a>' +
'</div>' +
'<div id= "favrots_' + (i+1) + '">' +
'<div class="like_button" id ="favrotsButton_' + (i+1) + '" onclick="'+ (cheackFavrots((i+1), 1) ? 'delFavrots(':'addFavrots(') + (i+1) +')' +
'"><p id="favrotsButtonText_' + (i+1) + '">' + (cheackFavrots((i+1), 1)? 'Remove from ':'Add to ') + 'my fivrots</p></div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'<br>';
document.getElementById("loding").parentNode.removeChild(document.getElementById("loding"));
document.getElementById("header").innerHTML = '<div class="title"><a href="./index.html"><h1>Beautiful wallpapers</h1></a></div>';
document.getElementById("imgeees").innerHTML = '<div id="imges_scrol"></div>';
document.getElementById("imges_scrol").innerHTML = tempHtml;
}
// Get random wallpaper
function getRandomWallpaper(){
var randImg = Math.floor(Math.random()*15) + 1;
document.getElementById("loding").parentNode.removeChild(document.getElementById("loding"));
document.getElementById("looooad").innerHTML = '<div id="imges_scrol"></div>';
document.getElementById("imges_scrol").innerHTML =
'<div class="card" id="card_' + randImg + '">' +
'<div class="card-cild">' +
'<img alt="" src="' + alpums[current_alpum].mainUrl + '/' + randImg + '.jpg' + '"/>' +
'<div class="toolbar">' +
'<div class="link">' +
'<a href="' + alpums[current_alpum].mainUrl + '/' + randImg + '.jpg' + '" download>' +
'<div class="download">' +
'<p>Download</p>' +
'</div>' +
'</a>' +
'</div>' +
'<div id= "favrots_' + randImg + '">' +
'<div class="like_button" id ="favrotsButton_' + randImg + '" onclick="'+ (cheackFavrots(randImg, 1) ? 'delFavrots(':'addFavrots(') + randImg+')' +
'"><p id="favrotsButtonText_' + randImg + '">' + (cheackFavrots(randImg, 1)? 'Remove from ':'Add to ') + 'my fivrots</p></div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'<br>';
}
// Add me
function me(){
document.getElementById("footer").innerHTML = '<a href="https://github.com/Anas-Elgarhy"><p>Coding and design by me ^-^</p></a>';
}
// Cookies for save favertos
// Cheack cookies fun
function cheakCookies(){
var favrots = getCookies("favrotsIn" + alpums[current_alpum].title);
if(favrots != "")
return true;
else
return false;
}
// Set cookie
function setCookies(cvalue, exdays, option){
var temp = "favrotsIn" + alpums[current_alpum].title;
// end date
var endDate = new Date();
var date = new Date();
endDate.setTime(endDate.getTime() + (exdays*24*60*60*1000));
// Cheak
if(cheakCookies() && option == 1)
temp += getCookies();
else
temp += "=";
//
if(option == 1)
document.cookie = temp + cvalue + "|" + date.toLocaleTimeString() + ",;" + "expires="+ endDate.toUTCString() + ";path=/" + alpums[current_alpum].url;
else
{
let tempSize = cvalue.length -1;
document.cookie = temp + cvalue + (cvalue == ""? ";": ((cvalue[tempSize] != ",")? ",;":";")) + "expires="+ endDate.toUTCString() + ";path=/" + alpums[current_alpum].url;
}
}
// Get cookie
function getCookies(){
let cname = "favrotsIn" + alpums[current_alpum].title;
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(cname) == 0) {
return c.substring(cname.length, c.length);
}
}
return "";
}
// Delete cookikes
function delCookies(){
document.cookie = "favrotsIn" + alpums[current_alpum].title + "=0|1:39:14 AM,;expires=Thu, 18 Dec 2013 12:00:00 UTC;path=/" + alpums[current_alpum].url;
}
/// This function want tow parameters, one parameter kye to you want cheak or search and tow parameter option to you want use
// Cheack alrdy in favrots
function cheackFavrots(key, option){
let fav = new Array();
// Get favrots in current alpum
let favrots = getCookies().substring(1); // del "=" from return value
// Split return value in array
let alrdyIn = favrots.split(",");
// Get favrots without Date
for(let i=0; i < alrdyIn.length-1; i++)
{
let temp = alrdyIn[i].split("|");
fav[i] = parseInt(temp[0]);
}
//
if(fav.indexOf(parseInt(key)) < 0)
if(option == 1)
return false;
else
return (-1);
else
if(option == 1)
return true;
else
return (fav.indexOf(parseInt(key)));
}
// add favrots
function addFavrots(key){
// Cheack secure
if(!cheackFavrots(key, 1))
{
setCookies(key, 30, 1);
// set favrotsButton
document.getElementById("favrots_" + key).innerHTML = '<div class="like_button" id ="favrotsButton_' + key + '" onclick="delFavrots('+ key +')">'
document.getElementById("favrotsButton_" + key).innerHTML = '<p>Remove from my favrots</p>';
}
else
window.alert("The picture is already in you favorites");
}
// delete favrots
function delFavrots(key){
// Get kay pos with binry search
let pos = cheackFavrots(key, 2);
// Delete
if(pos > -1)
{
// Get all favrots and store in locale array
let allFavrots = getCookies().substring(1).split(",");
allFavrots.splice(pos,1);
let temp = allFavrots.toString();
setCookies(temp, 30, 2);
// Set button favorts
document.getElementById("favrots_" + key).innerHTML = '<div class="like_button" id ="favrotsButton_' + key + '" onclick="addFavrots('+ key +')">'
document.getElementById("favrotsButton_" + key).innerHTML = '<p>Add to my favrots</p>';
}
else
window.alert("Error!!!!");
}
// Get all favorts
function getAllFavrots(){
window.alert("Soooooooooooooooooooooooooooooooooooooooon ");
}