-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.js
139 lines (118 loc) · 3.63 KB
/
home.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
function slideShow(){
const arr=[
"https://img1.hotstarext.com/image/upload/f_auto,t_web_m_1x/sources/r1/cms/prod/8295/1328295-h-b05c8156e59a",
"https://img1.hotstarext.com/image/upload/f_auto,t_web_m_1x/sources/r1/cms/prod/old_images/MOVIE/3314/1770003314/1770003314-h",
"https://img1.hotstarext.com/image/upload/f_auto,t_web_m_1x/sources/r1/cms/prod/6530/1326530-h-f2a7e4e4e3d6"
];
let i=0;
let div=document.getElementById("slider");
let img=document.createElement("img");
img.src=arr[0];
div.append(img);
i=i+1;
setInterval(function(){
if(i==3){
i=0;
}
img.src=arr[i];
i=i+1;
div.append(img);
},2000)
}
slideShow();
let movies=[
{
name:"CHHICHHORE",
rating:9.3,
img:"https://img1.hotstarext.com/image/upload/f_auto,t_web_vl_3x/sources/r1/cms/prod/896/580896-v"
},
{
name:"SUPER 30",
rating:8.5,
img:"https://img1.hotstarext.com/image/upload/f_auto,t_web_vl_3x/sources/r1/cms/prod/6828/556828-v"
},
{
name:"MISSON MANGAL",
rating:9.4,
img:"https://img1.hotstarext.com/image/upload/f_auto,t_web_vl_3x/sources/r1/cms/prod/1529/571529-v"
},
{
name:"MS DHONI",
rating:8.3,
img:"https://img1.hotstarext.com/image/upload/f_auto,t_web_vl_3x/sources/r1/cms/prod/old_images/vertical/MOVIE/3314/1770003314/1770003314-v"
},
{
name:"BAGGI 3",
rating:8.9,
img:"https://img1.hotstarext.com/image/upload/f_auto,t_web_vl_3x/sources/r1/cms/prod/6536/846536-v"
},
{
name:"TANHAJI",
rating:9.5,
img:"https://img1.hotstarext.com/image/upload/f_auto,t_web_vl_3x/sources/r1/cms/prod/7676/647676-v"
},
{
name:"TIRANGA",
rating:9.8,
img:"https://img1.hotstarext.com/image/upload/f_auto,t_web_vl_3x/sources/r1/cms/prod/7710/1317710-v-25d4e8e8a6cf"
},
{
name:"CADAVER",
rating:7,
img:"https://img1.hotstarext.com/image/upload/f_auto,t_web_vl_3x/sources/r1/cms/prod/8285/388285-v"
},
{
name:"THOR",
rating:9.8,
img:"https://img1.hotstarext.com/image/upload/f_auto,t_web_vl_3x/sources/r1/cms/prod/8317/1328317-v-56412010beba"
}
];
localStorage.setItem("movies",JSON.stringify(movies));
let data=JSON.parse(localStorage.getItem("movies"));
function appendMovies(data){
let data_div=document.getElementById("basic");
data_div.innerHTML=null;
// data_div.id="movies";
data.forEach(function(el){
let div=document.createElement("div");
let name=document.createElement("p");
name.innerHTML=`Name: ${el.name}`;
let rating=document.createElement("p");
rating.innerHTML=`Rating: ${el.rating}`;
let img=document.createElement("img");
img.id="poster";
img.src=el.img;
div.append(img,name,rating);
data_div.append(div)
})
}
let mypromise=new Promise(function(resolve,reject){
setTimeout(function(){
let data=movies;
if(data!=null){
resolve(data);
}else{
reject("Issue from Server")
}
},2000)
})
async function main(){
try{
let response=await mypromise;
appendMovies(response)
}catch(err){
console.log(err)
}
}
main();
//-----------------sorting------------
function sortLH(){
let data =JSON.parse(localStorage.getItem("movies"));
data =data.sort((a,b)=>a.rating-b.rating);
appendMovies(data)
}
function sortHL(){
let data =JSON.parse(localStorage.getItem("movies"));
data =data.sort((a,b)=>b.rating-a.rating);
appendMovies(data)
}